From: Mikael Nordfeldth Date: Sun, 3 Jan 2016 21:35:49 +0000 (+0100) Subject: Fave deletion would fail in some cases with missing profiles or notices X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bda30a92bc41912ac60dbd417aae00fc27eaa4fc;p=quix0rs-gnu-social.git Fave deletion would fail in some cases with missing profiles or notices --- diff --git a/plugins/Favorite/classes/Fave.php b/plugins/Favorite/classes/Fave.php index ad7cc67df8..7fa7705e8f 100644 --- a/plugins/Favorite/classes/Fave.php +++ b/plugins/Favorite/classes/Fave.php @@ -114,24 +114,38 @@ class Fave extends Managed_DataObject public function delete($useWhere=false) { - $profile = Profile::getKV('id', $this->user_id); - $notice = Notice::getKV('id', $this->notice_id); - $result = null; - if (Event::handle('StartDisfavorNotice', array($profile, $notice, &$result))) { + try { + $profile = $this->getActor(); + $notice = $this->getTarget(); + + if (Event::handle('StartDisfavorNotice', array($profile, $notice, &$result))) { + + $result = parent::delete($useWhere); + + self::blowCacheForProfileId($this->user_id); + self::blowCacheForNoticeId($this->notice_id); + self::blow('popular'); + + if ($result !== false) { + Event::handle('EndDisfavorNotice', array($profile, $notice)); + } + } + + } catch (NoResultException $e) { + common_log(LOG_INFO, '"'.get_class($e->obj).'" with id=='.var_export($e->obj->id, true).' object not found when deleting favorite, ignoring...'); + // Delete it without the event, as something is wrong and we don't want it anyway. $result = parent::delete($useWhere); self::blowCacheForProfileId($this->user_id); self::blowCacheForNoticeId($this->notice_id); self::blow('popular'); - - if ($result) { - Event::handle('EndDisfavorNotice', array($profile, $notice)); - } } + + return $result; } @@ -391,14 +405,7 @@ class Fave extends Managed_DataObject public function getTarget() { - // throws exception on failure - $target = new Notice(); - $target->id = $this->notice_id; - if (!$target->find(true)) { - throw new NoResultException($target); - } - - return $target; + return Notice::getByID($this->notice_id); } public function getTargetObject()