1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

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:
epriestley 2017-08-11 16:27:38 -07:00
parent 5348f34c9e
commit 7b695aa43b
5 changed files with 24 additions and 34 deletions

View file

@ -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";

View file

@ -31,21 +31,6 @@ final class DifferentialLegacyQuery
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() {
$all = array(
DifferentialRevisionStatus::NEEDS_REVIEW,

View file

@ -695,7 +695,7 @@ final class DifferentialRevisionQuery
$where[] = qsprintf(
$conn_r,
'r.status in (%Ls)',
DifferentialLegacyQuery::getLegacyValues($this->statuses));
$this->statuses);
}
if ($this->isOpen !== null) {
@ -709,7 +709,7 @@ final class DifferentialRevisionQuery
$where[] = qsprintf(
$conn_r,
'r.status in (%Ls)',
DifferentialLegacyQuery::getLegacyValues($statuses));
$statuses);
}
$where[] = $this->buildWhereClauseParts($conn_r);

View file

@ -613,26 +613,15 @@ final class DifferentialRevision extends DifferentialDAO
}
public function setModernRevisionStatus($status) {
$status_object = DifferentialRevisionStatus::newForStatus($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);
return $this->setStatus($status);
}
public function getModernRevisionStatus() {
return $this->getStatusObject()->getKey();
return $this->getStatus();
}
public function getLegacyRevisionStatus() {
return $this->getStatus();
return $this->getStatusObject()->getLegacyKey();
}
public function isClosed() {
@ -677,7 +666,7 @@ final class DifferentialRevision extends DifferentialDAO
public function getStatusObject() {
$status = $this->getStatus();
return DifferentialRevisionStatus::newForLegacyStatus($status);
return DifferentialRevisionStatus::newForStatus($status);
}
public function getFlag(PhabricatorUser $viewer) {

View file

@ -14,8 +14,7 @@ final class DifferentialRevisionStatusTransaction
}
public function getTitle() {
$new = $this->getNewValue();
$status = DifferentialRevisionStatus::newForLegacyStatus($new);
$status = $this->newStatusObject();
if ($status->isAccepted()) {
return pht('This revision is now accepted and ready to land.');