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

Modernize the Herald rule search engine

Summary: Ref T13216. Update the Herald Rule SearchEngine and Query to use a more modern style.

Test Plan: Ran various rule queries in the UI, got sensible results

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13216

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

+65 -120
+19 -24
src/applications/herald/query/HeraldRuleQuery.php
··· 70 70 return $this; 71 71 } 72 72 73 + public function newResultObject() { 74 + return new HeraldRule(); 75 + } 76 + 73 77 protected function loadPage() { 74 - $table = new HeraldRule(); 75 - $conn_r = $table->establishConnection('r'); 76 - 77 - $data = queryfx_all( 78 - $conn_r, 79 - 'SELECT rule.* FROM %T rule %Q %Q %Q', 80 - $table->getTableName(), 81 - $this->buildWhereClause($conn_r), 82 - $this->buildOrderClause($conn_r), 83 - $this->buildLimitClause($conn_r)); 84 - 85 - return $table->loadAllFromArray($data); 78 + return $this->loadStandardPage($this->newResultObject()); 86 79 } 87 80 88 81 protected function willFilterPage(array $rules) { ··· 175 168 return $rules; 176 169 } 177 170 178 - protected function buildWhereClause(AphrontDatabaseConnection $conn) { 179 - $where = array(); 171 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 172 + $where = parent::buildWhereClauseParts($conn); 180 173 181 - if ($this->ids) { 174 + if ($this->ids !== null) { 182 175 $where[] = qsprintf( 183 176 $conn, 184 177 'rule.id IN (%Ld)', 185 178 $this->ids); 186 179 } 187 180 188 - if ($this->phids) { 181 + if ($this->phids !== null) { 189 182 $where[] = qsprintf( 190 183 $conn, 191 184 'rule.phid IN (%Ls)', 192 185 $this->phids); 193 186 } 194 187 195 - if ($this->authorPHIDs) { 188 + if ($this->authorPHIDs !== null) { 196 189 $where[] = qsprintf( 197 190 $conn, 198 191 'rule.authorPHID IN (%Ls)', 199 192 $this->authorPHIDs); 200 193 } 201 194 202 - if ($this->ruleTypes) { 195 + if ($this->ruleTypes !== null) { 203 196 $where[] = qsprintf( 204 197 $conn, 205 198 'rule.ruleType IN (%Ls)', 206 199 $this->ruleTypes); 207 200 } 208 201 209 - if ($this->contentTypes) { 202 + if ($this->contentTypes !== null) { 210 203 $where[] = qsprintf( 211 204 $conn, 212 205 'rule.contentType IN (%Ls)', ··· 220 213 (int)$this->disabled); 221 214 } 222 215 223 - if ($this->datasourceQuery) { 216 + if ($this->datasourceQuery !== null) { 224 217 $where[] = qsprintf( 225 218 $conn, 226 219 'rule.name LIKE %>', 227 220 $this->datasourceQuery); 228 221 } 229 222 230 - if ($this->triggerObjectPHIDs) { 223 + if ($this->triggerObjectPHIDs !== null) { 231 224 $where[] = qsprintf( 232 225 $conn, 233 226 'rule.triggerObjectPHID IN (%Ls)', 234 227 $this->triggerObjectPHIDs); 235 228 } 236 229 237 - $where[] = $this->buildPagingClause($conn); 238 - 239 - return $this->formatWhereClause($conn, $where); 230 + return $where; 240 231 } 241 232 242 233 private function validateRuleAuthors(array $rules) { ··· 279 270 280 271 public function getQueryApplicationClass() { 281 272 return 'PhabricatorHeraldApplication'; 273 + } 274 + 275 + protected function getPrimaryTableAlias() { 276 + return 'rule'; 282 277 } 283 278 284 279 }
+46 -96
src/applications/herald/query/HeraldRuleSearchEngine.php
··· 10 10 return 'PhabricatorHeraldApplication'; 11 11 } 12 12 13 - public function buildSavedQueryFromRequest(AphrontRequest $request) { 14 - $saved = new PhabricatorSavedQuery(); 13 + public function newQuery() { 14 + return new HeraldRuleQuery(); 15 + } 15 16 16 - $saved->setParameter( 17 - 'authorPHIDs', 18 - $this->readUsersFromRequest($request, 'authors')); 17 + protected function buildCustomSearchFields() { 18 + $viewer = $this->requireViewer(); 19 19 20 - $saved->setParameter('contentType', $request->getStr('contentType')); 21 - $saved->setParameter('ruleType', $request->getStr('ruleType')); 22 - $saved->setParameter( 23 - 'disabled', 24 - $this->readBoolFromRequest($request, 'disabled')); 20 + $rule_types = HeraldRuleTypeConfig::getRuleTypeMap(); 21 + $content_types = HeraldAdapter::getEnabledAdapterMap($viewer); 25 22 26 - return $saved; 23 + return array( 24 + id(new PhabricatorUsersSearchField()) 25 + ->setLabel(pht('Authors')) 26 + ->setKey('authorPHIDs') 27 + ->setAliases(array('author', 'authors', 'authorPHID')) 28 + ->setDescription( 29 + pht('Search for rules with given authors.')), 30 + id(new PhabricatorSearchCheckboxesField()) 31 + ->setKey('ruleTypes') 32 + ->setAliases(array('ruleType')) 33 + ->setLabel(pht('Rule Type')) 34 + ->setDescription( 35 + pht('Search for rules of given types.')) 36 + ->setOptions($rule_types), 37 + id(new PhabricatorSearchCheckboxesField()) 38 + ->setKey('contentTypes') 39 + ->setLabel(pht('Content Type')) 40 + ->setDescription( 41 + pht('Search for rules affecting given types of content.')) 42 + ->setOptions($content_types), 43 + id(new PhabricatorSearchThreeStateField()) 44 + ->setLabel(pht('Rule Status')) 45 + ->setKey('disabled') 46 + ->setOptions( 47 + pht('(Show All)'), 48 + pht('Show Only Disabled Rules'), 49 + pht('Show Only Enabled Rules')), 50 + ); 27 51 } 28 52 29 - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 30 - $query = id(new HeraldRuleQuery()); 53 + protected function buildQueryFromParameters(array $map) { 54 + $query = $this->newQuery(); 31 55 32 - $author_phids = $saved->getParameter('authorPHIDs'); 33 - if ($author_phids) { 34 - $query->withAuthorPHIDs($author_phids); 56 + if ($map['authorPHIDs']) { 57 + $query->withAuthorPHIDs($map['authorPHIDs']); 35 58 } 36 59 37 - $content_type = $saved->getParameter('contentType'); 38 - $content_type = idx($this->getContentTypeValues(), $content_type); 39 - if ($content_type) { 40 - $query->withContentTypes(array($content_type)); 60 + if ($map['contentTypes']) { 61 + $query->withContentTypes($map['contentTypes']); 41 62 } 42 63 43 - $rule_type = $saved->getParameter('ruleType'); 44 - $rule_type = idx($this->getRuleTypeValues(), $rule_type); 45 - if ($rule_type) { 46 - $query->withRuleTypes(array($rule_type)); 64 + if ($map['ruleTypes']) { 65 + $query->withRuleTypes($map['ruleTypes']); 47 66 } 48 67 49 - $disabled = $saved->getParameter('disabled'); 50 - if ($disabled !== null) { 51 - $query->withDisabled($disabled); 68 + if ($map['disabled'] !== null) { 69 + $query->withDisabled($map['disabled']); 52 70 } 53 71 54 72 return $query; 55 73 } 56 74 57 - public function buildSearchForm( 58 - AphrontFormView $form, 59 - PhabricatorSavedQuery $saved_query) { 60 - 61 - $author_phids = $saved_query->getParameter('authorPHIDs', array()); 62 - $content_type = $saved_query->getParameter('contentType'); 63 - $rule_type = $saved_query->getParameter('ruleType'); 64 - 65 - $form 66 - ->appendControl( 67 - id(new AphrontFormTokenizerControl()) 68 - ->setDatasource(new PhabricatorPeopleDatasource()) 69 - ->setName('authors') 70 - ->setLabel(pht('Authors')) 71 - ->setValue($author_phids)) 72 - ->appendChild( 73 - id(new AphrontFormSelectControl()) 74 - ->setName('contentType') 75 - ->setLabel(pht('Content Type')) 76 - ->setValue($content_type) 77 - ->setOptions($this->getContentTypeOptions())) 78 - ->appendChild( 79 - id(new AphrontFormSelectControl()) 80 - ->setName('ruleType') 81 - ->setLabel(pht('Rule Type')) 82 - ->setValue($rule_type) 83 - ->setOptions($this->getRuleTypeOptions())) 84 - ->appendChild( 85 - id(new AphrontFormSelectControl()) 86 - ->setName('disabled') 87 - ->setLabel(pht('Rule Status')) 88 - ->setValue($this->getBoolFromQuery($saved_query, 'disabled')) 89 - ->setOptions( 90 - array( 91 - '' => pht('Show Enabled and Disabled Rules'), 92 - 'false' => pht('Show Only Enabled Rules'), 93 - 'true' => pht('Show Only Disabled Rules'), 94 - ))); 95 - } 96 - 97 75 protected function getURI($path) { 98 76 return '/herald/'.$path; 99 77 } ··· 131 109 return parent::buildSavedQueryFromBuiltin($query_key); 132 110 } 133 111 134 - private function getContentTypeOptions() { 135 - return array( 136 - '' => pht('(All Content Types)'), 137 - ) + HeraldAdapter::getEnabledAdapterMap($this->requireViewer()); 138 - } 139 - 140 - private function getContentTypeValues() { 141 - return array_fuse( 142 - array_keys( 143 - HeraldAdapter::getEnabledAdapterMap($this->requireViewer()))); 144 - } 145 - 146 - private function getRuleTypeOptions() { 147 - return array( 148 - '' => pht('(All Rule Types)'), 149 - ) + HeraldRuleTypeConfig::getRuleTypeMap(); 150 - } 151 - 152 - private function getRuleTypeValues() { 153 - return array_fuse(array_keys(HeraldRuleTypeConfig::getRuleTypeMap())); 154 - } 155 - 156 - protected function getRequiredHandlePHIDsForResultList( 157 - array $rules, 158 - PhabricatorSavedQuery $query) { 159 - 160 - return mpull($rules, 'getAuthorPHID'); 161 - } 162 - 163 112 protected function renderResultList( 164 113 array $rules, 165 114 PhabricatorSavedQuery $query, ··· 167 116 assert_instances_of($rules, 'HeraldRule'); 168 117 169 118 $viewer = $this->requireViewer(); 119 + $handles = $viewer->loadHandles(mpull($rules, 'getAuthorPHID')); 170 120 171 121 $content_type_map = HeraldAdapter::getEnabledAdapterMap($viewer); 172 122