function delete() { // For auditing purposes, save a record that the notice // was deleted. // @fixme we have some cases where things get re-run and so the // insert fails. $deleted = Deleted_notice::staticGet('id', $this->id); if (!$deleted) { $deleted = new Deleted_notice(); $deleted->id = $this->id; $deleted->profile_id = $this->profile_id; $deleted->uri = $this->uri; $deleted->created = $this->created; $deleted->deleted = common_sql_now(); $deleted->insert(); } if (Event::handle('NoticeDeleteRelated', array($this))) { // Clear related records $this->clearReplies(); $this->clearRepeats(); $this->clearFaves(); $this->clearTags(); $this->clearGroupInboxes(); // NOTE: we don't clear inboxes // NOTE: we don't clear queue items } $result = parent::delete(); $this->blowOnDelete(); return $result; }
/** * This is run before ->insert, so our task in this function is just to * delete if it is the delete verb. */ public function onStartNoticeSave(Notice $stored) { // DELETE is a bit special, we have to remove the existing entry and then // add a new one with the same URI in order to trigger the distribution. // (that's why we don't use $this->isMyNotice(...)) if (!ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::DELETE))) { return true; } try { $target = Notice::getByUri($stored->uri); } catch (NoResultException $e) { throw new AlreadyFulfilledException('Notice URI not found, so we have nothing to delete.'); } $actor = $stored->getProfile(); $owner = $target->getProfile(); if ($owner->hasRole(Profile_role::DELETED)) { // Don't bother with replacing notices if its author is being deleted. // The later "StoreActivityObject" will pick this up and execute // the deletion then. // (the "delete verb notice" is too new to ever pass through Notice::saveNew // which otherwise wouldn't execute the StoreActivityObject event) return true; } // Since the user deleting may not be the same as the notice's owner, // double-check this and also set the "re-stored" notice profile_id. if (!$actor->sameAs($owner) && !$actor->hasRight(Right::DELETEOTHERSNOTICE)) { throw new AuthorizationException(_('You are not allowed to delete another user\'s notice.')); } // We copy the identifying fields and replace the sensitive ones. //$stored->id = $target->id; // We can't copy this since DB_DataObject won't inject it anyway $props = array('uri', 'profile_id', 'conversation', 'reply_to', 'created', 'repeat_of', 'object_type', 'is_local', 'scope'); foreach ($props as $prop) { $stored->{$prop} = $target->{$prop}; } // Let's see if this has been deleted already. try { $deleted = Deleted_notice::getByKeys(['uri' => $stored->getUri()]); return $deleted; } catch (NoResultException $e) { $deleted = new Deleted_notice(); $deleted->id = $target->getID(); $deleted->profile_id = $actor->getID(); $deleted->uri = $stored->getUri(); $deleted->act_created = $stored->created; $deleted->created = common_sql_now(); // throws exception on error $result = $deleted->insert(); } // Now we delete the original notice, leaving the id and uri free. $target->delete(); return true; }
function delete() { // For auditing purposes, save a record that the notice // was deleted. $deleted = new Deleted_notice(); $deleted->id = $this->id; $deleted->profile_id = $this->profile_id; $deleted->uri = $this->uri; $deleted->created = $this->created; $deleted->deleted = common_sql_now(); $deleted->insert(); // Clear related records $this->clearReplies(); $this->clearRepeats(); $this->clearFaves(); $this->clearTags(); $this->clearGroupInboxes(); // NOTE: we don't clear inboxes // NOTE: we don't clear queue items $result = parent::delete(); $this->blowOnDelete(); return $result; }