@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Drive conduit result ordering through Query order specifications

Summary:
Ref T7803. Ref T5873. Allows Query methods to expose orderings from the underlying Query class nearly-for-free.

Callers can specify a string to use a builtin ordering, or an array to use a low-level column ordering.

Test Plan: {F368236}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5873, T7803

Differential Revision: https://secure.phabricator.com/D12381

+118 -5
+60 -1
src/applications/conduit/controller/PhabricatorConduitConsoleController.php
··· 119 119 $form_box = id(new PHUIObjectBoxView()) 120 120 ->setHeader($header) 121 121 ->setFormErrors($errors) 122 - ->setForm($form); 122 + ->appendChild($form); 123 + 124 + $content = array(); 125 + 126 + $query = $method->newQueryObject(); 127 + if ($query) { 128 + $orders = $query->getBuiltinOrders(); 129 + 130 + $rows = array(); 131 + foreach ($orders as $key => $order) { 132 + $rows[] = array( 133 + $key, 134 + $order['name'], 135 + implode(', ', $order['vector']), 136 + ); 137 + } 138 + 139 + $table = id(new AphrontTableView($rows)) 140 + ->setHeaders( 141 + array( 142 + pht('Key'), 143 + pht('Description'), 144 + pht('Columns'), 145 + )) 146 + ->setColumnClasses( 147 + array( 148 + 'pri', 149 + '', 150 + 'wide', 151 + )); 152 + $content[] = id(new PHUIObjectBoxView()) 153 + ->setHeaderText(pht('Builtin Orders')) 154 + ->appendChild($table); 155 + 156 + $columns = $query->getOrderableColumns(); 157 + 158 + $rows = array(); 159 + foreach ($columns as $key => $column) { 160 + $rows[] = array( 161 + $key, 162 + idx($column, 'unique') ? pht('Yes') : pht('No'), 163 + ); 164 + } 165 + 166 + $table = id(new AphrontTableView($rows)) 167 + ->setHeaders( 168 + array( 169 + pht('Key'), 170 + pht('Unique'), 171 + )) 172 + ->setColumnClasses( 173 + array( 174 + 'pri', 175 + 'wide', 176 + )); 177 + $content[] = id(new PHUIObjectBoxView()) 178 + ->setHeaderText(pht('Column Orders')) 179 + ->appendChild($table); 180 + } 123 181 124 182 $crumbs = $this->buildApplicationCrumbs(); 125 183 $crumbs->addTextCrumb($method->getAPIMethodName()); ··· 128 186 array( 129 187 $crumbs, 130 188 $form_box, 189 + $content, 131 190 ), 132 191 array( 133 192 'title' => $method->getAPIMethodName(),
+51 -1
src/applications/conduit/method/ConduitAPIMethod.php
··· 26 26 public function __construct() {} 27 27 28 28 public function getParamTypes() { 29 - return $this->defineParamTypes(); 29 + $types = $this->defineParamTypes(); 30 + 31 + $query = $this->newQueryObject(); 32 + if ($query) { 33 + $types['order'] = 'order'; 34 + $types += $this->getPagerParamTypes(); 35 + } 36 + 37 + return $types; 30 38 } 31 39 32 40 public function getReturnType() { ··· 250 258 ); 251 259 252 260 return $results; 261 + } 262 + 263 + 264 + /* -( Implementing Query Methods )----------------------------------------- */ 265 + 266 + 267 + public function newQueryObject() { 268 + return null; 269 + } 270 + 271 + 272 + protected function newQueryForRequest(ConduitAPIRequest $request) { 273 + $query = $this->newQueryObject(); 274 + 275 + if (!$query) { 276 + throw new Exception( 277 + pht( 278 + 'You can not call newQueryFromRequest() in this method ("%s") '. 279 + 'because it does not implement newQueryObject().', 280 + get_class($this))); 281 + } 282 + 283 + if (!($query instanceof PhabricatorCursorPagedPolicyAwareQuery)) { 284 + throw new Exception( 285 + pht( 286 + 'Call to method newQueryObject() did not return an object of class '. 287 + '"%s".', 288 + 'PhabricatorCursorPagedPolicyAwareQuery')); 289 + } 290 + 291 + $query->setViewer($request->getUser()); 292 + 293 + $order = $request->getValue('order'); 294 + if ($order !== null) { 295 + if (is_scalar($order)) { 296 + $query->setOrder($order); 297 + } else { 298 + $query->setOrderVector($order); 299 + } 300 + } 301 + 302 + return $query; 253 303 } 254 304 255 305
+7 -3
src/applications/repository/conduit/RepositoryQueryConduitAPIMethod.php
··· 19 19 return pht('Query repositories.'); 20 20 } 21 21 22 + public function newQueryObject() { 23 + return new PhabricatorRepositoryQuery(); 24 + } 25 + 22 26 protected function defineParamTypes() { 23 27 return array( 24 28 'ids' => 'optional list<int>', ··· 35 39 } 36 40 37 41 protected function execute(ConduitAPIRequest $request) { 38 - $query = id(new PhabricatorRepositoryQuery()) 39 - ->setViewer($request->getUser()); 42 + $query = $this->newQueryForRequest($request); 40 43 41 44 $ids = $request->getValue('ids', array()); 42 45 if ($ids) { ··· 68 71 $query->withUUIDs($uuids); 69 72 } 70 73 71 - $repositories = $query->execute(); 74 + $pager = $this->newPager($request); 75 + $repositories = $query->executeWithCursorPager($pager); 72 76 73 77 $results = array(); 74 78 foreach ($repositories as $repository) {