5 * @maintainer Mikael Nordfeldth <mmn@hethane.se>
7 class ActivityModerationPlugin extends ActivityVerbHandlerPlugin
14 public function types()
19 public function verbs()
21 return array(ActivityVerb::DELETE);
24 public function onBeforePluginCheckSchema()
26 Deleted_notice::beforeSchemaUpdate();
30 public function onCheckSchema()
32 $schema = Schema::get();
33 $schema->ensureTable('deleted_notice', Deleted_notice::schemaDef());
37 protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
39 // FIXME: switch based on action type
40 return _m('TITLE', 'Notice moderation');
43 protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
48 protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
51 case ActivityUtils::compareVerbs($verb, array(ActivityVerb::DELETE)):
52 // do whatever preparation is necessary to delete a verb
56 throw new ServerException('ActivityVerb POST not handled by plugin that was supposed to do it.');
60 public function deleteRelated(Notice $notice)
65 public function onDeleteNoticeAsProfile(Notice $stored, Profile $actor, &$result) {
66 // By adding a new 'delete' verb we will eventually trigger $this->saveObjectFromActivity
67 if (false === Deleted_notice::addNew($stored, $actor)) {
68 // false is returned if we did not have an error, but did not create the object
69 // (i.e. the author is currently being deleted)
73 // We return false (to stop the event) if the deleted_notice entry was
74 // added, which means we have run $this->saveObjectFromActivity which
75 // in turn has called the delete function of the notice.
80 * This is run when a 'delete' verb activity comes in.
82 * @return boolean hook flag
84 protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
86 // Let's see if this has been deleted already.
87 $deleted = Deleted_notice::getKV('uri', $act->id);
88 if ($deleted instanceof Deleted_notice) {
92 common_debug('DELETING notice: ' . $act->objects[0]->id);
93 $target = Notice::getByUri($act->objects[0]->id);
95 $deleted = new Deleted_notice();
97 $deleted->id = $target->getID();
98 $deleted->profile_id = $target->getProfile()->getID();
99 $deleted->uri = Deleted_notice::newUri($target->getProfile(), $target);
100 $deleted->act_uri = $target->getUri();
101 $deleted->act_created = $target->created;
102 $deleted->created = common_sql_now();
104 common_debug('DELETING notice, storing Deleted_notice entry');
107 common_debug('DELETING notice, actually deleting now!');
113 public function activityObjectFromNotice(Notice $notice)
115 $object = Deleted_notice::fromStored($notice);
116 return $object->asActivityObject();
119 protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
121 if (!$scoped instanceof Profile || !($scoped->sameAs($target->getProfile()) || $scoped->hasRight(Right::DELETEOTHERSNOTICE))) {
122 throw new AuthorizationException(_('You are not allowed to delete other user\'s notices'));
124 return DeletenoticeForm($action, array('notice'=>$target));