@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.

Move Repositories to SearchField

Summary: Ref T8441. Ref T7715. Internalizes `setQueryOrder()`. Removes `appendOrderFieldsToForm()`.

Test Plan: Used all Repository search fields.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7715, T8441

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

+116 -187
+30 -37
src/applications/repository/query/PhabricatorRepositoryQuery.php
··· 150 150 $this->identifierMap = array(); 151 151 } 152 152 153 + public function newResultObject() { 154 + return new PhabricatorRepository(); 155 + } 156 + 153 157 protected function loadPage() { 154 - $table = new PhabricatorRepository(); 155 - $conn_r = $table->establishConnection('r'); 156 - 157 - $data = queryfx_all( 158 - $conn_r, 159 - '%Q FROM %T r %Q %Q %Q %Q %Q %Q', 160 - $this->buildSelectClause($conn_r), 161 - $table->getTableName(), 162 - $this->buildJoinClause($conn_r), 163 - $this->buildWhereClause($conn_r), 164 - $this->buildGroupClause($conn_r), 165 - $this->buildHavingClause($conn_r), 166 - $this->buildOrderClause($conn_r), 167 - $this->buildLimitClause($conn_r)); 168 - 158 + $table = $this->newResultObject(); 159 + $data = $this->loadStandardPageRows($table); 169 160 $repositories = $table->loadAllFromArray($data); 170 161 171 162 if ($this->needCommitCounts) { ··· 386 377 return $map; 387 378 } 388 379 389 - protected function buildSelectClause(AphrontDatabaseConnection $conn) { 390 - $parts = $this->buildSelectClauseParts($conn); 380 + protected function buildSelectClauseParts(AphrontDatabaseConnection $conn) { 381 + $parts = parent::buildSelectClauseParts($conn); 382 + 391 383 if ($this->shouldJoinSummaryTable()) { 392 384 $parts[] = 's.*'; 393 385 } 394 - return $this->formatSelectClause($parts); 386 + 387 + return $parts; 395 388 } 396 389 397 - protected function buildJoinClause(AphrontDatabaseConnection $conn_r) { 398 - $joins = $this->buildJoinClauseParts($conn_r); 390 + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 391 + $joins = parent::buildJoinClauseParts($conn); 399 392 400 393 if ($this->shouldJoinSummaryTable()) { 401 394 $joins[] = qsprintf( 402 - $conn_r, 395 + $conn, 403 396 'LEFT JOIN %T s ON r.id = s.repositoryID', 404 397 PhabricatorRepository::TABLE_SUMMARY); 405 398 } 406 399 407 - return $this->formatJoinClause($joins); 400 + return $joins; 408 401 } 409 402 410 403 private function shouldJoinSummaryTable() { ··· 428 421 return false; 429 422 } 430 423 431 - protected function buildWhereClauseParts(AphrontDatabaseConnection $conn_r) { 432 - $where = parent::buildWhereClauseParts($conn_r); 424 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 425 + $where = parent::buildWhereClauseParts($conn); 433 426 434 - if ($this->ids) { 427 + if ($this->ids !== null) { 435 428 $where[] = qsprintf( 436 - $conn_r, 429 + $conn, 437 430 'r.id IN (%Ld)', 438 431 $this->ids); 439 432 } 440 433 441 - if ($this->phids) { 434 + if ($this->phids !== null) { 442 435 $where[] = qsprintf( 443 - $conn_r, 436 + $conn, 444 437 'r.phid IN (%Ls)', 445 438 $this->phids); 446 439 } 447 440 448 - if ($this->callsigns) { 441 + if ($this->callsigns !== null) { 449 442 $where[] = qsprintf( 450 - $conn_r, 443 + $conn, 451 444 'r.callsign IN (%Ls)', 452 445 $this->callsigns); 453 446 } ··· 459 452 460 453 if ($this->numericIdentifiers) { 461 454 $identifier_clause[] = qsprintf( 462 - $conn_r, 455 + $conn, 463 456 'r.id IN (%Ld)', 464 457 $this->numericIdentifiers); 465 458 } 466 459 467 460 if ($this->callsignIdentifiers) { 468 461 $identifier_clause[] = qsprintf( 469 - $conn_r, 462 + $conn, 470 463 'r.callsign IN (%Ls)', 471 464 $this->callsignIdentifiers); 472 465 } 473 466 474 467 if ($this->phidIdentifiers) { 475 468 $identifier_clause[] = qsprintf( 476 - $conn_r, 469 + $conn, 477 470 'r.phid IN (%Ls)', 478 471 $this->phidIdentifiers); 479 472 } ··· 483 476 484 477 if ($this->types) { 485 478 $where[] = qsprintf( 486 - $conn_r, 479 + $conn, 487 480 'r.versionControlSystem IN (%Ls)', 488 481 $this->types); 489 482 } 490 483 491 484 if ($this->uuids) { 492 485 $where[] = qsprintf( 493 - $conn_r, 486 + $conn, 494 487 'r.uuid IN (%Ls)', 495 488 $this->uuids); 496 489 } 497 490 498 491 if (strlen($this->nameContains)) { 499 492 $where[] = qsprintf( 500 - $conn_r, 493 + $conn, 501 494 'name LIKE %~', 502 495 $this->nameContains); 503 496 } ··· 511 504 $callsign = $query; 512 505 } 513 506 $where[] = qsprintf( 514 - $conn_r, 507 + $conn, 515 508 'r.name LIKE %> OR r.callsign LIKE %>', 516 509 $query, 517 510 $callsign);
+54 -105
src/applications/repository/query/PhabricatorRepositorySearchEngine.php
··· 11 11 return 'PhabricatorDiffusionApplication'; 12 12 } 13 13 14 - public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 - $saved = new PhabricatorSavedQuery(); 16 - 17 - $saved->setParameter('callsigns', $request->getStrList('callsigns')); 18 - $saved->setParameter('status', $request->getStr('status')); 19 - $saved->setParameter('order', $request->getStr('order')); 20 - $saved->setParameter('hosted', $request->getStr('hosted')); 21 - $saved->setParameter('types', $request->getArr('types')); 22 - $saved->setParameter('name', $request->getStr('name')); 23 - 24 - $saved->setParameter( 25 - 'projects', 26 - $this->readProjectsFromRequest($request, 'projects')); 27 - 28 - return $saved; 29 - } 30 - 31 - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 32 - $query = id(new PhabricatorRepositoryQuery()) 14 + public function newQuery() { 15 + return id(new PhabricatorRepositoryQuery()) 33 16 ->needProjectPHIDs(true) 34 17 ->needCommitCounts(true) 35 18 ->needMostRecentCommits(true); 19 + } 36 20 37 - $callsigns = $saved->getParameter('callsigns'); 38 - if ($callsigns) { 39 - $query->withCallsigns($callsigns); 40 - } 41 - 42 - $status = $saved->getParameter('status'); 43 - $status = idx($this->getStatusValues(), $status); 44 - if ($status) { 45 - $query->withStatus($status); 46 - } 21 + protected function buildCustomSearchFields() { 22 + return array( 23 + id(new PhabricatorSearchStringListField()) 24 + ->setLabel(pht('Callsigns')) 25 + ->setKey('callsigns'), 26 + id(new PhabricatorSearchTextField()) 27 + ->setLabel(pht('Name Contains')) 28 + ->setKey('name'), 29 + id(new PhabricatorSearchSelectField()) 30 + ->setLabel(pht('Status')) 31 + ->setKey('status') 32 + ->setOptions($this->getStatusOptions()), 33 + id(new PhabricatorSearchSelectField()) 34 + ->setLabel(pht('Hosted')) 35 + ->setKey('hosted') 36 + ->setOptions($this->getHostedOptions()), 37 + id(new PhabricatorSearchCheckboxesField()) 38 + ->setLabel(pht('Types')) 39 + ->setKey('types') 40 + ->setOptions(PhabricatorRepositoryType::getAllRepositoryTypes()), 41 + ); 42 + } 47 43 48 - $this->setQueryOrder($query, $saved); 44 + public function buildQueryFromParameters(array $map) { 45 + $query = $this->newQuery(); 49 46 50 - $hosted = $saved->getParameter('hosted'); 51 - $hosted = idx($this->getHostedValues(), $hosted); 52 - if ($hosted) { 53 - $query->withHosted($hosted); 47 + if ($map['callsigns']) { 48 + $query->withCallsigns($map['callsigns']); 54 49 } 55 50 56 - $types = $saved->getParameter('types'); 57 - if ($types) { 58 - $query->withTypes($types); 51 + if ($map['status']) { 52 + $status = idx($this->getStatusValues(), $map['status']); 53 + if ($status) { 54 + $query->withStatus($status); 55 + } 59 56 } 60 57 61 - $name = $saved->getParameter('name'); 62 - if (strlen($name)) { 63 - $query->withNameContains($name); 58 + if ($map['hosted']) { 59 + $hosted = idx($this->getHostedValues(), $map['hosted']); 60 + if ($hosted) { 61 + $query->withHosted($hosted); 62 + } 64 63 } 65 64 66 - $adjusted = clone $saved; 67 - $adjusted->setParameter('projects', $this->readProjectTokens($saved)); 68 - $this->setQueryProjects($query, $adjusted); 65 + if ($map['types']) { 66 + $query->withTypes($map['types']); 67 + } 69 68 70 - return $query; 71 - } 72 - 73 - public function buildSearchForm( 74 - AphrontFormView $form, 75 - PhabricatorSavedQuery $saved_query) { 76 - 77 - $callsigns = $saved_query->getParameter('callsigns', array()); 78 - $types = $saved_query->getParameter('types', array()); 79 - $types = array_fuse($types); 80 - $name = $saved_query->getParameter('name'); 81 - $projects = $this->readProjectTokens($saved_query); 82 - 83 - $form 84 - ->appendChild( 85 - id(new AphrontFormTextControl()) 86 - ->setName('callsigns') 87 - ->setLabel(pht('Callsigns')) 88 - ->setValue(implode(', ', $callsigns))) 89 - ->appendChild( 90 - id(new AphrontFormTextControl()) 91 - ->setName('name') 92 - ->setLabel(pht('Name Contains')) 93 - ->setValue($name)) 94 - ->appendControl( 95 - id(new AphrontFormTokenizerControl()) 96 - ->setDatasource(new PhabricatorProjectLogicalDatasource()) 97 - ->setName('projects') 98 - ->setLabel(pht('Projects')) 99 - ->setValue($projects)) 100 - ->appendChild( 101 - id(new AphrontFormSelectControl()) 102 - ->setName('status') 103 - ->setLabel(pht('Status')) 104 - ->setValue($saved_query->getParameter('status')) 105 - ->setOptions($this->getStatusOptions())) 106 - ->appendChild( 107 - id(new AphrontFormSelectControl()) 108 - ->setName('hosted') 109 - ->setLabel(pht('Hosted')) 110 - ->setValue($saved_query->getParameter('hosted')) 111 - ->setOptions($this->getHostedOptions())); 112 - 113 - $type_control = id(new AphrontFormCheckboxControl()) 114 - ->setLabel(pht('Types')); 115 - 116 - $all_types = PhabricatorRepositoryType::getAllRepositoryTypes(); 117 - foreach ($all_types as $key => $name) { 118 - $type_control->addCheckbox( 119 - 'types[]', 120 - $key, 121 - $name, 122 - isset($types[$key])); 69 + if (strlen($map['name'])) { 70 + $query->withNameContains($map['name']); 123 71 } 124 - $form->appendChild($type_control); 125 72 126 - $this->appendOrderFieldsToForm( 127 - $form, 128 - $saved_query, 129 - new PhabricatorRepositoryQuery()); 73 + return $query; 130 74 } 131 75 132 76 protected function getURI($path) { ··· 268 212 return $list; 269 213 } 270 214 271 - private function readProjectTokens(PhabricatorSavedQuery $saved) { 272 - $projects = $saved->getParameter('projects', array()); 215 + protected function willUseSavedQuery(PhabricatorSavedQuery $saved) { 216 + $project_phids = $saved->getParameter('projectPHIDs', array()); 217 + 218 + $old = $saved->getParameter('projects', array()); 219 + foreach ($old as $phid) { 220 + $project_phids[] = $phid; 221 + } 273 222 274 223 $any = $saved->getParameter('anyProjectPHIDs', array()); 275 224 foreach ($any as $project) { 276 - $projects[] = 'any('.$project.')'; 225 + $project_phids[] = 'any('.$project.')'; 277 226 } 278 227 279 - return $projects; 228 + $saved->setParameter('projectPHIDs', $project_phids); 280 229 } 281 230 282 231 }
+32 -45
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
··· 108 108 * @return The result of the query. 109 109 */ 110 110 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 111 + $saved = clone $saved; 112 + $this->willUseSavedQuery($saved); 113 + 111 114 $fields = $this->buildSearchFields(); 112 115 $viewer = $this->requireViewer(); 113 116 ··· 153 156 $this->applyCustomFieldsToQuery($query, $saved); 154 157 } 155 158 156 - $this->setQueryOrder($query, $saved); 159 + $order = $saved->getParameter('order'); 160 + $builtin = $query->getBuiltinOrders(); 161 + if (strlen($order) && isset($builtin[$order])) { 162 + $query->setOrder($order); 163 + } else { 164 + // If the order is invalid or not available, we choose the first 165 + // builtin order. This isn't always the default order for the query, 166 + // but is the first value in the "Order" dropdown, and makes the query 167 + // behavior more consistent with the UI. In queries where the two 168 + // orders differ, this order is the preferred order for humans. 169 + $query->setOrder(head_key($builtin)); 170 + } 157 171 158 172 return $query; 159 173 } 160 174 175 + /** 176 + * Hook for subclasses to adjust saved queries prior to use. 177 + * 178 + * If an application changes how queries are saved, it can implement this 179 + * hook to keep old queries working the way users expect, by reading, 180 + * adjusting, and overwriting parameters. 181 + * 182 + * @param PhabricatorSavedQuery Saved query which will be executed. 183 + * @return void 184 + */ 185 + protected function willUseSavedQuery(PhabricatorSavedQuery $saved) { 186 + return; 187 + } 188 + 161 189 protected function buildQueryFromParameters(array $parameters) { 162 190 throw new PhutilMethodNotImplementedException(); 163 191 } ··· 172 200 public function buildSearchForm( 173 201 AphrontFormView $form, 174 202 PhabricatorSavedQuery $saved) { 203 + 204 + $saved = clone $saved; 205 + $this->willUseSavedQuery($saved); 175 206 176 207 $fields = $this->buildSearchFields(); 177 208 $viewer = $this->requireViewer(); ··· 888 919 ->setValue($end_str)); 889 920 } 890 921 891 - 892 - /* -( Result Ordering )---------------------------------------------------- */ 893 - 894 - /** 895 - * Set query ordering from a saved value. 896 - */ 897 - protected function setQueryOrder( 898 - PhabricatorCursorPagedPolicyAwareQuery $query, 899 - PhabricatorSavedQuery $saved) { 900 - 901 - $order = $saved->getParameter('order'); 902 - $builtin = $query->getBuiltinOrders(); 903 - 904 - if (strlen($order) && isset($builtin[$order])) { 905 - $query->setOrder($order); 906 - } else { 907 - // If the order is invalid or not available, we choose the first 908 - // builtin order. This isn't always the default order for the query, 909 - // but is the first value in the "Order" dropdown, and makes the query 910 - // behavior more consistent with the UI. In queries where the two 911 - // orders differ, this order is the preferred order for humans. 912 - $query->setOrder(head_key($builtin)); 913 - } 914 - 915 - return $this; 916 - } 917 - 918 - 919 - 920 - protected function appendOrderFieldsToForm( 921 - AphrontFormView $form, 922 - PhabricatorSavedQuery $saved, 923 - PhabricatorCursorPagedPolicyAwareQuery $query) { 924 - 925 - $orders = $query->getBuiltinOrders(); 926 - $orders = ipull($orders, 'name'); 927 - 928 - $form->appendControl( 929 - id(new AphrontFormSelectControl()) 930 - ->setLabel(pht('Order')) 931 - ->setName('order') 932 - ->setOptions($orders) 933 - ->setValue($saved->getParameter('order'))); 934 - } 935 922 936 923 /* -( Paging and Executing Queries )--------------------------------------- */ 937 924