]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Start reworking Bookmark plugin for more modern code
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 10 Oct 2015 19:53:45 +0000 (21:53 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 10 Oct 2015 19:56:02 +0000 (21:56 +0200)
lib/activityhandlerplugin.php
plugins/Bookmark/BookmarkPlugin.php
plugins/Bookmark/classes/Bookmark.php

index c4ff7e3f38770dafd082db592925c6f2909888a2..2544179c5e2e96a6a196f75de45325fa737674f0 100644 (file)
@@ -281,10 +281,14 @@ abstract class ActivityHandlerPlugin extends Plugin
      *
      * @return boolean hook value
      */
-    function onNoticeDeleteRelated(Notice $notice)
+    public function onNoticeDeleteRelated(Notice $notice)
     {
         if ($this->isMyNotice($notice)) {
-            $this->deleteRelated($notice);
+            try {
+                $this->deleteRelated($notice);
+            } catch (AlreadyFulfilledException $e) {
+                // Nothing to see here, it's obviously already gone...
+            }
         }
 
         // Always continue this event in our activity handling plugins.
index 547efa2370104187891241cfbd7ba90d7ad689c8..6b0c07b6a5e9b8e32975cadf9332119efe513f51 100644 (file)
@@ -280,14 +280,12 @@ class BookmarkPlugin extends MicroAppPlugin
      */
     function deleteRelated(Notice $notice)
     {
-       if ($this->isMyNotice($notice)) {
-               
-               $nb = Bookmark::getByNotice($notice);
-
-               if (!empty($nb)) {
-               $nb->delete();
-               }
-       }
+        try {
+            $nb = Bookmark::fromStored($notice);
+        } catch (NoResultException $e) {
+            throw new AlreadyFulfilledException('Bookmark already gone when deleting: '.$e->getMessage());
+        }
+        $nb->delete();
        
         return true;
     }
@@ -388,12 +386,12 @@ class BookmarkPlugin extends MicroAppPlugin
                    "Formatting notice {$notice->uri} as a bookmark.");
 
         $object = new ActivityObject();
-        $nb = Bookmark::getByNotice($notice);
+        $nb = Bookmark::fromStored($notice);
 
         $object->id      = $notice->uri;
         $object->type    = ActivityObject::BOOKMARK;
-        $object->title   = $nb->title;
-        $object->summary = $nb->description;
+        $object->title   = $nb->getTitle();
+        $object->summary = $nb->getDescription();
         $object->link    = $notice->getUrl();
 
         // Attributes of the URL
@@ -481,14 +479,10 @@ class BookmarkPlugin extends MicroAppPlugin
     {
         assert($obj->type == ActivityObject::BOOKMARK);
 
-        $bm = Bookmark::getKV('uri', $obj->id);
-
-        if (empty($bm)) {
-            throw new ServerException("Unknown bookmark: " . $obj->id);
-        }
+        $bm = Bookmark::getByPK(array('uri', $obj->id));
 
-        $out['displayName'] = $bm->title;
-        $out['targetUrl']   = $bm->url;
+        $out['displayName'] = $bm->getTitle();
+        $out['targetUrl']   = $bm->getUrl();
 
         return true;
     }
@@ -501,24 +495,32 @@ class BookmarkPlugin extends MicroAppPlugin
         $nli->out->elementEnd('div');
     }
 
-    protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
+    public function getDescription()
+    {
+        return $this->description;
+    }
+
+    public function getTitle()
     {
-        $nb = Bookmark::getByNotice($stored);
-
-        if (empty($nb)) {
-            common_log(LOG_ERR, "No bookmark for notice {$stored->id}");
-            parent::showContent();
-            return;
-        } else if (empty($nb->url)) {
-            common_log(LOG_ERR, "No url for bookmark {$nb->id} for notice {$stored->id}");
-            parent::showContent();
-            return;
+        return $this->title;
+    }
+
+    public function getUrl()
+    {
+        if (empty($this->url)) {
+            throw new InvalidUrlException($this->url);
         }
+        return $this->url;
+    }
+
+    protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
+    {
+        $nb = Bookmark::fromStored($stored);
 
         $profile = $stored->getProfile();
 
         // Whether to nofollow
-        $attrs = array('href' => $nb->url, 'class' => 'bookmark-title');
+        $attrs = array('href' => $nb->getUrl(), 'class' => 'bookmark-title');
 
         $nf = common_config('nofollow', 'external');
 
index b680634ffc82ae8ad995b86bff099f3ba63394d0..e92fd33449453a6d91d53d4bbbc1e81b9c992b23 100644 (file)
@@ -74,8 +74,8 @@ class Bookmark extends Managed_DataObject
                 'bookmark_uri_key' => array('uri'),
             ),
             'foreign keys' => array(
-                'bookmark_profile_id_fkey' => array('profile', array('profile_id' => 'id'))
-                'bookmark_uri_fkey' => array('notice', array('uri' => 'uri'))
+                'bookmark_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
+                'bookmark_uri_fkey' => array('notice', array('uri' => 'uri')),
             ),
             'indexes' => array('bookmark_created_idx' => array('created'),
                             'bookmark_url_idx' => array('url'),