if ($this->user->id == $this->notice->profile_id) {
if (Event::handle('StartDeleteOwnNotice', array($this->user, $this->notice))) {
- $this->notice->delete();
+ $this->notice->deleteAs($this->scoped);
Event::handle('EndDeleteOwnNotice', array($this->user, $this->notice));
}
$this->showNotice();
}
if (Event::handle('StartDeleteOwnNotice', array($this->auth_user, $this->notice))) {
- $this->notice->delete();
+ $this->notice->deleteAs($this->scoped);
Event::handle('EndDeleteOwnNotice', array($this->auth_user, $this->notice));
}
{
if ($this->arg('yes')) {
if (Event::handle('StartDeleteOwnNotice', array($this->scoped->getUser(), $this->notice))) {
- $this->notice->delete();
+ $this->notice->deleteAs($this->scoped);
Event::handle('EndDeleteOwnNotice', array($this->scoped->getUser(), $this->notice));
}
} else {
$this->_profile[$this->profile_id] = $profile;
}
- public function deleteAs(Profile $actor)
+ public function deleteAs(Profile $actor, $delete_event=true)
{
- if ($this->getProfile()->sameAs($actor) || $actor->hasRight(Right::DELETEOTHERSNOTICE)) {
- return $this->delete();
+ if (!$this->getProfile()->sameAs($actor) && !$actor->hasRight(Right::DELETEOTHERSNOTICE)) {
+ throw new AuthorizationException(_('You are not allowed to delete another user\'s notice.'));
}
- throw new AuthorizationException(_('You are not allowed to delete other user\'s notices'));
- }
- public function delete($useWhere=false)
- {
if (Event::handle('NoticeDeleteRelated', array($this))) {
-
// Clear related records
-
$this->clearReplies();
$this->clearLocation();
$this->clearRepeats();
$this->clearGroupInboxes();
$this->clearFiles();
$this->clearAttentions();
-
// NOTE: we don't clear queue items
}
+ $result = null;
+ if (!$delete_event || Event::handle('DeleteNoticeAsProfile', array($this, $actor, &$result))) {
+ // If $delete_event is true, we run the event. If the Event then
+ // returns false it is assumed everything was handled properly
+ // and the notice was deleted.
+ $result = $this->delete();
+ }
+ return $result;
+ }
+
+ public function delete($useWhere=false)
+ {
$result = parent::delete($useWhere);
$this->blowOnDelete();
$sink->postActivity($act);
$notice = Notice::getKV('uri', $act->objects[0]->id);
if (!empty($notice)) {
- $notice->delete();
+ $notice->deleteAs($user->getProfile(), false);
}
break;
case ActivityVerb::JOIN:
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;
}
/**
);
}
- 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();
);
$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));
// NB: this will delete the rsvp, too
if (!empty($notice)) {
common_log(LOG_DEBUG, "Deleting notice...");
- $notice->delete();
+ $notice->deleteAs($this->scoped);
} else {
common_log(LOG_DEBUG, "Deleting RSVP alone...");
$this->rsvp->delete();
$this->photo->delete();
if (Event::handle('StartDeleteOwnNotice', array($this->user, $notice))) {
- $notice->delete();
+ $notice->deleteAs($this->scoped);
Event::handle('EndDeleteOwnNotice', array($this->user, $notice));
}
$this->showForm(_('Success!'));