Also delete category/object relations when deleting a category.

This commit is contained in:
Thomas Tanghus 2012-10-24 22:39:34 +02:00
parent 675a56c5ed
commit 2fc495a91a
1 changed files with 15 additions and 1 deletions

View File

@ -632,9 +632,11 @@ class OC_VCategories {
OC_Log::write('core', __METHOD__ . ', before: '
. print_r(self::$categories, true), OC_Log::DEBUG);
foreach($names as $name) {
$id = null;
OC_Log::write('core', __METHOD__.', '.$name, OC_Log::DEBUG);
if($this->hasCategory($name)) {
unset(self::$categories[$this->array_searchi($name, self::$categories)]);
$id = $this->array_searchi($name, self::$categories);
unset(self::$categories[$id]);
}
try {
$stmt = OCP\DB::prepare('DELETE FROM `' . self::CATEGORY_TABLE . '` WHERE '
@ -644,6 +646,18 @@ class OC_VCategories {
OCP\Util::writeLog('core', __METHOD__ . ', exception: '
. $e->getMessage(), OCP\Util::ERROR);
}
if(!is_null($id) && $id !== false) {
try {
$sql = 'DELETE FROM `' . self::RELATION_TABLE . '` '
. 'WHERE `categoryid` = ?';
$stmt = OCP\DB::prepare($sql);
$stmt->execute(array($id));
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
OCP\Util::ERROR);
return false;
}
}
}
OC_Log::write('core', __METHOD__.', after: '
. print_r(self::$categories, true), OC_Log::DEBUG);