]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added more error checking in add()
authorThomas Tanghus <thomas@tanghus.net>
Mon, 23 Sep 2013 11:27:43 +0000 (13:27 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Mon, 23 Sep 2013 21:39:36 +0000 (23:39 +0200)
lib/tags.php

index 2eaa603c1a3783520de4aa02964533743b10d180..e2e1a83dd9432c82d0def044f30271315b56aeae 100644 (file)
@@ -233,17 +233,25 @@ class Tags implements \OCP\ITags {
                        return false;
                }
                try {
-                       \OCP\DB::insertIfNotExist(self::TAG_TABLE,
+                       $result = \OCP\DB::insertIfNotExist(
+                               self::TAG_TABLE,
                                array(
                                        'uid' => $this->user,
                                        'type' => $this->type,
                                        'category' => $name,
-                               ));
-                       } catch(\Exception $e) {
-                               \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
-                                       \OCP\Util::ERROR);
+                               )
+                       );
+                       if (\OCP\DB::isError($result)) {
+                               \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
                                return false;
+                       } elseif((int)$result === 0) {
+                               \OCP\Util::writeLog('core', __METHOD__.', Tag already exists: ' . $name, \OCP\Util::DEBUG);
                        }
+               } catch(\Exception $e) {
+                       \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
+                               \OCP\Util::ERROR);
+                       return false;
+               }
                $id = \OCP\DB::insertid(self::TAG_TABLE);
                \OCP\Util::writeLog('core', __METHOD__.', id: ' . $id, \OCP\Util::DEBUG);
                $this->tags[$id] = $name;