*
* @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.
*/
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;
}
"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
{
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;
}
$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');
'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'),