From 461302244ee0aed22c355f1b1201d79ec899b2ad Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 27 Mar 2015 17:33:26 +0100 Subject: [PATCH 1/3] Keep shares when deleting shared folders The share entries will be linked with the fileid while they are kept in the trashbin. In the future a background just will scrape orphaned shares and delete them. --- apps/files_sharing/lib/helper.php | 1 - apps/files_sharing/lib/updater.php | 32 ------------------------------ 2 files changed, 33 deletions(-) diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index 3f1de7233a..5b5525e244 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -33,7 +33,6 @@ class Helper { \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OCA\Files_Sharing\External\Manager', 'setup'); \OCP\Util::connectHook('OC_Filesystem', 'post_write', '\OC\Files\Cache\Shared_Updater', 'writeHook'); - \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Shared_Updater', 'postDeleteHook'); \OCP\Util::connectHook('OC_Filesystem', 'delete', '\OC\Files\Cache\Shared_Updater', 'deleteHook'); \OCP\Util::connectHook('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Shared_Updater', 'renameHook'); \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren'); diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index d748d5555f..affa28720b 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -81,25 +81,6 @@ class Shared_Updater { } } - /** - * remove all shares for a given file if the file was deleted - * - * @param string $path - */ - private static function removeShare($path) { - $fileSource = self::$toRemove[$path]; - - if (!\OC\Files\Filesystem::file_exists($path)) { - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source`=?'); - try { - \OC_DB::executeAudited($query, array($fileSource)); - } catch (\Exception $e) { - \OCP\Util::writeLog('files_sharing', "can't remove share: " . $e->getMessage(), \OCP\Util::WARN); - } - } - unset(self::$toRemove[$path]); - } - /** * @param array $params */ @@ -122,19 +103,6 @@ class Shared_Updater { static public function deleteHook($params) { $path = $params['path']; self::correctFolders($path); - - $fileInfo = \OC\Files\Filesystem::getFileInfo($path); - - // mark file as deleted so that we can clean up the share table if - // the file was deleted successfully - self::$toRemove[$path] = $fileInfo['fileid']; - } - - /** - * @param array $params - */ - static public function postDeleteHook($params) { - self::removeShare($params['path']); } /** From 08a9d1d2dcb9553edd394f6f4df1ace8a407156a Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 9 Apr 2015 12:34:19 +0200 Subject: [PATCH 2/3] Remove unused $toRemove --- apps/files_sharing/lib/updater.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index affa28720b..322c031f2f 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -27,9 +27,6 @@ namespace OC\Files\Cache; class Shared_Updater { - // shares which can be removed from oc_share after the delete operation was successful - static private $toRemove = array(); - /** * walk up the users file tree and update the etags * @param string $user From 5803a1f5f7a22feee84cef552bfff3e6b40e6859 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 9 Apr 2015 15:02:24 +0200 Subject: [PATCH 3/3] Remove trashbin storage wrapper when disabling it for tests --- apps/files_sharing/tests/deleteorphanedsharesjobtest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/files_sharing/tests/deleteorphanedsharesjobtest.php b/apps/files_sharing/tests/deleteorphanedsharesjobtest.php index e1c6a6f6ad..20f3bcd5eb 100644 --- a/apps/files_sharing/tests/deleteorphanedsharesjobtest.php +++ b/apps/files_sharing/tests/deleteorphanedsharesjobtest.php @@ -55,6 +55,9 @@ class DeleteOrphanedSharesJobTest extends \Test\TestCase { $appManager = \OC::$server->getAppManager(); self::$trashBinStatus = $appManager->isEnabledForUser('files_trashbin'); $appManager->disableApp('files_trashbin'); + + // just in case... + \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin'); } public static function tearDownAfterClass() {