[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/resources/sql/autopatches/ -> 20140420.rel.2.objectmig.php (source)

   1  <?php
   2  
   3  $pull_table = new ReleephRequest();
   4  $table_name = $pull_table->getTableName();
   5  $conn_w = $pull_table->establishConnection('w');
   6  
   7  echo "Setting object PHIDs for requests...\n";
   8  foreach (new LiskMigrationIterator($pull_table) as $pull) {
   9    $id = $pull->getID();
  10  
  11    echo "Migrating pull request {$id}...\n";
  12    if ($pull->getRequestedObjectPHID()) {
  13      // We already have a valid PHID, so skip this request.
  14      continue;
  15    }
  16  
  17    $commit_phids = $pull->getCommitPHIDs();
  18    if (count($commit_phids) != 1) {
  19      // At the time this migration was written, all requests had exactly one
  20      // commit. If a request has more than one, we don't have the information
  21      // we need to process it.
  22      continue;
  23    }
  24  
  25    $commit_phid = head($commit_phids);
  26  
  27    $revision_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
  28      $commit_phid,
  29      PhabricatorEdgeConfig::TYPE_COMMIT_HAS_DREV);
  30  
  31    if ($revision_phids) {
  32      $object_phid = head($revision_phids);
  33    } else {
  34      $object_phid = $commit_phid;
  35    }
  36  
  37    queryfx(
  38      $conn_w,
  39      'UPDATE %T SET requestedObjectPHID = %s WHERE id = %d',
  40      $table_name,
  41      $object_phid,
  42      $id);
  43  }
  44  
  45  echo "Done.\n";


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