From 48a3760814d69292f9d6ec98360a24a6ca2fc6aa Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 29 Jan 2019 18:00:15 -0800 Subject: [PATCH] Correct a bug where milestone "spacePHID" columns could become desynchronized Summary: Depends on D20041. See PHI1046. If you do this: - Create a parent project called "Crab" in Space 1. - Create a milestone called "Left Claw". - Shift "Crab" to Space 2. - Create a milestone called "Right Claw". ...you currently end up with "Left Claw" in the wrong `spacePHID` in the database. At the application level it's in the correct space, but when we `WHERE ... AND spacePHID IN (...)` we can incorrectly filter it out. Test Plan: - Did the above setup. - Saved "Crab", saw the space fix itself. - Put things back in the broken state. - Ran the migration script, saw things fix themselves again. Reviewers: amckinley Reviewed By: amckinley Subscribers: aeiser, PHID-OPKG-gm6ozazyms6q6i22gyam Differential Revision: https://secure.phabricator.com/D20063 --- .../autopatches/20190129.project.01.spaces.php | 18 ++++++++++++++++++ .../PhabricatorProjectTransactionEditor.php | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 resources/sql/autopatches/20190129.project.01.spaces.php diff --git a/resources/sql/autopatches/20190129.project.01.spaces.php b/resources/sql/autopatches/20190129.project.01.spaces.php new file mode 100644 index 0000000000..845b4ff25d --- /dev/null +++ b/resources/sql/autopatches/20190129.project.01.spaces.php @@ -0,0 +1,18 @@ +establishConnection('w'); +$table_name = $table->getTableName(); + +foreach (new LiskRawMigrationIterator($conn, $table_name) as $project_row) { + queryfx( + $conn, + 'UPDATE %R SET spacePHID = %ns + WHERE parentProjectPHID = %s AND milestoneNumber IS NOT NULL', + $table, + $project_row['spacePHID'], + $project_row['phid']); +} diff --git a/src/applications/project/editor/PhabricatorProjectTransactionEditor.php b/src/applications/project/editor/PhabricatorProjectTransactionEditor.php index ee2c087085..b714f66830 100644 --- a/src/applications/project/editor/PhabricatorProjectTransactionEditor.php +++ b/src/applications/project/editor/PhabricatorProjectTransactionEditor.php @@ -249,6 +249,17 @@ final class PhabricatorProjectTransactionEditor ->rematerialize($new_parent); } + // See PHI1046. Milestones are always in the Space of their parent project. + // Synchronize the database values to match the application values. + $conn = $object->establishConnection('w'); + queryfx( + $conn, + 'UPDATE %R SET spacePHID = %ns + WHERE parentProjectPHID = %s AND milestoneNumber IS NOT NULL', + $object, + $object->getSpacePHID(), + $object->getPHID()); + return parent::applyFinalEffects($object, $xactions); }