Merge pull request #1920 from owncloud/catch_vcategories_exceptions

Catch exceptions on malformed categories.
This commit is contained in:
Lukas Reschke 2013-02-26 07:34:46 -08:00
commit 81c664697b
1 changed files with 34 additions and 18 deletions

View File

@ -306,12 +306,18 @@ class OC_VCategories {
OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', OCP\Util::DEBUG); OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', OCP\Util::DEBUG);
return false; return false;
} }
try {
OCP\DB::insertIfNotExist(self::CATEGORY_TABLE, OCP\DB::insertIfNotExist(self::CATEGORY_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(),
OCP\Util::ERROR);
return false;
}
$id = OCP\DB::insertid(self::CATEGORY_TABLE); $id = OCP\DB::insertid(self::CATEGORY_TABLE);
OCP\Util::writeLog('core', __METHOD__.', id: ' . $id, OCP\Util::DEBUG); OCP\Util::writeLog('core', __METHOD__.', id: ' . $id, OCP\Util::DEBUG);
$this->categories[$id] = $name; $this->categories[$id] = $name;
@ -436,12 +442,17 @@ class OC_VCategories {
private function save() { private function save() {
if(is_array($this->categories)) { if(is_array($this->categories)) {
foreach($this->categories as $category) { foreach($this->categories as $category) {
try {
OCP\DB::insertIfNotExist(self::CATEGORY_TABLE, OCP\DB::insertIfNotExist(self::CATEGORY_TABLE,
array( array(
'uid' => $this->user, 'uid' => $this->user,
'type' => $this->type, 'type' => $this->type,
'category' => $category, 'category' => $category,
)); ));
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
OCP\Util::ERROR);
}
} }
// reload categories to get the proper ids. // reload categories to get the proper ids.
$this->loadCategories(); $this->loadCategories();
@ -454,12 +465,17 @@ class OC_VCategories {
$catid = $this->array_searchi($relation['category'], $categories); $catid = $this->array_searchi($relation['category'], $categories);
OC_Log::write('core', __METHOD__ . 'catid, ' . $relation['category'] . ' ' . $catid, OC_Log::DEBUG); OC_Log::write('core', __METHOD__ . 'catid, ' . $relation['category'] . ' ' . $catid, OC_Log::DEBUG);
if($catid) { if($catid) {
try {
OCP\DB::insertIfNotExist(self::RELATION_TABLE, OCP\DB::insertIfNotExist(self::RELATION_TABLE,
array( array(
'objid' => $relation['objid'], 'objid' => $relation['objid'],
'categoryid' => $catid, 'categoryid' => $catid,
'type' => $this->type, 'type' => $this->type,
)); ));
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
OCP\Util::ERROR);
}
} }
} }
self::$relations = array(); // reset self::$relations = array(); // reset