1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Migrate old commit saved queries to new audit status constants

Summary: Depends on D19651. Ref T13197. The application now accepts either numeric or string values. However, for consistency and to reduce surprise in the future, migrate existing saved queries to use string values.

Test Plan: Saved some queries on `master` with numeric constants, ran the migration, saw string constants in the database and equivalent behavior in the UI.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13197

Differential Revision: https://secure.phabricator.com/D19652
This commit is contained in:
epriestley 2018-09-10 12:48:13 -07:00
parent cc3b6d5790
commit 09703938fb

View file

@ -0,0 +1,54 @@
<?php
$table = new PhabricatorSavedQuery();
$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 $query) {
if ($query->getEngineClassName() !== 'PhabricatorCommitSearchEngine') {
continue;
}
$parameters = $query->getParameters();
$status = idx($parameters, 'statuses');
if (!$status) {
// No saved "status" constraint.
continue;
}
if (!is_array($status)) {
// Saved constraint isn't a list.
continue;
}
// Migrate old integer values to new string values.
$old_status = $status;
foreach ($status as $key => $value) {
if (is_numeric($value)) {
$status[$key] = $status_map[$value];
}
}
if ($status === $old_status) {
// Nothing changed.
continue;
}
$parameters['statuses'] = $status;
queryfx(
$conn,
'UPDATE %T SET parameters = %s WHERE id = %d',
$table->getTableName(),
phutil_json_encode($parameters),
$query->getID());
}