From 4d6df7dc146b9ea73c0fea8e59f7dbecb4fe12f4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 8 Jun 2012 19:15:42 -0700 Subject: [PATCH] Minor, fix insertNotifications() for unmigrated callsites. See discussion in rP3a6ee79190b709d84ff79865d1c1d6234e5c102a. --- .../feed/PhabricatorFeedStoryPublisher.php | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/applications/feed/PhabricatorFeedStoryPublisher.php b/src/applications/feed/PhabricatorFeedStoryPublisher.php index 2d54e4a567..d80073980b 100644 --- a/src/applications/feed/PhabricatorFeedStoryPublisher.php +++ b/src/applications/feed/PhabricatorFeedStoryPublisher.php @@ -104,35 +104,39 @@ final class PhabricatorFeedStoryPublisher { private function insertNotifications($chrono_key) { + if (!$this->subscribedPHIDs) { + return; + } + if (!$this->primaryObjectPHID) { - throw - new Exception("Call setPrimaryObjectPHID() before Publishing!"); + throw new Exception( + "You must call setPrimaryObjectPHID() if you setSubscribedPHIDs()!"); } - if ($this->subscribedPHIDs) { - $notif = new PhabricatorFeedStoryNotification(); - $sql = array(); - $conn = $notif->establishConnection('w'); - foreach (array_unique($this->subscribedPHIDs) as $user_phid) { - $sql[] = qsprintf( - $conn, - '(%s, %s, %s, %d)', - $this->primaryObjectPHID, - $user_phid, - $chrono_key, - 0); - } + $notif = new PhabricatorFeedStoryNotification(); + $sql = array(); + $conn = $notif->establishConnection('w'); - queryfx( + foreach (array_unique($this->subscribedPHIDs) as $user_phid) { + $sql[] = qsprintf( $conn, - 'INSERT INTO %T - (primaryObjectPHID, userPHID, chronologicalKey, hasViewed) - VALUES %Q', - $notif->getTableName(), - implode(', ', $sql)); + '(%s, %s, %s, %d)', + $this->primaryObjectPHID, + $user_phid, + $chrono_key, + 0); } + queryfx( + $conn, + 'INSERT INTO %T + (primaryObjectPHID, userPHID, chronologicalKey, hasViewed) + VALUES %Q', + $notif->getTableName(), + implode(', ', $sql)); } + + /** * We generate a unique chronological key for each story type because we want * to be able to page through the stream with a cursor (i.e., select stories