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)
62 if ($notice->getProfile()->hasRole(Profile_role::DELETED)) {
63 // Don't save a new Deleted_notice entry if the profile is being deleted
67 // For auditing purposes, save a record that the notice was deleted.
68 return Deleted_notice::addNew($notice);
72 * This is run when a 'delete' verb activity comes in.
74 * @return boolean hook flag
76 protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
78 // Let's see if this has been deleted already.
79 $deleted = Deleted_notice::getKV('uri', $act->id);
80 if ($deleted instanceof Deleted_notice) {
84 common_debug('DELETING notice: ' . $act->objects[0]->id);
85 $target = Notice::getByUri($act->objects[0]->id);
87 $deleted = new Deleted_notice();
89 $deleted->id = $target->getID();
90 $deleted->profile_id = $target->getProfile()->getID();
91 $deleted->uri = Deleted_notice::newUri($target->getProfile(), $target);
92 $deleted->act_uri = $target->getUri();
93 $deleted->act_created = $target->created;
94 $deleted->created = common_sql_now();
96 common_debug('DELETING notice, storing Deleted_notice entry');
99 common_debug('DELETING notice, actually deleting now!');
105 public function activityObjectFromNotice(Notice $notice)
107 $object = Deleted_notice::fromStored($notice);
108 return $object->asActivityObject();
111 protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
113 if (!$scoped instanceof Profile || !($scoped->sameAs($target->getProfile()) || $scoped->hasRight(Right::DELETEOTHERSNOTICE))) {
114 throw new AuthorizationException(_('You are not allowed to delete other user\'s notices'));
116 return DeletenoticeForm($action, array('notice'=>$target));