From 2fc495a91a1c38e0fbf53f0c78d157698e7ff024 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Wed, 24 Oct 2012 22:39:34 +0200 Subject: Also delete category/object relations when deleting a category. --- lib/vcategories.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/vcategories.php') diff --git a/lib/vcategories.php b/lib/vcategories.php index ec243297a43..116c1d1cd95 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -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); -- cgit v1.2.3