1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

Migrate old Maniphest custom queries to new query infrastructure

Summary: Ref T2625. EVERYONE LOVES MIGRATIONS!!!

Test Plan:
  - Created and migrated a query with every field, verified results were preserved.
  - Created and migrated a query using "noproject" and "upforgrabs" magic, verified results were preserved.

Here's the pre-migration "everything" query:

{F58110}

Here it is after migration:

{F58111}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

Differential Revision: https://secure.phabricator.com/D6977
This commit is contained in:
epriestley 2013-09-13 09:23:35 -07:00
parent a82c3a8914
commit 9864d562dd
2 changed files with 212 additions and 0 deletions

View file

@ -0,0 +1,208 @@
<?php
// NOTE: If you need to make any significant updates to this to deal with
// future changes to objects, it's probably better to just wipe the whole
// migration. This feature doesn't see overwhelming amounts of use, and users
// who do use it can recreate their queries fairly easily with the new
// interface. By the time this needs to be updated, the vast majority of
// users who it impacts will likely have migrated their data already.
$table = new ManiphestTask();
$conn_w = $table->establishConnection('w');
$search_table = new PhabricatorSearchQuery();
$search_conn_w = $search_table->establishConnection('w');
echo "Updating saved Maniphest queries...\n";
$rows = new LiskRawMigrationIterator($conn_w, 'maniphest_savedquery');
foreach ($rows as $row) {
$id = $row['id'];
echo "Updating query {$id}...\n";
$data = queryfx_one(
$search_conn_w,
'SELECT parameters FROM %T WHERE queryKey = %s',
$search_table->getTableName(),
$row['queryKey']);
if (!$data) {
echo "Unable to locate query data.\n";
continue;
}
$data = json_decode($data['parameters'], true);
if (!is_array($data)) {
echo "Unable to decode query data.\n";
continue;
}
if (idx($data, 'view') != 'custom') {
echo "Query is not a custom query.\n";
continue;
}
$new_data = array(
'limit' => 1000,
);
if (isset($data['lowPriority']) || isset($data['highPriority'])) {
$lo = idx($data, 'lowPriority');
$hi = idx($data, 'highPriority');
$priorities = array();
$all = ManiphestTaskPriority::getTaskPriorityMap();
foreach ($all as $pri => $name) {
if (($lo !== null) && ($pri < $lo)) {
continue;
}
if (($hi !== null) && ($pri > $hi)) {
continue;
}
$priorities[] = $pri;
}
if (count($priorities) != count($all)) {
$new_data['priorities'] = $priorities;
}
}
foreach ($data as $key => $value) {
switch ($key) {
case 'fullTextSearch':
if (strlen($value)) {
$new_data['fulltext'] = $value;
}
break;
case 'userPHIDs':
// This was (I think?) one-off data provied to specific hard-coded
// queries.
break;
case 'projectPHIDs':
foreach ($value as $k => $v) {
if ($v === null || $v === ManiphestTaskOwner::PROJECT_NO_PROJECT) {
$new_data['withNoProject'] = true;
unset($value[$k]);
break;
}
}
if ($value) {
$new_data['allProjectPHIDs'] = $value;
}
break;
case 'anyProjectPHIDs':
if ($value) {
$new_data['anyProjectPHIDs'] = $value;
}
break;
case 'anyUserProjectPHIDs':
if ($value) {
$new_data['userProjectPHIDs'] = $value;
}
break;
case 'excludeProjectPHIDs':
if ($value) {
$new_data['excludeProjectPHIDs'] = $value;
}
break;
case 'ownerPHIDs':
foreach ($value as $k => $v) {
if ($v === null || $v === ManiphestTaskOwner::OWNER_UP_FOR_GRABS) {
$new_data['withUnassigned'] = true;
unset($value[$k]);
break;
}
}
if ($value) {
$new_data['assignedPHIDs'] = $value;
}
break;
case 'authorPHIDs':
if ($value) {
$new_data['authorPHIDs'] = $value;
}
break;
case 'taskIDs':
if ($value) {
$new_data['ids'] = $value;
}
break;
case 'status':
$include_open = !empty($value['open']);
$include_closed = !empty($value['closed']);
if ($include_open xor $include_closed) {
if ($include_open) {
$new_data['statuses'] = array(
ManiphestTaskStatus::STATUS_OPEN,
);
} else {
$statuses = array();
foreach (ManiphestTaskStatus::getTaskStatusMap() as $status => $n) {
if ($status != ManiphestTaskStatus::STATUS_OPEN) {
$statuses[] = $status;
}
}
$new_data['statuses'] = $statuses;
}
}
break;
case 'order':
$map = array(
'priority' => 'priority',
'created' => 'created',
'title' => 'title',
);
if (isset($map[$value])) {
$new_data['order'] = $map[$value];
} else {
$new_data['order'] = 'priority';
}
break;
case 'group':
$map = array(
'priority' => 'priority',
'owner' => 'assigned',
'status' => 'status',
'project' => 'project',
'none' => 'none',
);
if (isset($map[$value])) {
$new_data['group'] = $map[$value];
} else {
$new_data['group'] = 'priority';
}
break;
}
}
$saved = id(new PhabricatorSavedQuery())
->setEngineClassName('ManiphestTaskSearchEngine');
foreach ($new_data as $key => $value) {
$saved->setParameter($key, $value);
}
try {
$saved->save();
} catch (AphrontQueryDuplicateKeyException $ex) {
// Ignore this, we just have duplicate saved queries.
}
$named = id(new PhabricatorNamedQuery())
->setEngineClassName('ManiphestTaskSearchEngine')
->setQueryKey($saved->getQueryKey())
->setQueryName($row['name'])
->setUserPHID($row['userPHID']);
try {
$named->save();
} catch (Exception $ex) {
// The user already has this query under another name. This can occur if
// the migration runs twice.
echo "Failed to save named query.\n";
continue;
}
echo "OK.\n";
}
echo "Done.\n";

View file

@ -1588,6 +1588,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'type' => 'php',
'name' => $this->getPatchPath('20130912.maniphest.4.fillindex.php'),
),
'20130913.maniphest.1.migratesearch.php' => array(
'type' => 'php',
'name' => $this->getPatchPath('20130913.maniphest.1.migratesearch.php'),
),
);
}
}