Deleted_notice is pluginified, don't call directly from core

This commit is contained in:
Mikael Nordfeldth 2016-01-13 21:19:20 +01:00
parent 45dd343126
commit adba38ce20
3 changed files with 35 additions and 16 deletions

View File

@ -74,16 +74,21 @@ class ApiStatusesShowAction extends ApiPrivateAuthAction
$this->notice_id = (int)$this->trimmed('id');
$this->notice = Notice::getKV('id', $this->notice_id);
if (!$this->notice instanceof Notice) {
$deleted = Deleted_notice::getKV('id', $this->notice_id);
if ($deleted instanceof Deleted_notice) {
$this->notice = null;
try {
$this->notice = Notice::getByID($this->notice_id);
} catch (NoResultException $e) {
// No such notice was found, maybe it was deleted?
$deleted = null;
Event::handle('IsNoticeDeleted', array($this->notice_id, &$deleted));
if ($deleted === true) {
// TRANS: Client error displayed trying to show a deleted notice.
$this->clientError(_('Notice deleted.'), 410);
throw new ClientException(_('Notice deleted.'), 410);
}
// TRANS: Client error displayed trying to show a non-existing notice.
$this->clientError(_('No such notice.'), 404);
throw new ClientException(_('No such notice.'), 404);
}
if (!$this->notice->inScope($this->scoped)) {
// TRANS: Client exception thrown when trying a view a notice the user has no access to.
throw new ClientException(_('Access restricted.'), 403);

View File

@ -113,20 +113,22 @@ class ShownoticeAction extends ManagedAction
{
$id = $this->arg('notice');
$notice = Notice::getKV('id', $id);
if ($notice instanceof Notice) {
$notice = null;
try {
$notice = Notice::getByID($id);
// Alright, got it!
return $notice;
}
// Did we use to have it, and it got deleted?
$deleted = Deleted_notice::getKV('id', $id);
if ($deleted instanceof Deleted_notice) {
// TRANS: Client error displayed trying to show a deleted notice.
$this->clientError(_('Notice deleted.'), 410);
} catch (NoResultException $e) {
// Hm, not found.
$deleted = null;
Event::handle('IsNoticeDeleted', array($id, &$deleted));
if ($deleted === true) {
// TRANS: Client error displayed trying to show a deleted notice.
throw new ClientException(_('Notice deleted.'), 410);
}
}
// TRANS: Client error displayed trying to show a non-existing notice.
$this->clientError(_('No such notice.'), 404);
throw new ClientException(_('No such notice.'), 404);
}
/**

View File

@ -46,6 +46,18 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin
return false;
}
public function onIsNoticeDeleted($id, &$deleted)
{
try {
$found = Deleted_notice::getByID($id);
$deleted = ($found instanceof Deleted_notice);
} catch (NoResultException $e) {
$deleted = false;
}
// return true (continue event) if $deleted is false, return false (stop event) if deleted notice was found
return !$deleted;
}
protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
{
// FIXME: switch based on action type