]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Exception throwing and proper db retrieval
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 31 Dec 2015 11:41:30 +0000 (12:41 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 31 Dec 2015 11:42:33 +0000 (12:42 +0100)
ActivityModeration plugin and its Deleted_notice class.

plugins/ActivityModeration/ActivityModerationPlugin.php
plugins/ActivityModeration/classes/Deleted_notice.php

index 8a4f694df0af2c0e636f2f4972ce92c47e7135c6..22384ba06b90f7ee3d6ca51cced1f372d9f63ef2 100644 (file)
@@ -149,22 +149,20 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin
         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_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.
index f834f88bb7dd7e3f337d1c8a62affdf679410357..76674d9bec63d31dc60dd1f77c9ba10477eae9f0 100644 (file)
@@ -96,7 +96,7 @@ class Deleted_notice extends Managed_DataObject
     static public function fromStored(Notice $stored)
     {
         $class = get_called_class();
-        return self::getByPK(array('uri' => $stored->getUri()));
+        return self::getByKeys( ['uri' => $stored->getUri()] );
     }
 
     // The one who deleted the notice, not the notice's author
@@ -206,4 +206,14 @@ class Deleted_notice extends Managed_DataObject
         print "Resuming core schema upgrade...";
     }
 
+    function insert()
+    {
+        $result = parent::insert();
+
+        if ($result === false) {
+            common_log_db_error($this, 'INSERT', __FILE__);
+            // TRANS: Server exception thrown when a stored object entry cannot be saved.
+            throw new ServerException('Could not save Deleted_notice');
+        }
+    }
 }