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

Fix sorting algorithm for group-by-project

Summary:
When viewing Maniphest tasks grouped by project, there's this
weird algorithm that involves generating strings to use as sort keys.
It's pretty clearly wrong in several cases; this aims to fix it.

Test Plan:
Open Maniphest and try to sort by things. Unfortunately, I
don't have access to a decent Maniphest database, so I'm not certain it
works as it should.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, mikaaay

Maniphest Tasks: T1595

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

+29 -20
+25 -6
src/applications/maniphest/ManiphestTaskQuery.php
··· 72 72 73 73 private $rowCount = null; 74 74 75 + private $groupByProjectResults = null; // See comment at bottom for details 76 + 75 77 76 78 public function withAuthors(array $authors) { 77 79 $this->authorPHIDs = $authors; ··· 171 173 "retrieve a row count."); 172 174 } 173 175 return $this->rowCount; 176 + } 177 + 178 + public function getGroupByProjectResults() { 179 + return $this->groupByProjectResults; 174 180 } 175 181 176 182 public function withAnyProject($any_project) { ··· 556 562 * server-side magic since there's currently no way to sort by project name on 557 563 * the database. 558 564 * 565 + * As a consequence of this, moreover, because the list we return from here 566 + * may include a single task multiple times (once for each project it's in), 567 + * sorting gets screwed up in the controller unless we tell it which project 568 + * to put the task in each time it appears. Hence the magic field 569 + * groupByProjectResults. 570 + * 559 571 * TODO: Move this all to the database. 560 572 */ 561 573 private function applyGroupByProject(array $tasks) { ··· 586 598 if ($phids) { 587 599 foreach ($phids as $phid) { 588 600 $items[] = array( 589 - 'key' => $key, 590 - 'seq' => sprintf( 591 - '%'.$max.'s%d', 601 + 'key' => $key, 602 + 'proj' => $phid, 603 + 'seq' => sprintf( 604 + '%'.$max.'s%09d', 592 605 $handles[$phid]->getName(), 593 606 $ii), 594 607 ); ··· 596 609 } else { 597 610 // Sort "no project" tasks first. 598 611 $items[] = array( 599 - 'key' => $key, 600 - 'seq' => '', 612 + 'key' => $key, 613 + 'proj' => null, 614 + 'seq' => sprintf( 615 + '%'.$max.'s%09d', 616 + '', 617 + $ii), 601 618 ); 602 619 } 603 620 ++$ii; ··· 610 627 nonempty($this->limit, self::DEFAULT_PAGE_SIZE)); 611 628 612 629 $result = array(); 630 + $projects = array(); 613 631 foreach ($items as $item) { 614 - $result[] = $tasks[$item['key']]; 632 + $result[] = $projects[$item['proj']][] = $tasks[$item['key']]; 615 633 } 634 + $this->groupByProjectResults = $projects; 616 635 617 636 return $result; 618 637 }
+4 -14
src/applications/maniphest/controller/ManiphestTaskListController.php
··· 582 582 break; 583 583 case 'project': 584 584 $grouped = array(); 585 - foreach ($data as $task) { 586 - $phids = $task->getProjectPHIDs(); 587 - if ($project_phids && $any_project !== true) { 588 - // If the user is filtering on "Bugs", don't show a "Bugs" group 589 - // with every result since that's silly (the query also does this 590 - // on the backend). 591 - $phids = array_diff($phids, $project_phids); 592 - } 593 - if ($phids) { 594 - foreach ($phids as $phid) { 595 - $grouped[$handles[$phid]->getName()][$task->getID()] = $task; 596 - } 597 - } else { 598 - $grouped['No Project'][$task->getID()] = $task; 585 + foreach ($query->getGroupByProjectResults() as $project => $tasks) { 586 + foreach ($tasks as $task) { 587 + $group = $project ? $handles[$project]->getName() : 'No Project'; 588 + $grouped[$group][$task->getID()] = $task; 599 589 } 600 590 } 601 591 $data = $grouped;