From e76499bbbb62edfb4d9f7cd62e0d3bd583735834 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Mon, 22 Dec 2014 11:54:02 -0800 Subject: [PATCH] Maniphest - kill TYPE_PROJECTS Summary: Fixes T5245. Migrate old TYPE_PROJECTS transaction to new style edge transactions. Kill remaining rendering code. Test Plan: issued some fun queries to get some old-style transaction in my install: ``` // go from nothing to 1 INSERT INTO maniphest_transaction (phid, authorPHID, objectPHID, viewPolicy, editPolicy, commentVersion, transactionType, oldValue, newValue, contentSource, metadata, dateCreated, dateModified) VALUES ('PHID-XACT-TASK-000000000000000', 'PHID-USER-zo35vxnoi4bxqak6yqhc', 'PHID-TASK-hb5wphctibxxqryo6ssi', 'users', 'users', 0, 'projects', '[]', '["PHID-PROJ-4teaxbjk5okv7mdz2qlx"]', '', '{}', 1419274578, 1419274578) // go from 1 to 2 INSERT INTO maniphest_transaction (phid, authorPHID, objectPHID, viewPolicy, editPolicy, commentVersion, transactionType, oldValue, newValue, contentSource, metadata, dateCreated, dateModified) VALUES ('PHID-XACT-TASK-111111111111111', 'PHID-USER-zo35vxnoi4bxqak6yqhc', 'PHID-TASK-hb5wphctibxxqryo6ssi', 'users', 'users', 0, 'projects', '["PHID-PROJ-4teaxbjk5okv7mdz2qlx"]', '["PHID-PROJ-4teaxbjk5okv7mdz2qlx", "PHID-PROJ-a7giqlyyfirqswg6gn6x"]', '', '{}', 1419274580, 1419274580) // swap 1 for 1 with 2 in set INSERT INTO maniphest_transaction (phid, authorPHID, objectPHID, viewPolicy, editPolicy, commentVersion, transactionType, oldValue, newValue, contentSource, metadata, dateCreated, dateModified) VALUES ('PHID-XACT-TASK-222222222222222', 'PHID-USER-zo35vxnoi4bxqak6yqhc', 'PHID-TASK-hb5wphctibxxqryo6ssi', 'users', 'users', 0, 'projects', '["PHID-PROJ-4teaxbjk5okv7mdz2qlx", "PHID-PROJ-a7giqlyyfirqswg6gn6x"]', '["PHID-PROJ-4teaxbjk5okv7mdz2qlx", "PHID-PROJ-cety4gr55gpxzhwtrkhx"]', '', '{}', 1419274582, 1419274582) // go from 2 to 1 INSERT INTO maniphest_transaction (phid, authorPHID, objectPHID, viewPolicy, editPolicy, commentVersion, transactionType, oldValue, newValue, contentSource, metadata, dateCreated, dateModified) VALUES ('PHID-XACT-TASK-333333333333333', 'PHID-USER-zo35vxnoi4bxqak6yqhc', 'PHID-TASK-hb5wphctibxxqryo6ssi', 'users', 'users', 0, 'projects', '["PHID-PROJ-4teaxbjk5okv7mdz2qlx", "PHID-PROJ-cety4gr55gpxzhwtrkhx"]', '["PHID-PROJ-4teaxbjk5okv7mdz2qlx"]', '', '{}', 1419274584, 1419274584) ``` took a screenshot. ran the migration script and compared the screenshots and things looked correctly migrated...! old style: {F255408} new style: {F255407} Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T5245 Differential Revision: https://secure.phabricator.com/D11032 --- .../autopatches/20141222.maniphestprojtxn.php | 48 +++++++++++ .../storage/ManiphestTransaction.php | 80 ------------------- 2 files changed, 48 insertions(+), 80 deletions(-) create mode 100644 resources/sql/autopatches/20141222.maniphestprojtxn.php diff --git a/resources/sql/autopatches/20141222.maniphestprojtxn.php b/resources/sql/autopatches/20141222.maniphestprojtxn.php new file mode 100644 index 0000000000..985fb1421b --- /dev/null +++ b/resources/sql/autopatches/20141222.maniphestprojtxn.php @@ -0,0 +1,48 @@ +establishConnection('w'); + +echo "Converting Maniphest project transactions to modern EDGE ". + "transactions...\n"; +$metadata = array( + 'edge:type' => PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,); +foreach (new LiskMigrationIterator($table) as $txn) { + // ManiphestTransaction::TYPE_PROJECTS + if ($txn->getTransactionType() == 'projects') { + $old_value = mig20141222_build_edge_data( + $txn->getOldValue(), + $txn->getObjectPHID()); + $new_value = mig20141222_build_edge_data( + $txn->getNewvalue(), + $txn->getObjectPHID()); + queryfx( + $conn_w, + 'UPDATE %T SET '. + 'transactionType = %s, oldValue = %s, newValue = %s, metaData = %s '. + 'WHERE id = %d', + $table->getTableName(), + PhabricatorTransactions::TYPE_EDGE, + json_encode($old_value), + json_encode($new_value), + json_encode($metadata), + $txn->getID()); + } +} + +echo "Done.\n"; + +function mig20141222_build_edge_data(array $project_phids, $task_phid) { + $edge_data = array(); + foreach ($project_phids as $project_phid) { + if (!is_scalar($project_phid)) { + continue; + } + $edge_data[$project_phid] = array( + 'src' => $task_phid, + 'type' => PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, + 'dst' => $project_phid, + ); + } + return $edge_data; +} diff --git a/src/applications/maniphest/storage/ManiphestTransaction.php b/src/applications/maniphest/storage/ManiphestTransaction.php index c72851c8dc..074fc36010 100644 --- a/src/applications/maniphest/storage/ManiphestTransaction.php +++ b/src/applications/maniphest/storage/ManiphestTransaction.php @@ -18,12 +18,6 @@ final class ManiphestTransaction // NOTE: this type is deprecated. Keep it around for legacy installs // so any transactions render correctly. const TYPE_ATTACH = 'attach'; - /** - * TYPE_PROJECTS is legacy and depracted in favor of - * PhabricatorTransactions::TYPE_EDGE; keep it around for legacy - * transaction-rendering. - */ - const TYPE_PROJECTS = 'projects'; const MAILTAG_STATUS = 'maniphest-status'; const MAILTAG_OWNER = 'maniphest-owner'; @@ -87,14 +81,6 @@ final class ManiphestTransaction $phids[] = $old; } break; - case self::TYPE_PROJECTS: - $phids = array_mergev( - array( - $phids, - nonempty($old, array()), - nonempty($new, array()), - )); - break; case self::TYPE_PROJECT_COLUMN: $phids[] = $new['projectPHID']; $phids[] = head($new['columnPHIDs']); @@ -267,9 +253,6 @@ final class ManiphestTransaction return pht('Reassigned'); } - case self::TYPE_PROJECTS: - return pht('Changed Projects'); - case self::TYPE_PROJECT_COLUMN: return pht('Changed Project Column'); @@ -340,9 +323,6 @@ final class ManiphestTransaction case self::TYPE_DESCRIPTION: return 'fa-pencil'; - case self::TYPE_PROJECTS: - return 'fa-briefcase'; - case self::TYPE_PROJECT_COLUMN: return 'fa-columns'; @@ -483,36 +463,6 @@ final class ManiphestTransaction $this->renderHandleLink($new)); } - case self::TYPE_PROJECTS: - $added = array_diff($new, $old); - $removed = array_diff($old, $new); - if ($added && !$removed) { - return pht( - '%s added %d project(s): %s', - $this->renderHandleLink($author_phid), - count($added), - $this->renderHandleList($added)); - } else if ($removed && !$added) { - return pht( - '%s removed %d project(s): %s', - $this->renderHandleLink($author_phid), - count($removed), - $this->renderHandleList($removed)); - } else if ($removed && $added) { - return pht( - '%s changed project(s), added %d: %s; removed %d: %s', - $this->renderHandleLink($author_phid), - count($added), - $this->renderHandleList($added), - count($removed), - $this->renderHandleList($removed)); - } else { - // This is hit when rendering previews. - return pht( - '%s changed projects...', - $this->renderHandleLink($author_phid)); - } - case self::TYPE_PRIORITY: $old_name = ManiphestTaskPriority::getTaskPriorityName($old); $new_name = ManiphestTaskPriority::getTaskPriorityName($new); @@ -730,34 +680,6 @@ final class ManiphestTransaction $this->renderHandleLink($new)); } - case self::TYPE_PROJECTS: - $added = array_diff($new, $old); - $removed = array_diff($old, $new); - if ($added && !$removed) { - return pht( - '%s added %d project(s) to %s: %s', - $this->renderHandleLink($author_phid), - count($added), - $this->renderHandleLink($object_phid), - $this->renderHandleList($added)); - } else if ($removed && !$added) { - return pht( - '%s removed %d project(s) from %s: %s', - $this->renderHandleLink($author_phid), - count($removed), - $this->renderHandleLink($object_phid), - $this->renderHandleList($removed)); - } else if ($removed && $added) { - return pht( - '%s changed project(s) of %s, added %d: %s; removed %d: %s', - $this->renderHandleLink($author_phid), - $this->renderHandleLink($object_phid), - count($added), - $this->renderHandleList($added), - count($removed), - $this->renderHandleList($removed)); - } - case self::TYPE_PRIORITY: $old_name = ManiphestTaskPriority::getTaskPriorityName($old); $new_name = ManiphestTaskPriority::getTaskPriorityName($new); @@ -917,8 +839,6 @@ final class ManiphestTransaction return pht('The task already has the selected status.'); case self::TYPE_OWNER: return pht('The task already has the selected owner.'); - case self::TYPE_PROJECTS: - return pht('The task is already associated with those projects.'); case self::TYPE_PRIORITY: return pht('The task already has the selected priority.'); }