Added more error checking in add()

This commit is contained in:
Thomas Tanghus 2013-09-23 13:27:43 +02:00
parent 8fab9eef28
commit 8a02afd87a
1 changed files with 13 additions and 5 deletions

View File

@ -233,17 +233,25 @@ class Tags implements \OCP\ITags {
return false; return false;
} }
try { try {
\OCP\DB::insertIfNotExist(self::TAG_TABLE, $result = \OCP\DB::insertIfNotExist(
self::TAG_TABLE,
array( array(
'uid' => $this->user, 'uid' => $this->user,
'type' => $this->type, 'type' => $this->type,
'category' => $name, 'category' => $name,
)); )
} catch(\Exception $e) { );
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), if (\OCP\DB::isError($result)) {
\OCP\Util::ERROR); \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
return false; 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); $id = \OCP\DB::insertid(self::TAG_TABLE);
\OCP\Util::writeLog('core', __METHOD__.', id: ' . $id, \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', id: ' . $id, \OCP\Util::DEBUG);
$this->tags[$id] = $name; $this->tags[$id] = $name;