diff --git a/resources/sql/autopatches/20140807.boardpos1.sql b/resources/sql/autopatches/20140807.boardpos1.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20140807.boardpos1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_project.project_columnposition + ADD COLUMN objectOrderID INT UNSIGNED NOT NULL AFTER sequence; diff --git a/resources/sql/autopatches/20140807.boardpos2.php b/resources/sql/autopatches/20140807.boardpos2.php new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20140807.boardpos2.php @@ -0,0 +1,28 @@ +establishConnection('w'); + +foreach (new LiskMigrationIterator($table) as $row) { + $id = $row->getID(); + echo "Setting object order ID for position {$id}...\n"; + + if ($row->getObjectOrderID()) { + continue; + } + + $object = id(new PhabricatorObjectQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withPHIDs(array($row->getObjectPHID())) + ->executeOne(); + if ($object) { + queryfx( + $conn_w, + 'UPDATE %T SET objectOrderID = %d WHERE id = %d', + $table->getTableName(), + $object->getID(), + $id); + } +} + +echo "Done.\n"; diff --git a/src/applications/maniphest/editor/ManiphestTransactionEditor.php b/src/applications/maniphest/editor/ManiphestTransactionEditor.php --- a/src/applications/maniphest/editor/ManiphestTransactionEditor.php +++ b/src/applications/maniphest/editor/ManiphestTransactionEditor.php @@ -219,6 +219,7 @@ ->setBoardPHID($board_phid) ->setColumnPHID($phid) ->setObjectPHID($object->getPHID()) + ->setObjectOrderID($object->getID()) // TODO: Do real sequence stuff. ->setSequence(0) ->save(); diff --git a/src/applications/project/query/PhabricatorProjectColumnPositionQuery.php b/src/applications/project/query/PhabricatorProjectColumnPositionQuery.php --- a/src/applications/project/query/PhabricatorProjectColumnPositionQuery.php +++ b/src/applications/project/query/PhabricatorProjectColumnPositionQuery.php @@ -143,7 +143,7 @@ $unions[] = qsprintf( $conn_r, 'SELECT NULL id, e.src boardPHID, NULL columnPHID, e.dst objectPHID, - 0 sequence + 0 sequence, 0 objectOrderID FROM %T e LEFT JOIN %T p ON e.src = p.boardPHID AND e.dst = p.objectPHID %Q', @@ -178,14 +178,43 @@ $positions = $table->loadAllFromArray($data); + $ephemeral = array(); foreach ($positions as $position) { if ($position->getColumnPHID() === null) { $position->makeEphemeral(); $column_phid = idx($default_map, $position->getBoardPHID()); $position->setColumnPHID($column_phid); + + $ephemeral[] = $position; } } + // If we have objects which aren't in a column, pull the underlying data + // to get the correct sub-ordering. + + if ($ephemeral) { + $ephemeral_objects = id(new PhabricatorObjectQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withPHIDs(mpull($ephemeral, 'getObjectPHID')) + ->execute(); + + $ephemeral_objects = mpull($ephemeral_objects, null, 'getPHID'); + foreach ($ephemeral as $ephemeral_position) { + $object = idx($ephemeral_objects, $ephemeral_position->getObjectPHID()); + if ($object) { + $ephemeral_position->setObjectOrderID($object->getID()); + } + } + + // TODO: We should probably just save these positions and return real + // objects instead of ephemeral objects (that is, create the positions + // as a side effect of the query). This makes more sense now that boards + // start empty and need to be explicitly initialized. However, if we make + // a mess with this ordering stuff it's easier to clean up if we didn't + // write a bunch of extra rows. Keep them ephemeral for now and create + // real rows after T4807 is stable? + } + return $positions; } diff --git a/src/applications/project/storage/PhabricatorProjectColumnPosition.php b/src/applications/project/storage/PhabricatorProjectColumnPosition.php --- a/src/applications/project/storage/PhabricatorProjectColumnPosition.php +++ b/src/applications/project/storage/PhabricatorProjectColumnPosition.php @@ -7,6 +7,7 @@ protected $columnPHID; protected $objectPHID; protected $sequence; + protected $objectOrderID; private $column = self::ATTACHABLE;