From d838a3b33ff02ec5210695be593626f29dbc65a1 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus <thomas@tanghus.net> Date: Fri, 29 Mar 2013 05:51:41 +0100 Subject: Allow purging multiple objects from category index table. --- lib/vcategories.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/vcategories.php b/lib/vcategories.php index 2f990c5d2d2..a52c15f0670 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; -- cgit v1.2.3 From a56abd3f9bdb1107bddb6cd8982a2be8727a938e Mon Sep 17 00:00:00 2001 From: Thomas Tanghus <thomas@tanghus.net> Date: Fri, 29 Mar 2013 14:54:08 +0100 Subject: Typehint and check $ids parameter. --- lib/vcategories.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/vcategories.php b/lib/vcategories.php index a52c15f0670..372706b185a 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; } -- cgit v1.2.3 From 73dd54c9624a713d8180741c4558b2d56972a5ac Mon Sep 17 00:00:00 2001 From: Thomas Tanghus <thomas@tanghus.net> Date: Sat, 30 Mar 2013 16:35:13 +0100 Subject: Don't try to call a an array :-P --- lib/vcategories.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/vcategories.php b/lib/vcategories.php index 372706b185a..a1ba0f2482a 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) . '?) '; -- cgit v1.2.3 From d048ff719db224e145783c77d2f3b50c03eb30a0 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus <thomas@tanghus.net> Date: Thu, 4 Apr 2013 14:10:34 +0200 Subject: Remove redundant line --- lib/vcategories.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/vcategories.php b/lib/vcategories.php index a1ba0f2482a..5975e688b75 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); -- cgit v1.2.3