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

Begin lifting column layout logic out of ColumnPositionQuery

Summary:
Ref T10010. This is a precursor to D15171, which I'll eventually rebuild on top of these changes.

Currently, ColumnPositionQuery does a lot of "column layout" stuff that's very similar to the Milestone/Subproject stuff that needs to happen in D15171. The current approach there ended up splitting this layout stuff across two unrelated classes (ColumnPositionQuery + BoardViewController), neither of which is a particularly great place to do it -- the Query is too low-level, and the Controller is too high-level.

Instead, introduce a new "LayoutEngine" which does all this layout stuff. Swap two of the four places that we query this stuff over to the new engine:

- "Project (Column)" on tasks.
- Transaction generation when moving cards.

These sites aren't swapped by this diff, but will be by the next one:

- Actually applying transactions.
- Main layout for boards (this could swap easily now, but applying transactions currently relies on position writes having taken place, so it can't swap until the other one swaps).

Once everything is swapped over, I should be able to add the D15171 logic to LayoutEngine instead of BoardViewController and end up with a cleaner approach overall.

One particularly benefit is that //looking// at a board won't do a bunch of position writes anymore, which wasn't a big deal, but which I was a bit uneasy with.

Test Plan:
- Viewed tasks that are on boards, saw column annotations in project list.
- Moved cards between columns on a board.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10010

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

+218 -29
+2
src/__phutil_library_map__.php
··· 1814 1814 'PhabricatorBcryptPasswordHasher' => 'infrastructure/util/password/PhabricatorBcryptPasswordHasher.php', 1815 1815 'PhabricatorBinariesSetupCheck' => 'applications/config/check/PhabricatorBinariesSetupCheck.php', 1816 1816 'PhabricatorBitbucketAuthProvider' => 'applications/auth/provider/PhabricatorBitbucketAuthProvider.php', 1817 + 'PhabricatorBoardLayoutEngine' => 'applications/project/engine/PhabricatorBoardLayoutEngine.php', 1817 1818 'PhabricatorBot' => 'infrastructure/daemon/bot/PhabricatorBot.php', 1818 1819 'PhabricatorBotChannel' => 'infrastructure/daemon/bot/target/PhabricatorBotChannel.php', 1819 1820 'PhabricatorBotDebugLogHandler' => 'infrastructure/daemon/bot/handler/PhabricatorBotDebugLogHandler.php', ··· 6038 6039 'PhabricatorBcryptPasswordHasher' => 'PhabricatorPasswordHasher', 6039 6040 'PhabricatorBinariesSetupCheck' => 'PhabricatorSetupCheck', 6040 6041 'PhabricatorBitbucketAuthProvider' => 'PhabricatorOAuth1AuthProvider', 6042 + 'PhabricatorBoardLayoutEngine' => 'Phobject', 6041 6043 'PhabricatorBot' => 'PhabricatorDaemon', 6042 6044 'PhabricatorBotChannel' => 'PhabricatorBotTarget', 6043 6045 'PhabricatorBotDebugLogHandler' => 'PhabricatorBotHandler',
+10 -5
src/applications/project/controller/PhabricatorProjectMoveController.php
··· 26 26 return new Aphront404Response(); 27 27 } 28 28 29 + $board_phid = $project->getPHID(); 30 + 29 31 $object = id(new ManiphestTaskQuery()) 30 32 ->setViewer($viewer) 31 33 ->withPHIDs(array($object_phid)) ··· 54 56 return new Aphront404Response(); 55 57 } 56 58 57 - $positions = id(new PhabricatorProjectColumnPositionQuery()) 59 + $engine = id(new PhabricatorBoardLayoutEngine()) 58 60 ->setViewer($viewer) 59 - ->withColumns($columns) 60 - ->withObjectPHIDs(array($object_phid)) 61 - ->execute(); 61 + ->setBoardPHIDs(array($board_phid)) 62 + ->setObjectPHIDs(array($object_phid)) 63 + ->executeLayout(); 64 + 65 + $columns = $engine->getObjectColumns($board_phid, $object_phid); 66 + $old_column_phids = mpull($columns, 'getPHID'); 62 67 63 68 $xactions = array(); 64 69 ··· 80 85 ) + $order_params) 81 86 ->setOldValue( 82 87 array( 83 - 'columnPHIDs' => mpull($positions, 'getColumnPHID'), 88 + 'columnPHIDs' => $old_column_phids, 84 89 'projectPHID' => $column->getProjectPHID(), 85 90 )); 86 91
+187
src/applications/project/engine/PhabricatorBoardLayoutEngine.php
··· 1 + <?php 2 + 3 + final class PhabricatorBoardLayoutEngine extends Phobject { 4 + 5 + private $viewer; 6 + private $boardPHIDs; 7 + private $objectPHIDs; 8 + private $boards; 9 + private $columnMap; 10 + private $objectColumnMap = array(); 11 + private $boardLayout = array(); 12 + 13 + public function setViewer(PhabricatorUser $viewer) { 14 + $this->viewer = $viewer; 15 + return $this; 16 + } 17 + 18 + public function getViewer() { 19 + return $this->viewer; 20 + } 21 + 22 + public function setBoardPHIDs(array $board_phids) { 23 + $this->boardPHIDs = $board_phids; 24 + return $this; 25 + } 26 + 27 + public function getBoardPHIDs() { 28 + return $this->boardPHIDs; 29 + } 30 + 31 + public function setObjectPHIDs(array $object_phids) { 32 + $this->objectPHIDs = $object_phids; 33 + return $this; 34 + } 35 + 36 + public function getObjectPHIDs() { 37 + return $this->objectPHIDs; 38 + } 39 + 40 + public function executeLayout() { 41 + $viewer = $this->getViewer(); 42 + 43 + $boards = $this->loadBoards(); 44 + if (!$boards) { 45 + return $this; 46 + } 47 + 48 + $columns = $this->loadColumns($boards); 49 + $positions = $this->loadPositions($boards); 50 + 51 + foreach ($boards as $board_phid => $board) { 52 + $board_columns = idx($columns, $board_phid); 53 + 54 + // Don't layout boards with no columns. These boards need to be formally 55 + // created first. 56 + if (!$columns) { 57 + continue; 58 + } 59 + 60 + $board_positions = idx($positions, $board_phid, array()); 61 + 62 + $this->layoutBoard($board, $board_columns, $board_positions); 63 + } 64 + 65 + return $this; 66 + } 67 + 68 + public function getObjectColumns($board_phid, $object_phid) { 69 + $board_map = idx($this->objectColumnMap, $board_phid, array()); 70 + 71 + $column_phids = idx($board_map, $object_phid); 72 + if (!$column_phids) { 73 + return array(); 74 + } 75 + 76 + return array_select_keys($this->columnMap, $column_phids); 77 + } 78 + 79 + private function loadBoards() { 80 + $viewer = $this->getViewer(); 81 + $board_phids = $this->getBoardPHIDs(); 82 + 83 + $boards = id(new PhabricatorObjectQuery()) 84 + ->setViewer($viewer) 85 + ->withPHIDs($board_phids) 86 + ->execute(); 87 + $boards = mpull($boards, null, 'getPHID'); 88 + 89 + foreach ($boards as $key => $board) { 90 + if (!$board->getHasWorkboard()) { 91 + unset($boards[$key]); 92 + } 93 + } 94 + 95 + return $boards; 96 + } 97 + 98 + private function loadColumns(array $boards) { 99 + $viewer = $this->getViewer(); 100 + 101 + $columns = id(new PhabricatorProjectColumnQuery()) 102 + ->setViewer($viewer) 103 + ->withProjectPHIDs(array_keys($boards)) 104 + ->execute(); 105 + $columns = msort($columns, 'getSequence'); 106 + $columns = mpull($columns, null, 'getPHID'); 107 + 108 + $this->columnMap = $columns; 109 + $columns = mgroup($columns, 'getProjectPHID'); 110 + 111 + return $columns; 112 + } 113 + 114 + private function loadPositions(array $boards) { 115 + $viewer = $this->getViewer(); 116 + 117 + $positions = id(new PhabricatorProjectColumnPositionQuery()) 118 + ->setViewer($viewer) 119 + ->withBoardPHIDs(array_keys($boards)) 120 + ->withObjectPHIDs($this->getObjectPHIDs()) 121 + ->execute(); 122 + $positions = msort($positions, 'getOrderingKey'); 123 + $positions = mgroup($positions, 'getBoardPHID'); 124 + 125 + return $positions; 126 + } 127 + 128 + private function layoutBoard( 129 + $board, 130 + array $columns, 131 + array $positions) { 132 + 133 + $board_phid = $board->getPHID(); 134 + $position_groups = mgroup($positions, 'getObjectPHID'); 135 + 136 + foreach ($columns as $column) { 137 + if ($column->isDefaultColumn()) { 138 + $default_phid = $column->getPHID(); 139 + break; 140 + } 141 + } 142 + 143 + $layout = array(); 144 + 145 + $object_phids = $this->getObjectPHIDs(); 146 + foreach ($object_phids as $object_phid) { 147 + $positions = idx($position_groups, $object_phid, array()); 148 + 149 + // Remove any positions in columns which no longer exist. 150 + foreach ($positions as $key => $position) { 151 + $column_phid = $position->getColumnPHID(); 152 + if (empty($columns[$column_phid])) { 153 + unset($positions[$key]); 154 + } 155 + } 156 + 157 + // If the object has no position, put it on the default column. 158 + if (!$positions) { 159 + $new_position = id(new PhabricatorProjectColumnPosition()) 160 + ->setBoardPHID($board_phid) 161 + ->setColumnPHID($default_phid) 162 + ->setObjectPHID($object_phid) 163 + ->setSequence(0); 164 + $positions = array( 165 + $new_position, 166 + ); 167 + } 168 + 169 + foreach ($positions as $position) { 170 + $column_phid = $position->getColumnPHID(); 171 + $layout[$column_phid][$object_phid] = $position; 172 + } 173 + } 174 + 175 + foreach ($layout as $column_phid => $map) { 176 + $map = msort($map, 'getOrderingKey'); 177 + $layout[$column_phid] = $map; 178 + 179 + foreach ($map as $object_phid => $position) { 180 + $this->objectColumnMap[$board_phid][$object_phid][] = $column_phid; 181 + } 182 + } 183 + 184 + $this->boardLayout[$board_phid] = $layout; 185 + } 186 + 187 + }
+15 -24
src/applications/project/events/PhabricatorProjectUIEventListener.php
··· 49 49 50 50 $annotations = array(); 51 51 if ($handles && $can_appear_on_boards) { 52 + $engine = id(new PhabricatorBoardLayoutEngine()) 53 + ->setViewer($user) 54 + ->setBoardPHIDs($project_phids) 55 + ->setObjectPHIDs(array($object->getPHID())) 56 + ->executeLayout(); 52 57 53 58 // TDOO: Generalize this UI and move it out of Maniphest. 54 - 55 59 require_celerity_resource('maniphest-task-summary-css'); 56 60 57 - $positions_query = id(new PhabricatorProjectColumnPositionQuery()) 58 - ->setViewer($user) 59 - ->withBoardPHIDs($project_phids) 60 - ->withObjectPHIDs(array($object->getPHID())) 61 - ->needColumns(true); 62 - 63 - // This is important because positions will be created "on demand" 64 - // based on the set of columns. If we don't specify it, positions 65 - // won't be created. 66 - $columns = id(new PhabricatorProjectColumnQuery()) 67 - ->setViewer($user) 68 - ->withProjectPHIDs($project_phids) 69 - ->execute(); 70 - if ($columns) { 71 - $positions_query->withColumns($columns); 72 - } 73 - $positions = $positions_query->execute(); 74 - $positions = mpull($positions, null, 'getBoardPHID'); 75 - 76 61 foreach ($project_phids as $project_phid) { 77 62 $handle = $handles[$project_phid]; 78 63 79 - $position = idx($positions, $project_phid); 80 - if ($position) { 81 - $column = $position->getColumn(); 64 + $columns = $engine->getObjectColumns( 65 + $project_phid, 66 + $object->getPHID()); 82 67 68 + $annotation = array(); 69 + foreach ($columns as $column) { 83 70 $column_name = pht('(%s)', $column->getDisplayName()); 84 71 $column_link = phutil_tag( 85 72 'a', ··· 89 76 ), 90 77 $column_name); 91 78 79 + $annotation[] = $column_link; 80 + } 81 + 82 + if ($annotation) { 92 83 $annotations[$project_phid] = array( 93 84 ' ', 94 - $column_link, 85 + phutil_implode_html(', ', $annotation), 95 86 ); 96 87 } 97 88 }
+4
src/applications/project/storage/PhabricatorProjectColumnPosition.php
··· 41 41 } 42 42 43 43 public function getOrderingKey() { 44 + if (!$this->getID()) { 45 + return 0; 46 + } 47 + 44 48 // Low sequence numbers go above high sequence numbers. 45 49 // High position IDs go above low position IDs. 46 50 // Broadly, this makes newly added stuff float to the top.