mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +01:00
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
This commit is contained in:
parent
09703938fb
commit
d63281cc54
9 changed files with 107 additions and 32 deletions
2
resources/sql/autopatches/20180910.audit.02.string.sql
Normal file
2
resources/sql/autopatches/20180910.audit.02.string.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_repository.repository_commit
|
||||
CHANGE auditStatus auditStatus VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
|
28
resources/sql/autopatches/20180910.audit.03.status.php
Normal file
28
resources/sql/autopatches/20180910.audit.03.status.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
$table = new PhabricatorRepositoryCommit();
|
||||
$conn = $table->establishConnection('w');
|
||||
|
||||
$status_map = array(
|
||||
0 => 'none',
|
||||
1 => 'needs-audit',
|
||||
2 => 'concern-raised',
|
||||
3 => 'partially-audited',
|
||||
4 => 'audited',
|
||||
5 => 'needs-verification',
|
||||
);
|
||||
|
||||
foreach (new LiskMigrationIterator($table) as $commit) {
|
||||
$status = $commit->getAuditStatus();
|
||||
|
||||
if (!isset($status_map[$status])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
queryfx(
|
||||
$conn,
|
||||
'UPDATE %T SET auditStatus = %s WHERE id = %d',
|
||||
$table->getTableName(),
|
||||
$status_map[$status],
|
||||
$commit->getID());
|
||||
}
|
48
resources/sql/autopatches/20180910.audit.04.xactions.php
Normal file
48
resources/sql/autopatches/20180910.audit.04.xactions.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
$table = new PhabricatorAuditTransaction();
|
||||
$conn = $table->establishConnection('w');
|
||||
|
||||
$status_map = array(
|
||||
0 => 'none',
|
||||
1 => 'needs-audit',
|
||||
2 => 'concern-raised',
|
||||
3 => 'partially-audited',
|
||||
4 => 'audited',
|
||||
5 => 'needs-verification',
|
||||
);
|
||||
|
||||
$state_type = DiffusionCommitStateTransaction::TRANSACTIONTYPE;
|
||||
|
||||
foreach (new LiskMigrationIterator($table) as $xaction) {
|
||||
if ($xaction->getTransactionType() !== $state_type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$old_value = $xaction->getOldValue();
|
||||
$new_value = $xaction->getNewValue();
|
||||
|
||||
$any_change = false;
|
||||
|
||||
if (isset($status_map[$old_value])) {
|
||||
$old_value = $status_map[$old_value];
|
||||
$any_change = true;
|
||||
}
|
||||
|
||||
if (isset($status_map[$new_value])) {
|
||||
$new_value = $status_map[$new_value];
|
||||
$any_change = true;
|
||||
}
|
||||
|
||||
if (!$any_change) {
|
||||
continue;
|
||||
}
|
||||
|
||||
queryfx(
|
||||
$conn,
|
||||
'UPDATE %T SET oldValue = %s, newValue = %s WHERE id = %d',
|
||||
$table->getTableName(),
|
||||
phutil_json_encode($old_value),
|
||||
phutil_json_encode($new_value),
|
||||
$xaction->getID());
|
||||
}
|
|
@ -19,18 +19,21 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
|
|||
const MODERN_AUDITED = 'audited';
|
||||
const MODERN_NEEDS_VERIFICATION = 'needs-verification';
|
||||
|
||||
public static function newForLegacyStatus($status) {
|
||||
public static function newModernKeys(array $values) {
|
||||
$map = self::getMap();
|
||||
|
||||
if (is_int($status) || ctype_digit($status)) {
|
||||
$modern = array();
|
||||
foreach ($map as $key => $spec) {
|
||||
if ((int)idx($spec, 'legacy') === (int)$status) {
|
||||
return self::newForStatus($key);
|
||||
}
|
||||
if (isset($spec['legacy'])) {
|
||||
$modern[$spec['legacy']] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
return self::newForStatus($status);
|
||||
foreach ($values as $key => $value) {
|
||||
$values[$key] = idx($modern, $value, $value);
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
public static function newForStatus($status) {
|
||||
|
@ -58,10 +61,6 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
|
|||
return idx($this->spec, 'color');
|
||||
}
|
||||
|
||||
public function getLegacyKey() {
|
||||
return idx($this->spec, 'legacy');
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return idx($this->spec, 'name', pht('Unknown ("%s")', $this->key));
|
||||
}
|
||||
|
@ -96,9 +95,9 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
|
|||
|
||||
public static function getOpenStatusConstants() {
|
||||
$constants = array();
|
||||
foreach (self::getMap() as $map) {
|
||||
foreach (self::getMap() as $key => $map) {
|
||||
if (!$map['closed']) {
|
||||
$constants[] = $map['legacy'];
|
||||
$constants[] = $key;
|
||||
}
|
||||
}
|
||||
return $constants;
|
||||
|
|
|
@ -714,16 +714,12 @@ final class DiffusionCommitQuery
|
|||
}
|
||||
|
||||
if ($this->statuses !== null) {
|
||||
$statuses = array();
|
||||
foreach ($this->statuses as $status) {
|
||||
$object = PhabricatorAuditCommitStatusConstants::newForLegacyStatus(
|
||||
$status);
|
||||
$statuses[] = $object->getLegacyKey();
|
||||
}
|
||||
$statuses = PhabricatorAuditCommitStatusConstants::newModernKeys(
|
||||
$this->statuses);
|
||||
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'commit.auditStatus IN (%Ld)',
|
||||
'commit.auditStatus IN (%Ls)',
|
||||
$statuses);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ final class DiffusionCommitConcernTransaction
|
|||
// NOTE: We force the commit directly into "Concern Raised" so that we
|
||||
// override a possible "Needs Verification" state.
|
||||
$object->setAuditStatus(
|
||||
PhabricatorAuditCommitStatusConstants::CONCERN_RAISED);
|
||||
PhabricatorAuditCommitStatusConstants::MODERN_CONCERN_RAISED);
|
||||
}
|
||||
|
||||
public function applyExternalEffects($object, $value) {
|
||||
|
|
|
@ -13,7 +13,7 @@ final class DiffusionCommitStateTransaction
|
|||
|
||||
private function getAuditStatusObject() {
|
||||
$new = $this->getNewValue();
|
||||
return PhabricatorAuditCommitStatusConstants::newForLegacyStatus($new);
|
||||
return PhabricatorAuditCommitStatusConstants::newForStatus($new);
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
|
|
|
@ -37,7 +37,7 @@ final class DiffusionCommitVerifyTransaction
|
|||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setAuditStatus(
|
||||
PhabricatorAuditCommitStatusConstants::NEEDS_VERIFICATION);
|
||||
PhabricatorAuditCommitStatusConstants::MODERN_NEEDS_VERIFICATION);
|
||||
}
|
||||
|
||||
protected function validateAction($object, PhabricatorUser $viewer) {
|
||||
|
|
|
@ -27,7 +27,7 @@ final class PhabricatorRepositoryCommit
|
|||
protected $epoch;
|
||||
protected $mailKey;
|
||||
protected $authorPHID;
|
||||
protected $auditStatus = PhabricatorAuditCommitStatusConstants::NONE;
|
||||
protected $auditStatus = PhabricatorAuditCommitStatusConstants::MODERN_NONE;
|
||||
protected $summary = '';
|
||||
protected $importStatus = 0;
|
||||
|
||||
|
@ -120,7 +120,7 @@ final class PhabricatorRepositoryCommit
|
|||
'authorPHID' => 'phid?',
|
||||
'authorIdentityPHID' => 'phid?',
|
||||
'committerIdentityPHID' => 'phid?',
|
||||
'auditStatus' => 'uint32',
|
||||
'auditStatus' => 'text32',
|
||||
'summary' => 'text255',
|
||||
'importStatus' => 'uint32',
|
||||
),
|
||||
|
@ -385,20 +385,22 @@ final class PhabricatorRepositoryCommit
|
|||
if ($this->isAuditStatusNeedsVerification()) {
|
||||
// If the change is in "Needs Verification", we keep it there as
|
||||
// long as any auditors still have concerns.
|
||||
$status = PhabricatorAuditCommitStatusConstants::NEEDS_VERIFICATION;
|
||||
$status =
|
||||
PhabricatorAuditCommitStatusConstants::MODERN_NEEDS_VERIFICATION;
|
||||
} else {
|
||||
$status = PhabricatorAuditCommitStatusConstants::CONCERN_RAISED;
|
||||
$status = PhabricatorAuditCommitStatusConstants::MODERN_CONCERN_RAISED;
|
||||
}
|
||||
} else if ($any_accept) {
|
||||
if ($any_need) {
|
||||
$status = PhabricatorAuditCommitStatusConstants::PARTIALLY_AUDITED;
|
||||
$status =
|
||||
PhabricatorAuditCommitStatusConstants::MODERN_PARTIALLY_AUDITED;
|
||||
} else {
|
||||
$status = PhabricatorAuditCommitStatusConstants::FULLY_AUDITED;
|
||||
$status = PhabricatorAuditCommitStatusConstants::MODERN_AUDITED;
|
||||
}
|
||||
} else if ($any_need) {
|
||||
$status = PhabricatorAuditCommitStatusConstants::NEEDS_AUDIT;
|
||||
$status = PhabricatorAuditCommitStatusConstants::MODERN_NEEDS_AUDIT;
|
||||
} else {
|
||||
$status = PhabricatorAuditCommitStatusConstants::NONE;
|
||||
$status = PhabricatorAuditCommitStatusConstants::MODERN_NONE;
|
||||
}
|
||||
|
||||
return $this->setAuditStatus($status);
|
||||
|
@ -529,7 +531,7 @@ final class PhabricatorRepositoryCommit
|
|||
|
||||
public function getAuditStatusObject() {
|
||||
$status = $this->getAuditStatus();
|
||||
return PhabricatorAuditCommitStatusConstants::newForLegacyStatus($status);
|
||||
return PhabricatorAuditCommitStatusConstants::newForStatus($status);
|
||||
}
|
||||
|
||||
public function isAuditStatusNoAudit() {
|
||||
|
|
Loading…
Reference in a new issue