]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fave deletion would fail in some cases with missing profiles or notices
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 3 Jan 2016 21:35:49 +0000 (22:35 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 3 Jan 2016 21:35:49 +0000 (22:35 +0100)
plugins/Favorite/classes/Fave.php

index ad7cc67df86ebccd10b9ac7c3a1a37430368cd77..7fa7705e8faee2a854c2f782ce883723c289b6a4 100644 (file)
@@ -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()