[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/resources/sql/patches/ -> 20130403.conpherencecachemig.php (source)

   1  <?php
   2  
   3  echo "Migrating data from conpherence transactions to conpherence 'cache'...\n";
   4  
   5  $table = new ConpherenceThread();
   6  $table->openTransaction();
   7  $conn_w = $table->establishConnection('w');
   8  
   9  $participant_table = new ConpherenceParticipant();
  10  
  11  $conpherences = new LiskMigrationIterator($table);
  12  foreach ($conpherences as $conpherence) {
  13    echo 'Migrating conpherence #'.$conpherence->getID()."\n";
  14  
  15    $participants = id(new ConpherenceParticipant())
  16      ->loadAllWhere('conpherencePHID = %s', $conpherence->getPHID());
  17  
  18    $transactions = id(new ConpherenceTransaction())
  19      ->loadAllWhere('objectPHID = %s', $conpherence->getPHID());
  20  
  21    $participation_hash = mgroup($participants, 'getBehindTransactionPHID');
  22  
  23    $message_count = 0;
  24    $participants_to_cache = array();
  25    foreach ($transactions as $transaction) {
  26      $participants_to_cache[] = $transaction->getAuthorPHID();
  27      if ($transaction->getTransactionType() ==
  28        PhabricatorTransactions::TYPE_COMMENT) {
  29        $message_count++;
  30      }
  31      $participants_to_update = idx(
  32        $participation_hash,
  33        $transaction->getPHID(),
  34        array());
  35      if ($participants_to_update) {
  36        queryfx(
  37          $conn_w,
  38          'UPDATE %T SET seenMessageCount = %d '.
  39          'WHERE conpherencePHID = %s AND participantPHID IN (%Ls)',
  40          $participant_table->getTableName(),
  41          $message_count,
  42          $conpherence->getPHID(),
  43          mpull($participants_to_update, 'getParticipantPHID'));
  44      }
  45    }
  46  
  47    $participants_to_cache = array_slice(
  48      array_unique(array_reverse($participants_to_cache)),
  49      0,
  50      10);
  51    queryfx(
  52      $conn_w,
  53      'UPDATE %T '.
  54      'SET recentParticipantPHIDs = %s, '.
  55      'messageCount = %d '.
  56      'WHERE phid = %s',
  57      $table->getTableName(),
  58      json_encode($participants_to_cache),
  59      $message_count,
  60      $conpherence->getPHID());
  61  }
  62  
  63  $table->saveTransaction();
  64  echo "\nDone.\n";


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