From: Mikael Nordfeldth Date: Sat, 10 Oct 2015 19:53:45 +0000 (+0200) Subject: Start reworking Bookmark plugin for more modern code X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cae43344ecb4dbf0ac1309331bca4daaa27ca25b;p=quix0rs-gnu-social.git Start reworking Bookmark plugin for more modern code --- diff --git a/lib/activityhandlerplugin.php b/lib/activityhandlerplugin.php index c4ff7e3f38..2544179c5e 100644 --- a/lib/activityhandlerplugin.php +++ b/lib/activityhandlerplugin.php @@ -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. diff --git a/plugins/Bookmark/BookmarkPlugin.php b/plugins/Bookmark/BookmarkPlugin.php index 547efa2370..6b0c07b6a5 100644 --- a/plugins/Bookmark/BookmarkPlugin.php +++ b/plugins/Bookmark/BookmarkPlugin.php @@ -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'); diff --git a/plugins/Bookmark/classes/Bookmark.php b/plugins/Bookmark/classes/Bookmark.php index b680634ffc..e92fd33449 100644 --- a/plugins/Bookmark/classes/Bookmark.php +++ b/plugins/Bookmark/classes/Bookmark.php @@ -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'),