2013-02-18 19:50:07 +01:00
|
|
|
<?php
|
|
|
|
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Updating channel IDs of previous chatlog events...')."\n";
|
2013-02-18 19:50:07 +01:00
|
|
|
$event_table = new PhabricatorChatLogEvent();
|
|
|
|
$channel_table = new PhabricatorChatLogChannel();
|
|
|
|
|
|
|
|
$event_table->openTransaction();
|
|
|
|
$channel_table->openTransaction();
|
|
|
|
|
|
|
|
$event_table->beginReadLocking();
|
|
|
|
$channel_table->beginReadLocking();
|
|
|
|
|
|
|
|
$events = new LiskMigrationIterator($event_table);
|
2013-02-26 06:22:38 +01:00
|
|
|
$conn_w = $channel_table->establishConnection('w');
|
2013-02-18 19:50:07 +01:00
|
|
|
|
|
|
|
foreach ($events as $event) {
|
|
|
|
if ($event->getChannelID()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-02-26 06:22:38 +01:00
|
|
|
$event_row = queryfx_one(
|
|
|
|
$conn_w,
|
|
|
|
'SELECT channel FROM %T WHERE id = %d',
|
2013-02-26 14:23:31 +01:00
|
|
|
$event->getTableName(),
|
|
|
|
$event->getID());
|
2013-02-26 06:22:38 +01:00
|
|
|
$event_channel = $event_row['channel'];
|
|
|
|
|
|
|
|
$matched = queryfx_one(
|
|
|
|
$conn_w,
|
|
|
|
'SELECT * FROM %T WHERE
|
|
|
|
channelName = %s AND serviceName = %s AND serviceType = %s',
|
2013-02-26 14:23:31 +01:00
|
|
|
$channel_table->getTableName(),
|
2013-02-26 06:22:38 +01:00
|
|
|
$event_channel,
|
2013-02-18 19:50:07 +01:00
|
|
|
'',
|
|
|
|
'');
|
|
|
|
|
|
|
|
if (!$matched) {
|
|
|
|
$matched = id(new PhabricatorChatLogChannel())
|
2013-02-26 06:22:38 +01:00
|
|
|
->setChannelName($event_channel)
|
2013-02-18 19:50:07 +01:00
|
|
|
->setServiceType('')
|
|
|
|
->setServiceName('')
|
|
|
|
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
|
|
|
->setEditPolicy(PhabricatorPolicies::POLICY_USER)
|
|
|
|
->save();
|
2013-02-26 06:22:38 +01:00
|
|
|
$matched_id = $matched->getID();
|
|
|
|
} else {
|
|
|
|
$matched_id = $matched['id'];
|
2013-02-18 19:50:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
queryfx(
|
|
|
|
$event->establishConnection('w'),
|
|
|
|
'UPDATE %T SET channelID = %d WHERE id = %d',
|
|
|
|
$event->getTableName(),
|
2013-02-26 06:22:38 +01:00
|
|
|
$matched_id,
|
2013-02-18 19:50:07 +01:00
|
|
|
$event->getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
$event_table->endReadLocking();
|
|
|
|
$channel_table->endReadLocking();
|
|
|
|
|
|
|
|
$event_table->saveTransaction();
|
|
|
|
$channel_table->saveTransaction();
|
|
|
|
|
2015-05-22 09:27:56 +02:00
|
|
|
echo "\n".pht('Done.')."\n";
|