1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00
phorge-phorge/resources/sql/autopatches/20180910.audit.04.xactions.php
epriestley d63281cc54 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
2018-09-12 12:21:27 -07:00

48 lines
1 KiB
PHP

<?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());
}