]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/ActivityModeration/ActivityModerationPlugin.php
fix a link of doc/twitterapi
[quix0rs-gnu-social.git] / plugins / ActivityModeration / ActivityModerationPlugin.php
index 4ddcf27c25e34e641bbadfd82e1d533c9b4f0cfd..208a05449df1eb4d3797c3b8413291783b7e23b5 100644 (file)
@@ -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
@@ -144,28 +168,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.