From 09703938fb44b659fba28c18711ddc0870ba7032 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 10 Sep 2018 12:48:13 -0700 Subject: [PATCH] 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 --- .../20180910.audit.01.searches.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 resources/sql/autopatches/20180910.audit.01.searches.php diff --git a/resources/sql/autopatches/20180910.audit.01.searches.php b/resources/sql/autopatches/20180910.audit.01.searches.php new file mode 100644 index 0000000000..f68e76fe45 --- /dev/null +++ b/resources/sql/autopatches/20180910.audit.01.searches.php @@ -0,0 +1,54 @@ +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()); +}