Changeset View
Changeset View
Standalone View
Standalone View
resources/sql/autopatches/20140321.mstatus.2.mig.php
| <?php | <?php | ||||
| $status_map = array( | $status_map = array( | ||||
| 0 => 'open', | 0 => 'open', | ||||
| 1 => 'resolved', | 1 => 'resolved', | ||||
| 2 => 'wontfix', | 2 => 'wontfix', | ||||
| 3 => 'invalid', | 3 => 'invalid', | ||||
| 4 => 'duplicate', | 4 => 'duplicate', | ||||
| 5 => 'spite', | 5 => 'spite', | ||||
| ); | ); | ||||
| $conn_w = id(new ManiphestTask())->establishConnection('w'); | $conn_w = id(new ManiphestTask())->establishConnection('w'); | ||||
| echo "Migrating tasks to new status constants...\n"; | echo pht('Migrating tasks to new status constants...')."\n"; | ||||
| foreach (new LiskMigrationIterator(new ManiphestTask()) as $task) { | foreach (new LiskMigrationIterator(new ManiphestTask()) as $task) { | ||||
| $id = $task->getID(); | $id = $task->getID(); | ||||
| echo "Migrating T{$id}...\n"; | echo pht('Migrating %s...', "T{$id}")."\n"; | ||||
| $status = $task->getStatus(); | $status = $task->getStatus(); | ||||
| if (isset($status_map[$status])) { | if (isset($status_map[$status])) { | ||||
| queryfx( | queryfx( | ||||
| $conn_w, | $conn_w, | ||||
| 'UPDATE %T SET status = %s WHERE id = %d', | 'UPDATE %T SET status = %s WHERE id = %d', | ||||
| $task->getTableName(), | $task->getTableName(), | ||||
| $status_map[$status], | $status_map[$status], | ||||
| $id); | $id); | ||||
| } | } | ||||
| } | } | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||
| echo "Migrating task transactions to new status constants...\n"; | echo pht('Migrating task transactions to new status constants...')."\n"; | ||||
| foreach (new LiskMigrationIterator(new ManiphestTransaction()) as $xaction) { | foreach (new LiskMigrationIterator(new ManiphestTransaction()) as $xaction) { | ||||
| $id = $xaction->getID(); | $id = $xaction->getID(); | ||||
| echo "Migrating {$id}...\n"; | echo pht('Migrating %d...', $id)."\n"; | ||||
| if ($xaction->getTransactionType() == ManiphestTransaction::TYPE_STATUS) { | if ($xaction->getTransactionType() == ManiphestTransaction::TYPE_STATUS) { | ||||
| $old = $xaction->getOldValue(); | $old = $xaction->getOldValue(); | ||||
| if ($old !== null && isset($status_map[$old])) { | if ($old !== null && isset($status_map[$old])) { | ||||
| $old = $status_map[$old]; | $old = $status_map[$old]; | ||||
| } | } | ||||
| $new = $xaction->getNewValue(); | $new = $xaction->getNewValue(); | ||||
| if (isset($status_map[$new])) { | if (isset($status_map[$new])) { | ||||
| $new = $status_map[$new]; | $new = $status_map[$new]; | ||||
| } | } | ||||
| queryfx( | queryfx( | ||||
| $conn_w, | $conn_w, | ||||
| 'UPDATE %T SET oldValue = %s, newValue = %s WHERE id = %d', | 'UPDATE %T SET oldValue = %s, newValue = %s WHERE id = %d', | ||||
| $xaction->getTableName(), | $xaction->getTableName(), | ||||
| json_encode($old), | json_encode($old), | ||||
| json_encode($new), | json_encode($new), | ||||
| $id); | $id); | ||||
| } | } | ||||
| } | } | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||
| $conn_w = id(new PhabricatorSavedQuery())->establishConnection('w'); | $conn_w = id(new PhabricatorSavedQuery())->establishConnection('w'); | ||||
| echo "Migrating searches to new status constants...\n"; | echo pht('Migrating searches to new status constants...')."\n"; | ||||
| foreach (new LiskMigrationIterator(new PhabricatorSavedQuery()) as $query) { | foreach (new LiskMigrationIterator(new PhabricatorSavedQuery()) as $query) { | ||||
| $id = $query->getID(); | $id = $query->getID(); | ||||
| echo "Migrating {$id}...\n"; | echo pht('Migrating %d...', $id)."\n"; | ||||
| if ($query->getEngineClassName() !== 'ManiphestTaskSearchEngine') { | if ($query->getEngineClassName() !== 'ManiphestTaskSearchEngine') { | ||||
| continue; | continue; | ||||
| } | } | ||||
| $params = $query->getParameters(); | $params = $query->getParameters(); | ||||
| $statuses = idx($params, 'statuses', array()); | $statuses = idx($params, 'statuses', array()); | ||||
| if ($statuses) { | if ($statuses) { | ||||
| Show All 12 Lines | if ($changed) { | ||||
| $conn_w, | $conn_w, | ||||
| 'UPDATE %T SET parameters = %s WHERE id = %d', | 'UPDATE %T SET parameters = %s WHERE id = %d', | ||||
| $query->getTableName(), | $query->getTableName(), | ||||
| json_encode($params), | json_encode($params), | ||||
| $id); | $id); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||