@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

Migrate remaining Audit database status constants

Summary: Depends on D19652. Ref T13197. See PHI851. This migrates the actual `auditStatus` on Commits, and older status transactions.

Test Plan:
- Ran migrations.
- Spot-checked the database for sanity.
- Ran some different queries, got unchanged results from before migration.
- Reviewed historic audit state transactions, and accepted/raised concern on new audits. All state transactions appeared to generate properly.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13197

Differential Revision: https://secure.phabricator.com/D19655

+107 -32
+2
resources/sql/autopatches/20180910.audit.02.string.sql
··· 1 + ALTER TABLE {$NAMESPACE}_repository.repository_commit 2 + CHANGE auditStatus auditStatus VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
+28
resources/sql/autopatches/20180910.audit.03.status.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorRepositoryCommit(); 4 + $conn = $table->establishConnection('w'); 5 + 6 + $status_map = array( 7 + 0 => 'none', 8 + 1 => 'needs-audit', 9 + 2 => 'concern-raised', 10 + 3 => 'partially-audited', 11 + 4 => 'audited', 12 + 5 => 'needs-verification', 13 + ); 14 + 15 + foreach (new LiskMigrationIterator($table) as $commit) { 16 + $status = $commit->getAuditStatus(); 17 + 18 + if (!isset($status_map[$status])) { 19 + continue; 20 + } 21 + 22 + queryfx( 23 + $conn, 24 + 'UPDATE %T SET auditStatus = %s WHERE id = %d', 25 + $table->getTableName(), 26 + $status_map[$status], 27 + $commit->getID()); 28 + }
+48
resources/sql/autopatches/20180910.audit.04.xactions.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorAuditTransaction(); 4 + $conn = $table->establishConnection('w'); 5 + 6 + $status_map = array( 7 + 0 => 'none', 8 + 1 => 'needs-audit', 9 + 2 => 'concern-raised', 10 + 3 => 'partially-audited', 11 + 4 => 'audited', 12 + 5 => 'needs-verification', 13 + ); 14 + 15 + $state_type = DiffusionCommitStateTransaction::TRANSACTIONTYPE; 16 + 17 + foreach (new LiskMigrationIterator($table) as $xaction) { 18 + if ($xaction->getTransactionType() !== $state_type) { 19 + continue; 20 + } 21 + 22 + $old_value = $xaction->getOldValue(); 23 + $new_value = $xaction->getNewValue(); 24 + 25 + $any_change = false; 26 + 27 + if (isset($status_map[$old_value])) { 28 + $old_value = $status_map[$old_value]; 29 + $any_change = true; 30 + } 31 + 32 + if (isset($status_map[$new_value])) { 33 + $new_value = $status_map[$new_value]; 34 + $any_change = true; 35 + } 36 + 37 + if (!$any_change) { 38 + continue; 39 + } 40 + 41 + queryfx( 42 + $conn, 43 + 'UPDATE %T SET oldValue = %s, newValue = %s WHERE id = %d', 44 + $table->getTableName(), 45 + phutil_json_encode($old_value), 46 + phutil_json_encode($new_value), 47 + $xaction->getID()); 48 + }
+12 -13
src/applications/audit/constants/PhabricatorAuditCommitStatusConstants.php
··· 19 19 const MODERN_AUDITED = 'audited'; 20 20 const MODERN_NEEDS_VERIFICATION = 'needs-verification'; 21 21 22 - public static function newForLegacyStatus($status) { 22 + public static function newModernKeys(array $values) { 23 23 $map = self::getMap(); 24 24 25 - if (is_int($status) || ctype_digit($status)) { 26 - foreach ($map as $key => $spec) { 27 - if ((int)idx($spec, 'legacy') === (int)$status) { 28 - return self::newForStatus($key); 29 - } 25 + $modern = array(); 26 + foreach ($map as $key => $spec) { 27 + if (isset($spec['legacy'])) { 28 + $modern[$spec['legacy']] = $key; 30 29 } 31 30 } 32 31 33 - return self::newForStatus($status); 32 + foreach ($values as $key => $value) { 33 + $values[$key] = idx($modern, $value, $value); 34 + } 35 + 36 + return $values; 34 37 } 35 38 36 39 public static function newForStatus($status) { ··· 56 59 57 60 public function getColor() { 58 61 return idx($this->spec, 'color'); 59 - } 60 - 61 - public function getLegacyKey() { 62 - return idx($this->spec, 'legacy'); 63 62 } 64 63 65 64 public function getName() { ··· 96 95 97 96 public static function getOpenStatusConstants() { 98 97 $constants = array(); 99 - foreach (self::getMap() as $map) { 98 + foreach (self::getMap() as $key => $map) { 100 99 if (!$map['closed']) { 101 - $constants[] = $map['legacy']; 100 + $constants[] = $key; 102 101 } 103 102 } 104 103 return $constants;
+3 -7
src/applications/diffusion/query/DiffusionCommitQuery.php
··· 714 714 } 715 715 716 716 if ($this->statuses !== null) { 717 - $statuses = array(); 718 - foreach ($this->statuses as $status) { 719 - $object = PhabricatorAuditCommitStatusConstants::newForLegacyStatus( 720 - $status); 721 - $statuses[] = $object->getLegacyKey(); 722 - } 717 + $statuses = PhabricatorAuditCommitStatusConstants::newModernKeys( 718 + $this->statuses); 723 719 724 720 $where[] = qsprintf( 725 721 $conn, 726 - 'commit.auditStatus IN (%Ld)', 722 + 'commit.auditStatus IN (%Ls)', 727 723 $statuses); 728 724 } 729 725
+1 -1
src/applications/diffusion/xaction/DiffusionCommitConcernTransaction.php
··· 34 34 // NOTE: We force the commit directly into "Concern Raised" so that we 35 35 // override a possible "Needs Verification" state. 36 36 $object->setAuditStatus( 37 - PhabricatorAuditCommitStatusConstants::CONCERN_RAISED); 37 + PhabricatorAuditCommitStatusConstants::MODERN_CONCERN_RAISED); 38 38 } 39 39 40 40 public function applyExternalEffects($object, $value) {
+1 -1
src/applications/diffusion/xaction/DiffusionCommitStateTransaction.php
··· 13 13 14 14 private function getAuditStatusObject() { 15 15 $new = $this->getNewValue(); 16 - return PhabricatorAuditCommitStatusConstants::newForLegacyStatus($new); 16 + return PhabricatorAuditCommitStatusConstants::newForStatus($new); 17 17 } 18 18 19 19 public function getIcon() {
+1 -1
src/applications/diffusion/xaction/DiffusionCommitVerifyTransaction.php
··· 37 37 38 38 public function applyInternalEffects($object, $value) { 39 39 $object->setAuditStatus( 40 - PhabricatorAuditCommitStatusConstants::NEEDS_VERIFICATION); 40 + PhabricatorAuditCommitStatusConstants::MODERN_NEEDS_VERIFICATION); 41 41 } 42 42 43 43 protected function validateAction($object, PhabricatorUser $viewer) {
+11 -9
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 27 27 protected $epoch; 28 28 protected $mailKey; 29 29 protected $authorPHID; 30 - protected $auditStatus = PhabricatorAuditCommitStatusConstants::NONE; 30 + protected $auditStatus = PhabricatorAuditCommitStatusConstants::MODERN_NONE; 31 31 protected $summary = ''; 32 32 protected $importStatus = 0; 33 33 ··· 120 120 'authorPHID' => 'phid?', 121 121 'authorIdentityPHID' => 'phid?', 122 122 'committerIdentityPHID' => 'phid?', 123 - 'auditStatus' => 'uint32', 123 + 'auditStatus' => 'text32', 124 124 'summary' => 'text255', 125 125 'importStatus' => 'uint32', 126 126 ), ··· 385 385 if ($this->isAuditStatusNeedsVerification()) { 386 386 // If the change is in "Needs Verification", we keep it there as 387 387 // long as any auditors still have concerns. 388 - $status = PhabricatorAuditCommitStatusConstants::NEEDS_VERIFICATION; 388 + $status = 389 + PhabricatorAuditCommitStatusConstants::MODERN_NEEDS_VERIFICATION; 389 390 } else { 390 - $status = PhabricatorAuditCommitStatusConstants::CONCERN_RAISED; 391 + $status = PhabricatorAuditCommitStatusConstants::MODERN_CONCERN_RAISED; 391 392 } 392 393 } else if ($any_accept) { 393 394 if ($any_need) { 394 - $status = PhabricatorAuditCommitStatusConstants::PARTIALLY_AUDITED; 395 + $status = 396 + PhabricatorAuditCommitStatusConstants::MODERN_PARTIALLY_AUDITED; 395 397 } else { 396 - $status = PhabricatorAuditCommitStatusConstants::FULLY_AUDITED; 398 + $status = PhabricatorAuditCommitStatusConstants::MODERN_AUDITED; 397 399 } 398 400 } else if ($any_need) { 399 - $status = PhabricatorAuditCommitStatusConstants::NEEDS_AUDIT; 401 + $status = PhabricatorAuditCommitStatusConstants::MODERN_NEEDS_AUDIT; 400 402 } else { 401 - $status = PhabricatorAuditCommitStatusConstants::NONE; 403 + $status = PhabricatorAuditCommitStatusConstants::MODERN_NONE; 402 404 } 403 405 404 406 return $this->setAuditStatus($status); ··· 529 531 530 532 public function getAuditStatusObject() { 531 533 $status = $this->getAuditStatus(); 532 - return PhabricatorAuditCommitStatusConstants::newForLegacyStatus($status); 534 + return PhabricatorAuditCommitStatusConstants::newForStatus($status); 533 535 } 534 536 535 537 public function isAuditStatusNoAudit() {