From d838a3b33ff02ec5210695be593626f29dbc65a1 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 29 Mar 2013 05:51:41 +0100 Subject: [PATCH 1/4] Allow purging multiple objects from category index table. --- lib/vcategories.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/vcategories.php b/lib/vcategories.php index 2f990c5d2d..a52c15f067 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -536,17 +536,22 @@ class OC_VCategories { /** * @brief Delete category/object relations from the db - * @param int $id The id of the object + * @param array $ids The ids of the objects * @param string $type The type of object (event/contact/task/journal). * Defaults to the type set in the instance * @returns boolean Returns false on error. */ - public function purgeObject($id, $type = null) { + public function purgeObjects($ids, $type = null) { $type = is_null($type) ? $this->type : $type; + $updates = array(); try { - $stmt = OCP\DB::prepare('DELETE FROM `' . self::RELATION_TABLE . '` ' - . 'WHERE `objid` = ? AND `type`= ?'); - $result = $stmt->execute(array($id, $type)); + $query = 'DELETE FROM `' . self::RELATION_TABLE . '` '; + $query .= 'WHERE `objid` IN (' . str_repeat('?,', count($ids)-1) . '?) '; + $updates = $ids; + $query .= 'AND `type`= ?'; + $updates[] = $type; + $stmt = OCP\DB::prepare($query); + $result = $stmt->execute($updates); if (OC_DB::isError($result)) { OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR); return false; From a56abd3f9bdb1107bddb6cd8982a2be8727a938e Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 29 Mar 2013 14:54:08 +0100 Subject: [PATCH 2/4] Typehint and check $ids parameter. --- lib/vcategories.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/vcategories.php b/lib/vcategories.php index a52c15f067..372706b185 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -541,9 +541,13 @@ class OC_VCategories { * Defaults to the type set in the instance * @returns boolean Returns false on error. */ - public function purgeObjects($ids, $type = null) { + public function purgeObjects(array $ids, $type = null) { $type = is_null($type) ? $this->type : $type; - $updates = array(); + if(count($ids) === 0) { + // job done ;) + return true; + } + $updates = $ids(); try { $query = 'DELETE FROM `' . self::RELATION_TABLE . '` '; $query .= 'WHERE `objid` IN (' . str_repeat('?,', count($ids)-1) . '?) '; @@ -557,7 +561,7 @@ class OC_VCategories { return false; } } catch(Exception $e) { - OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), + OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(), OCP\Util::ERROR); return false; } From 73dd54c9624a713d8180741c4558b2d56972a5ac Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sat, 30 Mar 2013 16:35:13 +0100 Subject: [PATCH 3/4] Don't try to call a an array :-P --- lib/vcategories.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vcategories.php b/lib/vcategories.php index 372706b185..a1ba0f2482 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -547,7 +547,7 @@ class OC_VCategories { // job done ;) return true; } - $updates = $ids(); + $updates = $ids; try { $query = 'DELETE FROM `' . self::RELATION_TABLE . '` '; $query .= 'WHERE `objid` IN (' . str_repeat('?,', count($ids)-1) . '?) '; From d048ff719db224e145783c77d2f3b50c03eb30a0 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Thu, 4 Apr 2013 14:10:34 +0200 Subject: [PATCH 4/4] Remove redundant line --- lib/vcategories.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/vcategories.php b/lib/vcategories.php index a1ba0f2482..5975e688b7 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -551,7 +551,6 @@ class OC_VCategories { try { $query = 'DELETE FROM `' . self::RELATION_TABLE . '` '; $query .= 'WHERE `objid` IN (' . str_repeat('?,', count($ids)-1) . '?) '; - $updates = $ids; $query .= 'AND `type`= ?'; $updates[] = $type; $stmt = OCP\DB::prepare($query);