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);
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