1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Minor, fix this patch so it applies after channel got deleted from the event table.

Test plan: Applied the patch explicitly with `--apply`.
This commit is contained in:
epriestley 2013-02-25 21:22:38 -08:00
parent 32d23254c9
commit 0f22854823

View file

@ -11,33 +11,46 @@ $event_table->beginReadLocking();
$channel_table->beginReadLocking(); $channel_table->beginReadLocking();
$events = new LiskMigrationIterator($event_table); $events = new LiskMigrationIterator($event_table);
$conn_w = $channel_table->establishConnection('w');
foreach ($events as $event) { foreach ($events as $event) {
if ($event->getChannelID()) { if ($event->getChannelID()) {
continue; continue;
} }
$matched = $channel_table->loadOneWhere( $event_row = queryfx_one(
"channelName = %s AND serviceName = %s AND serviceType = %s", $conn_w,
$event->getChannel(), 'SELECT channel FROM %T WHERE id = %d',
$event->getTable(),
$event->getChannelID());
$event_channel = $event_row['channel'];
$matched = queryfx_one(
$conn_w,
'SELECT * FROM %T WHERE
channelName = %s AND serviceName = %s AND serviceType = %s',
$event_channel,
'', '',
''); '');
if (!$matched) { if (!$matched) {
$matched = id(new PhabricatorChatLogChannel()) $matched = id(new PhabricatorChatLogChannel())
->setChannelName($event->getChannel()) ->setChannelName($event_channel)
->setServiceType('') ->setServiceType('')
->setServiceName('') ->setServiceName('')
->setViewPolicy(PhabricatorPolicies::POLICY_USER) ->setViewPolicy(PhabricatorPolicies::POLICY_USER)
->setEditPolicy(PhabricatorPolicies::POLICY_USER) ->setEditPolicy(PhabricatorPolicies::POLICY_USER)
->save(); ->save();
$matched_id = $matched->getID();
} else {
$matched_id = $matched['id'];
} }
queryfx( queryfx(
$event->establishConnection('w'), $event->establishConnection('w'),
'UPDATE %T SET channelID = %d WHERE id = %d', 'UPDATE %T SET channelID = %d WHERE id = %d',
$event->getTableName(), $event->getTableName(),
$matched->getID(), $matched_id,
$event->getID()); $event->getID());
} }