diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2013-10-07 10:59:09 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2013-10-07 10:59:09 +0200 |
commit | 0346167bb2ab3c26fed26415470d52c21110d70e (patch) | |
tree | 2168b3b852fd4c904db8468dcfaa4830b217873b /apps/files_sharing/appinfo/update.php | |
parent | 401740166b6cea7a18ffb86c27c220a7606f14a1 (diff) | |
download | nextcloud-server-0346167bb2ab3c26fed26415470d52c21110d70e.tar.gz nextcloud-server-0346167bb2ab3c26fed26415470d52c21110d70e.zip |
clean up oc_share table from files which are no longer exists
Diffstat (limited to 'apps/files_sharing/appinfo/update.php')
-rw-r--r-- | apps/files_sharing/appinfo/update.php | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index 48e41e93048..bc33dd40437 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -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))); } } |