[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/resources/sql/patches/ -> 20130218.updatechannelid.php (source)

   1  <?php
   2  
   3  echo "Updating channel IDs of previous chatlog events...\n";
   4  $event_table = new PhabricatorChatLogEvent();
   5  $channel_table = new PhabricatorChatLogChannel();
   6  
   7  $event_table->openTransaction();
   8  $channel_table->openTransaction();
   9  
  10  $event_table->beginReadLocking();
  11  $channel_table->beginReadLocking();
  12  
  13  $events = new LiskMigrationIterator($event_table);
  14  $conn_w = $channel_table->establishConnection('w');
  15  
  16  foreach ($events as $event) {
  17    if ($event->getChannelID()) {
  18      continue;
  19    }
  20  
  21    $event_row = queryfx_one(
  22      $conn_w,
  23      'SELECT channel FROM %T WHERE id = %d',
  24      $event->getTableName(),
  25      $event->getID());
  26    $event_channel = $event_row['channel'];
  27  
  28    $matched = queryfx_one(
  29      $conn_w,
  30      'SELECT * FROM %T WHERE
  31        channelName = %s AND serviceName = %s AND serviceType = %s',
  32      $channel_table->getTableName(),
  33      $event_channel,
  34      '',
  35      '');
  36  
  37    if (!$matched) {
  38      $matched = id(new PhabricatorChatLogChannel())
  39        ->setChannelName($event_channel)
  40        ->setServiceType('')
  41        ->setServiceName('')
  42        ->setViewPolicy(PhabricatorPolicies::POLICY_USER)
  43        ->setEditPolicy(PhabricatorPolicies::POLICY_USER)
  44        ->save();
  45      $matched_id = $matched->getID();
  46    } else {
  47      $matched_id = $matched['id'];
  48    }
  49  
  50    queryfx(
  51      $event->establishConnection('w'),
  52      'UPDATE %T SET channelID = %d WHERE id = %d',
  53      $event->getTableName(),
  54      $matched_id,
  55      $event->getID());
  56  }
  57  
  58  $event_table->endReadLocking();
  59  $channel_table->endReadLocking();
  60  
  61  $event_table->saveTransaction();
  62  $channel_table->saveTransaction();
  63  
  64  echo "\nDone.\n";


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