@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+50 -44
+38
resources/sql/autopatches/20170811.differential.03.modernxaction.php
··· 1 + <?php 2 + 3 + $map = array( 4 + '0' => 'needs-review', 5 + '1' => 'needs-revision', 6 + '2' => 'accepted', 7 + '3' => 'published', 8 + '4' => 'abandoned', 9 + '5' => 'changes-planned', 10 + ); 11 + 12 + $table = new DifferentialTransaction(); 13 + $conn = $table->establishConnection('w'); 14 + 15 + foreach (new LiskMigrationIterator($table) as $xaction) { 16 + $type = $xaction->getTransactionType(); 17 + 18 + if (($type != 'differential:status') && 19 + ($type != 'differential.revision.status')) { 20 + continue; 21 + } 22 + 23 + $old = $xaction->getOldValue(); 24 + $new = $xaction->getNewValue(); 25 + 26 + $old = idx($map, $old, $old); 27 + $new = idx($map, $new, $new); 28 + 29 + queryfx( 30 + $conn, 31 + 'UPDATE %T SET transactionType = %s, oldValue = %s, newValue = %s 32 + WHERE id = %d', 33 + $table->getTableName(), 34 + 'differential.revision.status', 35 + json_encode($old), 36 + json_encode($new), 37 + $xaction->getID()); 38 + }
-21
src/applications/differential/constants/DifferentialRevisionStatus.php
··· 88 88 return $result; 89 89 } 90 90 91 - public static function newForLegacyStatus($legacy_status) { 92 - $result = new self(); 93 - 94 - $map = self::getMap(); 95 - foreach ($map as $key => $spec) { 96 - if (!isset($spec['legacy'])) { 97 - continue; 98 - } 99 - 100 - if ($spec['legacy'] != $legacy_status) { 101 - continue; 102 - } 103 - 104 - $result->key = $key; 105 - $result->spec = $spec; 106 - break; 107 - } 108 - 109 - return $result; 110 - } 111 - 112 91 public static function getAll() { 113 92 $result = array(); 114 93
+7 -9
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 535 535 return $xactions; 536 536 } 537 537 538 - $old_legacy_status = $revision->getLegacyRevisionStatus(); 539 - $revision->setModernRevisionStatus($new_status); 540 - $new_legacy_status = $revision->getLegacyRevisionStatus(); 541 - if ($new_legacy_status == $old_legacy_status) { 538 + $old_status = $revision->getModernRevisionStatus(); 539 + if ($new_status == $old_status) { 542 540 return $xactions; 543 541 } 544 542 545 543 $xaction = id(new DifferentialTransaction()) 546 544 ->setTransactionType( 547 545 DifferentialRevisionStatusTransaction::TRANSACTIONTYPE) 548 - ->setOldValue($old_legacy_status) 549 - ->setNewValue($new_legacy_status); 546 + ->setOldValue($old_status) 547 + ->setNewValue($new_status); 550 548 551 549 $xaction = $this->populateTransaction($revision, $xaction) 552 550 ->save(); 553 551 $xactions[] = $xaction; 554 552 555 553 // Save the status adjustment we made earlier. 556 - // TODO: This can be a little cleaner and more obvious once storage 557 - // migrates. 558 - $revision->save(); 554 + $revision 555 + ->setModernRevisionStatus($new_status) 556 + ->save(); 559 557 560 558 return $xactions; 561 559 }
+2 -11
src/applications/differential/storage/DifferentialTransaction.php
··· 41 41 } 42 42 } 43 43 44 - if ($xaction_type == 'differential:status') { 45 - return new DifferentialRevisionStatusTransaction(); 46 - } 47 - 48 44 return parent::newFallbackModularTransactionType(); 49 45 } 50 46 ··· 513 509 } 514 510 515 511 private function isStatusTransaction($xaction) { 516 - $old_status = 'differential:status'; 517 - if ($xaction->getTransactionType() == $old_status) { 518 - return true; 519 - } 520 - 521 - $new_status = DifferentialRevisionStatusTransaction::TRANSACTIONTYPE; 522 - if ($xaction->getTransactionType() == $new_status) { 512 + $status_type = DifferentialRevisionStatusTransaction::TRANSACTIONTYPE; 513 + if ($xaction->getTransactionType() == $status_type) { 523 514 return true; 524 515 } 525 516
+3 -3
src/applications/differential/xaction/DifferentialRevisionStatusTransaction.php
··· 6 6 const TRANSACTIONTYPE = 'differential.revision.status'; 7 7 8 8 public function generateOldValue($object) { 9 - return $object->getLegacyRevisionStatus(); 9 + return $object->getModernRevisionStatus(); 10 10 } 11 11 12 12 public function applyInternalEffects($object, $value) { 13 - $object->setLegacyRevisionStatus($value); 13 + $object->setModernRevisionStatus($value); 14 14 } 15 15 16 16 public function getTitle() { ··· 67 67 68 68 private function newStatusObject() { 69 69 $new = $this->getNewValue(); 70 - return DifferentialRevisionStatus::newForLegacyStatus($new); 70 + return DifferentialRevisionStatus::newForStatus($new); 71 71 } 72 72 73 73 }