From bc0963d54b1c92b97090f855f1931e7a5f1b7d0f Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 24 Aug 2017 12:49:47 -0700 Subject: [PATCH] Remove rows for personal saved builtin queries Summary: Ref T12956. After this change, individual users will no longer be able to modify builtin queries on a user-by-user basis: they will always appear at the bottom of the list, under their personal queries, and can only be managed by administrators. To support this, clean up the old rows which could be hanging around from before: delete any personal saved queries where the saved query is a builtin query. To ease this transition, try to pin the query we're deleting //if// the user had reordered things to put it on top. Test Plan: - Ran the migration, saw no changes in the UI but fewer rows. - Went back to `master`, reordered queries to put a builtin one on top. - Ran the migration. - Saw that builtin one drop to the bottom (since it can't be on top anymore) but be pinned, preserving the behavior of `/maniphest/`. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12956 Differential Revision: https://secure.phabricator.com/D18464 --- .../autopatches/20170824.search.01.saved.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 resources/sql/autopatches/20170824.search.01.saved.php diff --git a/resources/sql/autopatches/20170824.search.01.saved.php b/resources/sql/autopatches/20170824.search.01.saved.php new file mode 100644 index 0000000000..ab1485ebd5 --- /dev/null +++ b/resources/sql/autopatches/20170824.search.01.saved.php @@ -0,0 +1,46 @@ +establishConnection('w'); + +$config_table = new PhabricatorNamedQueryConfig(); + +foreach (new LiskMigrationIterator($table) as $named_query) { + + // If this isn't a builtin query, it isn't changing. Leave it alone. + if (!$named_query->getIsBuiltin()) { + continue; + } + + // If the user reordered things but left a builtin query at the top, pin + // the query before we remove the row. + if ($named_query->getSequence() == 1) { + queryfx( + $conn, + 'INSERT IGNORE INTO %T + (engineClassName, scopePHID, properties, dateCreated, dateModified) + VALUES + (%s, %s, %s, %d, %d)', + $config_table->getTableName(), + $named_query->getEngineClassName(), + $named_query->getUserPHID(), + phutil_json_encode( + array( + PhabricatorNamedQueryConfig::PROPERTY_PINNED => + $named_query->getQueryKey(), + )), + PhabricatorTime::getNow(), + PhabricatorTime::getNow()); + } + + $named_query->delete(); +}