1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00
phorge-phorge/resources/sql/autopatches/20170824.search.01.saved.php
epriestley bc0963d54b 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
2017-08-24 15:25:00 -07:00

46 lines
1.5 KiB
PHP

<?php
// Before T12956, normal users could reorder (and disable) builtin queries.
// After that change, there is a single global order which can only be
// changed by administrators.
// This migration removes the rows which store individual reordering and
// disabling of queries. If a user had reordered queries in such a way that
// a builtin query was at the top of the list, we try to write a preference
// which pins that query as their default to minimize disruption.
$table = new PhabricatorNamedQuery();
$conn = $table->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();
}