mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +01:00
Move all revision status transactions to modern values and mechanics
Summary: Ref T2543. This updates and migrates the status change transactions: - All storage now records the modern modular transaction ("differential.revision.status"), not the obsolete non-modular transaction ("differential:status"). - All storage now records the modern constants ("accepted"), not the obsolete numeric values ("2"). Test Plan: - Selected all the relevant rows before/after migration, data looked sane. - Browsed around, reviewed timelines, no changes after migration. - Changed revision states, saw appropriate new transactions in the database and timeline rendering. - Grepped for `differential:status`. Reviewers: chad Reviewed By: chad Maniphest Tasks: T2543 Differential Revision: https://secure.phabricator.com/D18419
This commit is contained in:
parent
7b695aa43b
commit
48a74de0b6
5 changed files with 50 additions and 44 deletions
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
$map = array(
|
||||
'0' => 'needs-review',
|
||||
'1' => 'needs-revision',
|
||||
'2' => 'accepted',
|
||||
'3' => 'published',
|
||||
'4' => 'abandoned',
|
||||
'5' => 'changes-planned',
|
||||
);
|
||||
|
||||
$table = new DifferentialTransaction();
|
||||
$conn = $table->establishConnection('w');
|
||||
|
||||
foreach (new LiskMigrationIterator($table) as $xaction) {
|
||||
$type = $xaction->getTransactionType();
|
||||
|
||||
if (($type != 'differential:status') &&
|
||||
($type != 'differential.revision.status')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$old = $xaction->getOldValue();
|
||||
$new = $xaction->getNewValue();
|
||||
|
||||
$old = idx($map, $old, $old);
|
||||
$new = idx($map, $new, $new);
|
||||
|
||||
queryfx(
|
||||
$conn,
|
||||
'UPDATE %T SET transactionType = %s, oldValue = %s, newValue = %s
|
||||
WHERE id = %d',
|
||||
$table->getTableName(),
|
||||
'differential.revision.status',
|
||||
json_encode($old),
|
||||
json_encode($new),
|
||||
$xaction->getID());
|
||||
}
|
|
@ -88,27 +88,6 @@ final class DifferentialRevisionStatus extends Phobject {
|
|||
return $result;
|
||||
}
|
||||
|
||||
public static function newForLegacyStatus($legacy_status) {
|
||||
$result = new self();
|
||||
|
||||
$map = self::getMap();
|
||||
foreach ($map as $key => $spec) {
|
||||
if (!isset($spec['legacy'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($spec['legacy'] != $legacy_status) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result->key = $key;
|
||||
$result->spec = $spec;
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$result = array();
|
||||
|
||||
|
|
|
@ -535,27 +535,25 @@ final class DifferentialTransactionEditor
|
|||
return $xactions;
|
||||
}
|
||||
|
||||
$old_legacy_status = $revision->getLegacyRevisionStatus();
|
||||
$revision->setModernRevisionStatus($new_status);
|
||||
$new_legacy_status = $revision->getLegacyRevisionStatus();
|
||||
if ($new_legacy_status == $old_legacy_status) {
|
||||
$old_status = $revision->getModernRevisionStatus();
|
||||
if ($new_status == $old_status) {
|
||||
return $xactions;
|
||||
}
|
||||
|
||||
$xaction = id(new DifferentialTransaction())
|
||||
->setTransactionType(
|
||||
DifferentialRevisionStatusTransaction::TRANSACTIONTYPE)
|
||||
->setOldValue($old_legacy_status)
|
||||
->setNewValue($new_legacy_status);
|
||||
->setOldValue($old_status)
|
||||
->setNewValue($new_status);
|
||||
|
||||
$xaction = $this->populateTransaction($revision, $xaction)
|
||||
->save();
|
||||
$xactions[] = $xaction;
|
||||
|
||||
// Save the status adjustment we made earlier.
|
||||
// TODO: This can be a little cleaner and more obvious once storage
|
||||
// migrates.
|
||||
$revision->save();
|
||||
$revision
|
||||
->setModernRevisionStatus($new_status)
|
||||
->save();
|
||||
|
||||
return $xactions;
|
||||
}
|
||||
|
|
|
@ -41,10 +41,6 @@ final class DifferentialTransaction
|
|||
}
|
||||
}
|
||||
|
||||
if ($xaction_type == 'differential:status') {
|
||||
return new DifferentialRevisionStatusTransaction();
|
||||
}
|
||||
|
||||
return parent::newFallbackModularTransactionType();
|
||||
}
|
||||
|
||||
|
@ -513,13 +509,8 @@ final class DifferentialTransaction
|
|||
}
|
||||
|
||||
private function isStatusTransaction($xaction) {
|
||||
$old_status = 'differential:status';
|
||||
if ($xaction->getTransactionType() == $old_status) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$new_status = DifferentialRevisionStatusTransaction::TRANSACTIONTYPE;
|
||||
if ($xaction->getTransactionType() == $new_status) {
|
||||
$status_type = DifferentialRevisionStatusTransaction::TRANSACTIONTYPE;
|
||||
if ($xaction->getTransactionType() == $status_type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@ final class DifferentialRevisionStatusTransaction
|
|||
const TRANSACTIONTYPE = 'differential.revision.status';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getLegacyRevisionStatus();
|
||||
return $object->getModernRevisionStatus();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setLegacyRevisionStatus($value);
|
||||
$object->setModernRevisionStatus($value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
|
@ -67,7 +67,7 @@ final class DifferentialRevisionStatusTransaction
|
|||
|
||||
private function newStatusObject() {
|
||||
$new = $this->getNewValue();
|
||||
return DifferentialRevisionStatus::newForLegacyStatus($new);
|
||||
return DifferentialRevisionStatus::newForStatus($new);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue