Migrate revision storage to modern status constants ("accepted") instead of legacy numeric values ("2")
Summary: Ref T2543. Rewrites all the storage to use constants. Note that transactions still use legacy values, I'll migrate and update them separately. Test Plan: - Ran migration. - Browsed around, changed revision states, viewed dashboard, etc. - Selected `DISTINCT()` and `GROUP_CONCAT()` of the `status` field in the database, saw sane/expected before and after values. - Verified that old Conduit methods still return numeric constants for compatibility. Reviewers: chad Reviewed By: chad Maniphest Tasks: T2543 Differential Revision: https://secure.phabricator.com/D18418
This commit is contained in:
		| @@ -0,0 +1,17 @@ | |||||||
|  | UPDATE {$NAMESPACE}_differential.differential_revision | ||||||
|  |   SET status = "needs-review" WHERE status = "0"; | ||||||
|  |  | ||||||
|  | UPDATE {$NAMESPACE}_differential.differential_revision | ||||||
|  |   SET status = "needs-revision" WHERE status = "1"; | ||||||
|  |  | ||||||
|  | UPDATE {$NAMESPACE}_differential.differential_revision | ||||||
|  |   SET status = "accepted" WHERE status = "2"; | ||||||
|  |  | ||||||
|  | UPDATE {$NAMESPACE}_differential.differential_revision | ||||||
|  |   SET status = "published" WHERE status = "3"; | ||||||
|  |  | ||||||
|  | UPDATE {$NAMESPACE}_differential.differential_revision | ||||||
|  |   SET status = "abandoned" WHERE status = "4"; | ||||||
|  |  | ||||||
|  | UPDATE {$NAMESPACE}_differential.differential_revision | ||||||
|  |   SET status = "changes-planned" WHERE status = "5"; | ||||||
| @@ -31,21 +31,6 @@ final class DifferentialLegacyQuery | |||||||
|     return $map[$status]; |     return $map[$status]; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public static function getLegacyValues(array $modern_values) { |  | ||||||
|     $values = array(); |  | ||||||
|     foreach ($modern_values as $status_constant) { |  | ||||||
|       $status_object = DifferentialRevisionStatus::newForStatus( |  | ||||||
|         $status_constant); |  | ||||||
|  |  | ||||||
|       $legacy_key = $status_object->getLegacyKey(); |  | ||||||
|       if ($legacy_key !== null) { |  | ||||||
|         $values[] = $legacy_key; |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     return $values; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private static function getMap() { |   private static function getMap() { | ||||||
|     $all = array( |     $all = array( | ||||||
|       DifferentialRevisionStatus::NEEDS_REVIEW, |       DifferentialRevisionStatus::NEEDS_REVIEW, | ||||||
|   | |||||||
| @@ -695,7 +695,7 @@ final class DifferentialRevisionQuery | |||||||
|       $where[] = qsprintf( |       $where[] = qsprintf( | ||||||
|         $conn_r, |         $conn_r, | ||||||
|         'r.status in (%Ls)', |         'r.status in (%Ls)', | ||||||
|         DifferentialLegacyQuery::getLegacyValues($this->statuses)); |         $this->statuses); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if ($this->isOpen !== null) { |     if ($this->isOpen !== null) { | ||||||
| @@ -709,7 +709,7 @@ final class DifferentialRevisionQuery | |||||||
|       $where[] = qsprintf( |       $where[] = qsprintf( | ||||||
|         $conn_r, |         $conn_r, | ||||||
|         'r.status in (%Ls)', |         'r.status in (%Ls)', | ||||||
|         DifferentialLegacyQuery::getLegacyValues($statuses)); |         $statuses); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     $where[] = $this->buildWhereClauseParts($conn_r); |     $where[] = $this->buildWhereClauseParts($conn_r); | ||||||
|   | |||||||
| @@ -613,26 +613,15 @@ final class DifferentialRevision extends DifferentialDAO | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   public function setModernRevisionStatus($status) { |   public function setModernRevisionStatus($status) { | ||||||
|     $status_object = DifferentialRevisionStatus::newForStatus($status); |     return $this->setStatus($status); | ||||||
|  |  | ||||||
|     if ($status_object->getKey() != $status) { |  | ||||||
|       throw new Exception( |  | ||||||
|         pht( |  | ||||||
|           'Trying to set revision to invalid status "%s".', |  | ||||||
|           $status)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     $legacy_status = $status_object->getLegacyKey(); |  | ||||||
|  |  | ||||||
|     return $this->setStatus($legacy_status); |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public function getModernRevisionStatus() { |   public function getModernRevisionStatus() { | ||||||
|     return $this->getStatusObject()->getKey(); |     return $this->getStatus(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public function getLegacyRevisionStatus() { |   public function getLegacyRevisionStatus() { | ||||||
|     return $this->getStatus(); |     return $this->getStatusObject()->getLegacyKey(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public function isClosed() { |   public function isClosed() { | ||||||
| @@ -677,7 +666,7 @@ final class DifferentialRevision extends DifferentialDAO | |||||||
|  |  | ||||||
|   public function getStatusObject() { |   public function getStatusObject() { | ||||||
|     $status = $this->getStatus(); |     $status = $this->getStatus(); | ||||||
|     return DifferentialRevisionStatus::newForLegacyStatus($status); |     return DifferentialRevisionStatus::newForStatus($status); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public function getFlag(PhabricatorUser $viewer) { |   public function getFlag(PhabricatorUser $viewer) { | ||||||
|   | |||||||
| @@ -14,8 +14,7 @@ final class DifferentialRevisionStatusTransaction | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   public function getTitle() { |   public function getTitle() { | ||||||
|     $new = $this->getNewValue(); |     $status = $this->newStatusObject(); | ||||||
|     $status = DifferentialRevisionStatus::newForLegacyStatus($new); |  | ||||||
|  |  | ||||||
|     if ($status->isAccepted()) { |     if ($status->isAccepted()) { | ||||||
|       return pht('This revision is now accepted and ready to land.'); |       return pht('This revision is now accepted and ready to land.'); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 epriestley
					epriestley