From 4c09c1dc477ef920aa408a99c88deac4e43df6e8 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 1 Mar 2011 17:01:35 -0800 Subject: [PATCH 1/2] Workaround for bug causing fatal error during favoriting; Profile::getCurrentNotice() was returning an ArrayList instead of a Notice directly due to pulling through Profile::getNotices(). This caused failure in Fave::addNew() which specifies it wants a Notice. Caused failure of the 'fav' IM command. --- classes/Profile.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classes/Profile.php b/classes/Profile.php index fd41c6139a..d030e38b1b 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -186,6 +186,10 @@ class Profile extends Memcached_DataObject $notice = $this->getNotices(0, 1); if ($notice->fetch()) { + if ($notice instanceof ArrayWrapper) { + // hack for things trying to work with single notices + return $notice->_items[0]; + } return $notice; } else { return null; From 3eb900e31f49c7d973266bb76e99eb0737f37880 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 1 Mar 2011 17:09:41 -0800 Subject: [PATCH 2/2] More fixes for 'fav' IM command: don't die with a fatal error if the notice has already been favored, and don't spew a warning when checking for user ID match. --- lib/command.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/command.php b/lib/command.php index 3fb4d76c75..29aa286d1d 100644 --- a/lib/command.php +++ b/lib/command.php @@ -287,6 +287,18 @@ class FavCommand extends Command function handle($channel) { $notice = $this->getNotice($this->other); + + $fave = new Fave(); + $fave->user_id = $this->user->id; + $fave->notice_id = $notice->id; + $fave->find(); + + if ($fave->fetch()) { + // TRANS: Error message text shown when a favorite could not be set because it has already been favorited. + $channel->error($this->user, _('Could not create favorite: already favorited.')); + return; + } + $fave = Fave::addNew($this->user->getProfile(), $notice); if (!$fave) { @@ -300,7 +312,7 @@ class FavCommand extends Command $other = User::staticGet('id', $notice->profile_id); - if ($other && $other->id != $user->id) { + if ($other && $other->id != $this->user->id) { if ($other->email && $other->emailnotifyfav) { mail_notify_fave($other, $this->user, $notice); }