Catch some exceptions in Linkback

This commit is contained in:
Mikael Nordfeldth 2016-03-24 02:00:16 +01:00
parent 49a91885c9
commit be22886be8
1 changed files with 30 additions and 25 deletions

View File

@ -59,41 +59,46 @@ class LinkbackPlugin extends Plugin
parent::__construct(); parent::__construct();
} }
function onHandleQueuedNotice($notice) function onHandleQueuedNotice(Notice $notice)
{ {
if (intval($notice->is_local) === Notice::LOCAL_PUBLIC) { if (!$notice->isLocal() || !$notice->isPublic()) {
// Try to avoid actually mucking with the return true;
// notice content }
$c = $notice->content;
$this->notice = $notice;
if(!$notice->getProfile()-> // Try to avoid actually mucking with the
getPref("linkbackplugin", "disable_linkbacks") // notice content
) { $c = $notice->content;
// Ignoring results $this->notice = $notice;
common_replace_urls_callback($c,
array($this, 'linkbackUrl'));
}
if($notice->isRepeat()) { if (!$notice->getProfile()->getPref('linkbackplugin', 'disable_linkbacks')) {
// Ignoring results
common_replace_urls_callback($c, array($this, 'linkbackUrl'));
}
try {
if ($notice->isRepeat()) {
$repeat = Notice::getByID($notice->repeat_of); $repeat = Notice::getByID($notice->repeat_of);
$this->linkbackUrl($repeat->getUrl()); $this->linkbackUrl($repeat->getUrl());
} else if(!empty($notice->reply_to)) { } elseif (!empty($notice->reply_to)) {
try { $parent = $notice->getParent();
$parent = $notice->getParent(); $this->linkbackUrl($parent->getUrl());
$this->linkbackUrl($parent->getUrl());
} catch (NoParentNoticeException $e) {
// can't link back to what we don't know (apparently parent notice disappeared from our db)
return true;
}
} }
} catch (InvalidUrlException $e) {
// can't send linkback to notice if we don't have a remote HTTP(S) URL
// but we can still ping the attention-receivers below
} catch (NoParentNoticeException $e) {
// can't send linkback to non-existing parent URL
return true;
}
// doubling up getReplies and getAttentionProfileIDs because we're not entirely migrated yet // doubling up getReplies and getAttentionProfileIDs because we're not entirely migrated yet
$replyProfiles = Profile::multiGet('id', array_unique(array_merge($notice->getReplies(), $notice->getAttentionProfileIDs()))); $replyProfiles = Profile::multiGet('id', array_unique(array_merge($notice->getReplies(), $notice->getAttentionProfileIDs())));
foreach($replyProfiles->fetchAll('profileurl') as $profileurl) { foreach ($replyProfiles->fetchAll('profileurl') as $profileurl) {
if (common_valid_http_url($profileurl)) {
$this->linkbackUrl($profileurl); $this->linkbackUrl($profileurl);
} }
} }
return true; return true;
} }