summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2013-09-23 13:27:43 +0200
committerThomas Tanghus <thomas@tanghus.net>2013-09-23 23:39:36 +0200
commit8a02afd87ae1e9a8d223f20ca2df35145a16ce74 (patch)
tree44fe23e473fe99c7a4463296f51a2d9812fd8219 /lib
parent8fab9eef28d2146c2c65f7e7f1aa826216915301 (diff)
downloadnextcloud-server-8a02afd87ae1e9a8d223f20ca2df35145a16ce74.tar.gz
nextcloud-server-8a02afd87ae1e9a8d223f20ca2df35145a16ce74.zip
Added more error checking in add()
Diffstat (limited to 'lib')
-rw-r--r--lib/tags.php18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/tags.php b/lib/tags.php
index 2eaa603c1a3..e2e1a83dd94 100644
--- a/lib/tags.php
+++ b/lib/tags.php
@@ -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;