From 0f22854823f041d0f9d8e1d06c8d9cef736df5a7 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 25 Feb 2013 21:22:38 -0800 Subject: [PATCH] Minor, fix this patch so it applies after `channel` got deleted from the event table. Test plan: Applied the patch explicitly with `--apply`. --- .../sql/patches/20130218.updatechannelid.php | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/resources/sql/patches/20130218.updatechannelid.php b/resources/sql/patches/20130218.updatechannelid.php index ee2e2e82be..f46674a110 100644 --- a/resources/sql/patches/20130218.updatechannelid.php +++ b/resources/sql/patches/20130218.updatechannelid.php @@ -11,33 +11,46 @@ $event_table->beginReadLocking(); $channel_table->beginReadLocking(); $events = new LiskMigrationIterator($event_table); +$conn_w = $channel_table->establishConnection('w'); foreach ($events as $event) { if ($event->getChannelID()) { continue; } - $matched = $channel_table->loadOneWhere( - "channelName = %s AND serviceName = %s AND serviceType = %s", - $event->getChannel(), + $event_row = queryfx_one( + $conn_w, + '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) { $matched = id(new PhabricatorChatLogChannel()) - ->setChannelName($event->getChannel()) + ->setChannelName($event_channel) ->setServiceType('') ->setServiceName('') ->setViewPolicy(PhabricatorPolicies::POLICY_USER) ->setEditPolicy(PhabricatorPolicies::POLICY_USER) ->save(); + $matched_id = $matched->getID(); + } else { + $matched_id = $matched['id']; } queryfx( $event->establishConnection('w'), 'UPDATE %T SET channelID = %d WHERE id = %d', $event->getTableName(), - $matched->getID(), + $matched_id, $event->getID()); }