X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FActivityModeration%2FActivityModerationPlugin.php;h=ba53a13a8af3437e06d6af5f78e77665024446fa;hb=93524c4be384a9d75cdb4cd3413894bb4e39de6b;hp=4ddcf27c25e34e641bbadfd82e1d533c9b4f0cfd;hpb=3255e2e1b81ce6d8d867e924eeacff2c9e53d706;p=quix0rs-gnu-social.git diff --git a/plugins/ActivityModeration/ActivityModerationPlugin.php b/plugins/ActivityModeration/ActivityModerationPlugin.php index 4ddcf27c25..ba53a13a8a 100644 --- a/plugins/ActivityModeration/ActivityModerationPlugin.php +++ b/plugins/ActivityModeration/ActivityModerationPlugin.php @@ -34,6 +34,30 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin return true; } + public function onGetNoticeSqlTimestamp($id, &$timestamp) + { + try { + $deleted = Deleted_notice::getByID($id); + $timestamp = $deleted->act_created; + } catch (NoResultException $e) { + return true; + } + // we're done for the event, so return false to stop it + return false; + } + + public function onIsNoticeDeleted($id, &$deleted) + { + try { + $found = Deleted_notice::getByID($id); + $deleted = ($found instanceof Deleted_notice); + } catch (NoResultException $e) { + $deleted = false; + } + // return true (continue event) if $deleted is false, return false (stop event) if deleted notice was found + return !$deleted; + } + protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped) { // FIXME: switch based on action type @@ -50,7 +74,7 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin switch (true) { case ActivityUtils::compareVerbs($verb, array(ActivityVerb::DELETE)): // do whatever preparation is necessary to delete a verb - $target->delete(); + $target->deleteAs($scoped); break; default: throw new ServerException('ActivityVerb POST not handled by plugin that was supposed to do it.'); @@ -63,7 +87,8 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin } public function onDeleteNoticeAsProfile(Notice $stored, Profile $actor, &$result) { - // By adding a new 'delete' verb we will eventually trigger $this->saveObjectFromActivity + // By adding a new object with the 'delete' verb we will trigger + // $this->saveObjectFromActivity that will do the actual ->delete() 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) @@ -71,8 +96,8 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin } // 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. + // added, which means we have already run $this->saveObjectFromActivity + // which in turn has called the delete function of the notice. return false; } @@ -144,28 +169,22 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin foreach($props as $prop) { $stored->$prop = $target->$prop; } - //$stored->content = $stored->content ?: _('Notice deleted.'); - //$stored->rendered = $stored->rendered ?: $stored->rendered; - common_debug('DELETENOTICE: Replacement notice has been prepared: '.var_export($stored, true)); // Let's see if this has been deleted already. - $deleted = Deleted_notice::getKV('uri', $stored->getUri()); - if ($deleted instanceof Deleted_notice) { + try { + $deleted = Deleted_notice::getByKeys( ['uri' => $stored->getUri()] ); return $deleted; - } - - $deleted = new Deleted_notice(); + } catch (NoResultException $e) { + $deleted = new Deleted_notice(); - $deleted->id = $target->getID(); - $deleted->profile_id = $actor->getID(); - $deleted->uri = $stored->getUri(); - $deleted->act_uri = $stored->getUri(); - $deleted->act_created = $stored->created; - $deleted->created = common_sql_now(); + $deleted->id = $target->getID(); + $deleted->profile_id = $actor->getID(); + $deleted->uri = $stored->getUri(); + $deleted->act_created = $stored->created; + $deleted->created = common_sql_now(); - $result = $deleted->insert(); - if ($result === false) { - throw new ServerException('Could not insert Deleted_notice entry into database!'); + // throws exception on error + $result = $deleted->insert(); } // Now we delete the original notice, leaving the id and uri free.