@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
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
17foreach (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}