]> source.dussan.org Git - nextcloud-server.git/commitdiff
clean up oc_share table from files which are no longer exists
authorBjoern Schiessle <schiessle@owncloud.com>
Mon, 7 Oct 2013 08:59:09 +0000 (10:59 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Mon, 7 Oct 2013 09:09:00 +0000 (11:09 +0200)
apps/files_sharing/appinfo/update.php
apps/files_sharing/appinfo/version

index 48e41e9304889fe1c1356ded114ffb6b08f299c7..bc33dd40437ab3bbd6dd9a61193076045f4593e7 100644 (file)
@@ -68,11 +68,21 @@ if (version_compare($installedVersion, '0.3', '<')) {
 //     $query = OCP\DB::prepare('DROP TABLE `*PREFIX*sharing`');
 //     $query->execute();
 }
-if (version_compare($installedVersion, '0.3.3', '<')) {
-       OC_User::useBackend(new OC_User_Database());
-       OC_App::loadApps(array('authentication'));
-       $users = OC_User::getUsers();
-       foreach ($users as $user) {
-//             OC_FileCache::delete('Shared', '/'.$user.'/files/');
+
+// clean up oc_share table from files which are no longer exists
+if (version_compare($installedVersion, '0.3.4', '<')) {
+
+       // get all shares where the original file no longer exists
+       $findShares = \OC_DB::prepare('SELECT `file_source` FROM `*PREFIX*share` LEFT JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE `*PREFIX*filecache`.`fileid` IS NULL');
+       $sharesFound = $findShares->execute(array())->fetchAll();
+
+       // delete those shares from the oc_share table
+       if (is_array($sharesFound) && !empty($sharesFound)) {
+               $delArray = array();
+               foreach ($sharesFound as $share) {
+                       $delArray[] = $share['file_source'];
+               }
+               $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source` IN (?)');
+               $result = $removeShares->execute(array(implode(',', $delArray)));
        }
 }
index 87a0871112f9244bbad0fc8331376317417760b9..448a0fa11cdb5dc89bd34011f071df2a56ee44d9 100644 (file)
@@ -1 +1 @@
-0.3.3
\ No newline at end of file
+0.3.4
\ No newline at end of file