I think all the notice deletion calls are event-compatible now

This means we can handle DeleteNoticeAsProfile in plugins, such as
the ActivityModeration plugin.
This commit is contained in:
Mikael Nordfeldth
2015-10-03 12:26:09 +02:00
parent 88f7bb1ed5
commit dac617d95a
9 changed files with 41 additions and 26 deletions

View File

@@ -59,13 +59,21 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin
public function deleteRelated(Notice $notice)
{
if ($notice->getProfile()->hasRole(Profile_role::DELETED)) {
// Don't save a new Deleted_notice entry if the profile is being deleted
// pass
}
public function onDeleteNoticeAsProfile(Notice $stored, Profile $actor, &$result) {
// By adding a new 'delete' verb we will eventually trigger $this->saveObjectFromActivity
if (false === Deleted_notice::addNew($stored, $actor)) {
// false is returned if we did not have an error, but did not create the object
// (i.e. the author is currently being deleted)
return true;
}
// For auditing purposes, save a record that the notice was deleted.
return Deleted_notice::addNew($notice);
// We return false (to stop the event) if the deleted_notice entry was
// added, which means we have run $this->saveObjectFromActivity which
// in turn has called the delete function of the notice.
return false;
}
/**

View File

@@ -54,13 +54,15 @@ class Deleted_notice extends Managed_DataObject
);
}
public static function addNew(Notice $notice)
public static function addNew(Notice $notice, Profile $actor=null)
{
$actor = $notice->getProfile();
if (is_null($actor)) {
$actor = $notice->getProfile();
}
if ($actor->hasRole(Profile_role::DELETED)) {
// Don't emit notices if the user is deleted
return true;
if ($notice->getProfile()->hasRole(Profile_role::DELETED)) {
// Don't emit notices if the notice author is (being) deleted
return false;
}
$act = new Activity();
@@ -80,7 +82,7 @@ class Deleted_notice extends Managed_DataObject
);
$act->actor = $actor->asActivityObject();
$act->target = new ActivityObject();
$act->target = new ActivityObject(); // We don't save the notice object, as it's supposed to be removed!
$act->target->id = $notice->getUri();
$act->objects = array(clone($act->target));