diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2013-02-26 15:01:42 +0100 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2013-02-26 15:01:42 +0100 |
commit | ea841e5e15959b224b85c748f1d82abd54bf2e95 (patch) | |
tree | c95da21a1d30068957b957e46689de8464849d55 /lib/vcategories.php | |
parent | 69eb69be0e8867eae4b9b5e4e724db592d3d9cf9 (diff) | |
download | nextcloud-server-ea841e5e15959b224b85c748f1d82abd54bf2e95.tar.gz nextcloud-server-ea841e5e15959b224b85c748f1d82abd54bf2e95.zip |
Catch exceptions on malformed categories.
Diffstat (limited to 'lib/vcategories.php')
-rw-r--r-- | lib/vcategories.php | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/lib/vcategories.php b/lib/vcategories.php index 8de497a6191..f94a0a55d3b 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -306,12 +306,18 @@ class OC_VCategories { OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', OCP\Util::DEBUG); return false; } - OCP\DB::insertIfNotExist(self::CATEGORY_TABLE, - array( - 'uid' => $this->user, - 'type' => $this->type, - 'category' => $name, - )); + try { + OCP\DB::insertIfNotExist(self::CATEGORY_TABLE, + array( + 'uid' => $this->user, + 'type' => $this->type, + 'category' => $name, + )); + } catch(Exception $e) { + OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), + OCP\Util::ERROR); + return false; + } $id = OCP\DB::insertid(self::CATEGORY_TABLE); OCP\Util::writeLog('core', __METHOD__.', id: ' . $id, OCP\Util::DEBUG); $this->categories[$id] = $name; @@ -436,12 +442,17 @@ class OC_VCategories { private function save() { if(is_array($this->categories)) { foreach($this->categories as $category) { - OCP\DB::insertIfNotExist(self::CATEGORY_TABLE, - array( - 'uid' => $this->user, - 'type' => $this->type, - 'category' => $category, - )); + try { + OCP\DB::insertIfNotExist(self::CATEGORY_TABLE, + array( + 'uid' => $this->user, + 'type' => $this->type, + 'category' => $category, + )); + } catch(Exception $e) { + OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), + OCP\Util::ERROR); + } } // reload categories to get the proper ids. $this->loadCategories(); @@ -454,12 +465,17 @@ class OC_VCategories { $catid = $this->array_searchi($relation['category'], $categories); OC_Log::write('core', __METHOD__ . 'catid, ' . $relation['category'] . ' ' . $catid, OC_Log::DEBUG); if($catid) { - OCP\DB::insertIfNotExist(self::RELATION_TABLE, - array( - 'objid' => $relation['objid'], - 'categoryid' => $catid, - 'type' => $this->type, - )); + try { + OCP\DB::insertIfNotExist(self::RELATION_TABLE, + array( + 'objid' => $relation['objid'], + 'categoryid' => $catid, + 'type' => $this->type, + )); + } catch(Exception $e) { + OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), + OCP\Util::ERROR); + } } } self::$relations = array(); // reset |