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(); +}