@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

Lightly modernize FundInitiativeSearchEngine

Summary: Ref T12819. Prepares for Ferret engine support.

Test Plan: Queried for various initiatives.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12819

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

+50 -102
-30
src/applications/fund/query/FundInitiativeQuery.php
··· 8 8 private $ownerPHIDs; 9 9 private $statuses; 10 10 11 - private $needProjectPHIDs; 12 - 13 11 public function withIDs(array $ids) { 14 12 $this->ids = $ids; 15 13 return $this; ··· 30 28 return $this; 31 29 } 32 30 33 - public function needProjectPHIDs($need) { 34 - $this->needProjectPHIDs = $need; 35 - return $this; 36 - } 37 - 38 31 public function newResultObject() { 39 32 return new FundInitiative(); 40 33 } 41 34 42 35 protected function loadPage() { 43 36 return $this->loadStandardPage($this->newResultObject()); 44 - } 45 - 46 - protected function didFilterPage(array $initiatives) { 47 - 48 - if ($this->needProjectPHIDs) { 49 - $edge_query = id(new PhabricatorEdgeQuery()) 50 - ->withSourcePHIDs(mpull($initiatives, 'getPHID')) 51 - ->withEdgeTypes( 52 - array( 53 - PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, 54 - )); 55 - $edge_query->execute(); 56 - 57 - foreach ($initiatives as $initiative) { 58 - $phids = $edge_query->getDestinationPHIDs( 59 - array( 60 - $initiative->getPHID(), 61 - )); 62 - $initiative->attachProjectPHIDs($phids); 63 - } 64 - } 65 - 66 - return $initiatives; 67 37 } 68 38 69 39 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+50 -72
src/applications/fund/query/FundInitiativeSearchEngine.php
··· 11 11 return 'PhabricatorFundApplication'; 12 12 } 13 13 14 - public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 - $saved = new PhabricatorSavedQuery(); 14 + public function newQuery() { 15 + return new FundInitiativeQuery(); 16 + } 16 17 17 - $saved->setParameter( 18 - 'ownerPHIDs', 19 - $this->readUsersFromRequest($request, 'owners')); 20 - 21 - $saved->setParameter( 22 - 'statuses', 23 - $this->readListFromRequest($request, 'statuses')); 24 - 25 - return $saved; 18 + protected function buildCustomSearchFields() { 19 + return array( 20 + id(new PhabricatorUsersSearchField()) 21 + ->setKey('ownerPHIDs') 22 + ->setAliases(array('owner', 'ownerPHID', 'owners')) 23 + ->setLabel(pht('Owners')), 24 + id(new PhabricatorSearchCheckboxesField()) 25 + ->setKey('statuses') 26 + ->setLabel(pht('Statuses')) 27 + ->setOptions(FundInitiative::getStatusNameMap()), 28 + ); 26 29 } 27 30 28 - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 29 - $query = id(new FundInitiativeQuery()) 30 - ->needProjectPHIDs(true); 31 + protected function buildQueryFromParameters(array $map) { 32 + $query = $this->newQuery(); 31 33 32 - $owner_phids = $saved->getParameter('ownerPHIDs'); 33 - if ($owner_phids) { 34 - $query->withOwnerPHIDs($owner_phids); 34 + if ($map['ownerPHIDs']) { 35 + $query->withOwnerPHIDs($map['ownerPHIDs']); 35 36 } 36 37 37 - $statuses = $saved->getParameter('statuses'); 38 - if ($statuses) { 39 - $query->withStatuses($statuses); 38 + if ($map['statuses']) { 39 + $query->withStatuses($map['statuses']); 40 40 } 41 41 42 42 return $query; 43 43 } 44 44 45 - public function buildSearchForm( 46 - AphrontFormView $form, 47 - PhabricatorSavedQuery $saved) { 48 - 49 - $statuses = $saved->getParameter('statuses', array()); 50 - $statuses = array_fuse($statuses); 51 - 52 - $owner_phids = $saved->getParameter('ownerPHIDs', array()); 53 - 54 - $status_map = FundInitiative::getStatusNameMap(); 55 - $status_control = id(new AphrontFormCheckboxControl()) 56 - ->setLabel(pht('Statuses')); 57 - foreach ($status_map as $status => $name) { 58 - $status_control->addCheckbox( 59 - 'statuses[]', 60 - $status, 61 - $name, 62 - isset($statuses[$status])); 63 - } 64 - 65 - $form 66 - ->appendControl( 67 - id(new AphrontFormTokenizerControl()) 68 - ->setLabel(pht('Owners')) 69 - ->setName('owners') 70 - ->setDatasource(new PhabricatorPeopleDatasource()) 71 - ->setValue($owner_phids)) 72 - ->appendChild($status_control); 73 - } 74 - 75 45 protected function getURI($path) { 76 46 return '/fund/'.$path; 77 47 } ··· 112 82 return parent::buildSavedQueryFromBuiltin($query_key); 113 83 } 114 84 115 - protected function getRequiredHandlePHIDsForResultList( 85 + protected function renderResultList( 116 86 array $initiatives, 117 - PhabricatorSavedQuery $query) { 87 + PhabricatorSavedQuery $query, 88 + array $handles) { 89 + assert_instances_of($initiatives, 'FundInitiative'); 90 + 91 + $viewer = $this->requireViewer(); 118 92 119 - $phids = array(); 93 + $load_phids = array(); 120 94 foreach ($initiatives as $initiative) { 121 - $phids[] = $initiative->getOwnerPHID(); 122 - foreach ($initiative->getProjectPHIDs() as $project_phid) { 123 - $phids[] = $project_phid; 124 - } 95 + $load_phids[] = $initiative->getOwnerPHID(); 125 96 } 126 97 127 - return $phids; 128 - } 98 + if ($initiatives) { 99 + $edge_query = id(new PhabricatorEdgeQuery()) 100 + ->withSourcePHIDs(mpull($initiatives, 'getPHID')) 101 + ->withEdgeTypes( 102 + array( 103 + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, 104 + )); 129 105 130 - protected function renderResultList( 131 - array $initiatives, 132 - PhabricatorSavedQuery $query, 133 - array $handles) { 134 - assert_instances_of($initiatives, 'FundInitiative'); 106 + $edge_query->execute(); 135 107 136 - $viewer = $this->requireViewer(); 108 + foreach ($edge_query->getDestinationPHIDs() as $phid) { 109 + $load_phids[] = $phid; 110 + } 111 + } 137 112 138 - $list = id(new PHUIObjectItemListView()); 113 + $handles = $viewer->loadHandles($load_phids); 114 + $handles = iterator_to_array($handles); 115 + 116 + $list = new PHUIObjectItemListView(); 139 117 foreach ($initiatives as $initiative) { 140 118 $owner_handle = $handles[$initiative->getOwnerPHID()]; 141 119 ··· 149 127 $item->setDisabled(true); 150 128 } 151 129 152 - $project_handles = array_select_keys( 153 - $handles, 154 - $initiative->getProjectPHIDs()); 130 + $project_phids = $edge_query->getDestinationPHIDs( 131 + array( 132 + $initiative->getPHID(), 133 + )); 134 + 135 + $project_handles = array_select_keys($handles, $project_phids); 155 136 if ($project_handles) { 156 137 $item->addAttribute( 157 138 id(new PHUIHandleTagListView()) ··· 168 149 $result->setNoDataString(pht('No initiatives found.')); 169 150 170 151 return $result; 171 - 172 - 173 - return $list; 174 152 } 175 153 176 154 }