summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMorris Jobke <morris.jobke@gmail.com>2014-03-03 19:59:25 +0100
committerMorris Jobke <morris.jobke@gmail.com>2014-03-13 13:09:32 +0100
commit206364cd1c25e577544159a9822c9395a516d38a (patch)
tree9eb6c73038784f48ba26f79530491dd41eb62af6 /apps
parent02be15ce2fd78a7fd2b3b14fed6ac470666c560d (diff)
downloadnextcloud-server-206364cd1c25e577544159a9822c9395a516d38a.tar.gz
nextcloud-server-206364cd1c25e577544159a9822c9395a516d38a.zip
remove invalid shares with one SQL statement
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/lib/updater.php17
1 files 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());
}
}