[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/resources/sql/autopatches/ -> 20140321.mstatus.2.mig.php (source)

   1  <?php
   2  
   3  $status_map = array(
   4    0 => 'open',
   5    1 => 'resolved',
   6    2 => 'wontfix',
   7    3 => 'invalid',
   8    4 => 'duplicate',
   9    5 => 'spite',
  10  );
  11  
  12  $conn_w = id(new ManiphestTask())->establishConnection('w');
  13  
  14  echo "Migrating tasks to new status constants...\n";
  15  foreach (new LiskMigrationIterator(new ManiphestTask()) as $task) {
  16    $id = $task->getID();
  17    echo "Migrating T{$id}...\n";
  18  
  19    $status = $task->getStatus();
  20    if (isset($status_map[$status])) {
  21      queryfx(
  22        $conn_w,
  23        'UPDATE %T SET status = %s WHERE id = %d',
  24        $task->getTableName(),
  25        $status_map[$status],
  26        $id);
  27    }
  28  }
  29  
  30  echo "Done.\n";
  31  
  32  
  33  echo "Migrating task transactions to new status constants...\n";
  34  foreach (new LiskMigrationIterator(new ManiphestTransaction()) as $xaction) {
  35    $id = $xaction->getID();
  36    echo "Migrating {$id}...\n";
  37  
  38    if ($xaction->getTransactionType() == ManiphestTransaction::TYPE_STATUS) {
  39      $old = $xaction->getOldValue();
  40      if ($old !== null && isset($status_map[$old])) {
  41        $old = $status_map[$old];
  42      }
  43  
  44      $new = $xaction->getNewValue();
  45      if (isset($status_map[$new])) {
  46        $new = $status_map[$new];
  47      }
  48  
  49      queryfx(
  50        $conn_w,
  51        'UPDATE %T SET oldValue = %s, newValue = %s WHERE id = %d',
  52        $xaction->getTableName(),
  53        json_encode($old),
  54        json_encode($new),
  55        $id);
  56    }
  57  }
  58  echo "Done.\n";
  59  
  60  $conn_w = id(new PhabricatorSavedQuery())->establishConnection('w');
  61  
  62  echo "Migrating searches to new status constants...\n";
  63  foreach (new LiskMigrationIterator(new PhabricatorSavedQuery()) as $query) {
  64    $id = $query->getID();
  65    echo "Migrating {$id}...\n";
  66  
  67    if ($query->getEngineClassName() !== 'ManiphestTaskSearchEngine') {
  68      continue;
  69    }
  70  
  71    $params = $query->getParameters();
  72    $statuses = idx($params, 'statuses', array());
  73    if ($statuses) {
  74      $changed = false;
  75      foreach ($statuses as $key => $status) {
  76        if (isset($status_map[$status])) {
  77          $statuses[$key] = $status_map[$status];
  78          $changed = true;
  79        }
  80      }
  81  
  82      if ($changed) {
  83        $params['statuses'] = $statuses;
  84  
  85        queryfx(
  86          $conn_w,
  87          'UPDATE %T SET parameters = %s WHERE id = %d',
  88          $query->getTableName(),
  89          json_encode($params),
  90          $id);
  91      }
  92    }
  93  }
  94  echo "Done.\n";


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1