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

Make ManiphestTaskQuery a (mostly) policy-aware query

Summary: Ref T603.

Test Plan: Viewed home and maniphest, fiddled all the knobs.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

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

+20 -53
+1 -1
src/__phutil_library_map__.php
··· 2792 2792 'ManiphestTaskPriority' => 'ManiphestConstants', 2793 2793 'ManiphestTaskProject' => 'ManiphestDAO', 2794 2794 'ManiphestTaskProjectsView' => 'ManiphestView', 2795 - 'ManiphestTaskQuery' => 'PhabricatorQuery', 2795 + 'ManiphestTaskQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 2796 2796 'ManiphestTaskStatus' => 'ManiphestConstants', 2797 2797 'ManiphestTaskSubscriber' => 'ManiphestDAO', 2798 2798 'ManiphestTransaction' =>
+19 -52
src/applications/maniphest/ManiphestTaskQuery.php
··· 6 6 * 7 7 * @group maniphest 8 8 */ 9 - final class ManiphestTaskQuery extends PhabricatorQuery { 9 + final class ManiphestTaskQuery 10 + extends PhabricatorCursorPagedPolicyAwareQuery { 10 11 11 12 private $taskIDs = array(); 12 13 private $taskPHIDs = array(); ··· 59 60 private $rowCount = null; 60 61 61 62 private $groupByProjectResults = null; // See comment at bottom for details 62 - private $viewer; 63 - 64 - public function setViewer(PhabricatorUser $viewer) { 65 - $this->viewer = $viewer; 66 - return $this; 67 - } 68 - 69 - public function getViewer() { 70 - return $this->viewer; 71 - } 72 63 73 64 public function withAuthors(array $authors) { 74 65 $this->authorPHIDs = $authors; ··· 151 142 return $this; 152 143 } 153 144 154 - public function setLimit($limit) { 155 - $this->limit = $limit; 156 - return $this; 157 - } 158 - 159 - public function setOffset($offset) { 160 - $this->offset = $offset; 161 - return $this; 162 - } 163 - 164 145 public function setCalculateRows($calculate_rows) { 165 146 $this->calculateRows = $calculate_rows; 166 147 return $this; ··· 189 170 return $this; 190 171 } 191 172 192 - /** 193 - * This is a wrapper until we finish T603. The newer query class this class 194 - * will inherit from handles catching this exception already. 195 - */ 196 - public function execute() { 197 - 198 - try { 199 - $result = $this->executeManiphestQuery(); 200 - } catch (PhabricatorEmptyQueryException $ex) { 201 - $result = array(); 202 - if ($this->calculateRows) { 203 - $this->rowCount = 0; 204 - } 205 - } 206 - 207 - return $result; 208 - } 209 - 210 - private function executeManiphestQuery() { 211 - 173 + public function loadPage() { 212 174 $task_dao = new ManiphestTask(); 213 175 $conn = $task_dao->establishConnection('r'); 214 176 215 177 if ($this->calculateRows) { 216 178 $calc = 'SQL_CALC_FOUND_ROWS'; 179 + 180 + // Make sure we end up in the right state if we throw a 181 + // PhabricatorEmptyQueryException. 182 + $this->rowCount = 0; 217 183 } else { 218 184 $calc = ''; 219 185 } ··· 271 237 count($this->projectPHIDs)); 272 238 } 273 239 274 - $order = $this->buildOrderClause($conn); 240 + $order = $this->buildCustomOrderClause($conn); 275 241 276 - $offset = (int)nonempty($this->offset, 0); 277 - $limit = (int)nonempty($this->limit, self::DEFAULT_PAGE_SIZE); 242 + // TODO: Clean up this nonstandardness. 243 + if (!$this->getLimit()) { 244 + $this->setLimit(self::DEFAULT_PAGE_SIZE); 245 + } 278 246 279 247 if ($this->groupBy == self::GROUP_PROJECT) { 280 - $limit = PHP_INT_MAX; 281 - $offset = 0; 248 + $this->setLimit(PHP_INT_MAX); 249 + $this->setOffset(0); 282 250 } 283 251 284 252 $data = queryfx_all( 285 253 $conn, 286 - 'SELECT %Q * %Q FROM %T task %Q %Q %Q %Q %Q LIMIT %d, %d', 254 + 'SELECT %Q * %Q FROM %T task %Q %Q %Q %Q %Q %Q', 287 255 $calc, 288 256 $count, 289 257 $task_dao->getTableName(), ··· 292 260 $group, 293 261 $having, 294 262 $order, 295 - $offset, 296 - $limit); 263 + $this->buildLimitClause($conn)); 297 264 298 265 if ($this->calculateRows) { 299 266 $count = queryfx_one( ··· 569 536 $subscriber_dao->getTableName()); 570 537 } 571 538 572 - private function buildOrderClause(AphrontDatabaseConnection $conn) { 539 + private function buildCustomOrderClause(AphrontDatabaseConnection $conn) { 573 540 $order = array(); 574 541 575 542 switch ($this->groupBy) { ··· 704 671 $items = isort($items, 'seq'); 705 672 $items = array_slice( 706 673 $items, 707 - nonempty($this->offset), 708 - nonempty($this->limit, self::DEFAULT_PAGE_SIZE)); 674 + nonempty($this->getOffset()), 675 + nonempty($this->getLimit(), self::DEFAULT_PAGE_SIZE)); 709 676 710 677 $result = array(); 711 678 $projects = array();