@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+46
+46
resources/sql/autopatches/20170824.search.01.saved.php
··· 1 + <?php 2 + 3 + // Before T12956, normal users could reorder (and disable) builtin queries. 4 + // After that change, there is a single global order which can only be 5 + // changed by administrators. 6 + 7 + // This migration removes the rows which store individual reordering and 8 + // disabling of queries. If a user had reordered queries in such a way that 9 + // a builtin query was at the top of the list, we try to write a preference 10 + // which pins that query as their default to minimize disruption. 11 + 12 + $table = new PhabricatorNamedQuery(); 13 + $conn = $table->establishConnection('w'); 14 + 15 + $config_table = new PhabricatorNamedQueryConfig(); 16 + 17 + foreach (new LiskMigrationIterator($table) as $named_query) { 18 + 19 + // If this isn't a builtin query, it isn't changing. Leave it alone. 20 + if (!$named_query->getIsBuiltin()) { 21 + continue; 22 + } 23 + 24 + // If the user reordered things but left a builtin query at the top, pin 25 + // the query before we remove the row. 26 + if ($named_query->getSequence() == 1) { 27 + queryfx( 28 + $conn, 29 + 'INSERT IGNORE INTO %T 30 + (engineClassName, scopePHID, properties, dateCreated, dateModified) 31 + VALUES 32 + (%s, %s, %s, %d, %d)', 33 + $config_table->getTableName(), 34 + $named_query->getEngineClassName(), 35 + $named_query->getUserPHID(), 36 + phutil_json_encode( 37 + array( 38 + PhabricatorNamedQueryConfig::PROPERTY_PINNED => 39 + $named_query->getQueryKey(), 40 + )), 41 + PhabricatorTime::getNow(), 42 + PhabricatorTime::getNow()); 43 + } 44 + 45 + $named_query->delete(); 46 + }