From 206364cd1c25e577544159a9822c9395a516d38a Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 3 Mar 2014 19:59:25 +0100 Subject: remove invalid shares with one SQL statement --- apps/files_sharing/lib/updater.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 950575ec26b..e3a7679292d 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -143,18 +143,11 @@ class Shared_Updater { */ static public function fixBrokenSharesOnAppUpdate() { // delete all shares where the original file no longer exists - $findShares = \OC_DB::prepare('SELECT `*PREFIX*share`.`id` ' . - 'FROM `*PREFIX*share` LEFT JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` ' . - 'WHERE `*PREFIX*filecache`.`fileid` IS NULL AND `*PREFIX*share`.`item_type` IN (\'file\', \'folder\')'); - $sharesFound = $findShares->execute(array())->fetchAll(); - - // delete those shares from the oc_share table - if (is_array($sharesFound) && !empty($sharesFound)) { - $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` = ? '); - foreach ($sharesFound as $share) { - $result = $removeShares->execute(array($share['id'])); - } - } + $findAndRemoveShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` ' . + 'WHERE `file_source` NOT IN ( ' . + 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `item_type` IN (\'file\', \'folder\'))' + ); + $findAndRemoveShares->execute(array()); } } -- cgit v1.2.3