diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-07-22 22:11:01 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-07-23 22:03:14 +0200 |
commit | e84504c4d6a079d55d2f78ad21b1ad20d53035bb (patch) | |
tree | b1ac43a8573169257ee0c8d56d1dfd406cf68f59 | |
parent | c842678f0a1fb65981a03302895192ddc58479c9 (diff) | |
download | nextcloud-server-e84504c4d6a079d55d2f78ad21b1ad20d53035bb.tar.gz nextcloud-server-e84504c4d6a079d55d2f78ad21b1ad20d53035bb.zip |
Use IBootstrap for the files_trashbin app
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
-rw-r--r-- | apps/files_sharing/tests/SharedStorageTest.php | 6 | ||||
-rw-r--r-- | apps/files_sharing/tests/UpdaterTest.php | 7 | ||||
-rw-r--r-- | apps/files_trashbin/appinfo/app.php | 41 | ||||
-rw-r--r-- | apps/files_trashbin/lib/AppInfo/Application.php | 74 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Trashbin.php | 14 | ||||
-rw-r--r-- | apps/files_trashbin/tests/StorageTest.php | 6 | ||||
-rw-r--r-- | apps/files_trashbin/tests/TrashbinTest.php | 8 |
7 files changed, 59 insertions, 97 deletions
diff --git a/apps/files_sharing/tests/SharedStorageTest.php b/apps/files_sharing/tests/SharedStorageTest.php index fb8207a3c1d..e3e57cc73a4 100644 --- a/apps/files_sharing/tests/SharedStorageTest.php +++ b/apps/files_sharing/tests/SharedStorageTest.php @@ -31,6 +31,8 @@ namespace OCA\Files_Sharing\Tests; use OC\Files\View; use OCA\Files_Sharing\SharedStorage; +use OCA\Files_Trashbin\AppInfo\Application; +use OCP\AppFramework\Bootstrap\IBootContext; use OCP\Files\NotFoundException; use OCP\Share\IShare; @@ -42,7 +44,9 @@ use OCP\Share\IShare; class SharedStorageTest extends TestCase { protected function setUp(): void { parent::setUp(); - \OCA\Files_Trashbin\Trashbin::registerHooks(); + // register trashbin hooks + $trashbinApp = new Application(); + $trashbinApp->boot($this->createMock(IBootContext::class)); $this->folder = '/folder_share_storage_test'; $this->filename = '/share-api-storage.txt'; diff --git a/apps/files_sharing/tests/UpdaterTest.php b/apps/files_sharing/tests/UpdaterTest.php index 30efbac533d..344c08bea48 100644 --- a/apps/files_sharing/tests/UpdaterTest.php +++ b/apps/files_sharing/tests/UpdaterTest.php @@ -31,6 +31,8 @@ namespace OCA\Files_Sharing\Tests; +use OCA\Files_Trashbin\AppInfo\Application; +use OCP\AppFramework\Bootstrap\IBootContext; use OCP\Share\IShare; /** @@ -77,8 +79,9 @@ class UpdaterTest extends TestCase { $status = \OC::$server->getAppManager()->isEnabledForUser('files_trashbin'); (new \OC_App())->enable('files_trashbin'); - - \OCA\Files_Trashbin\Trashbin::registerHooks(); + // register trashbin hooks + $trashbinApp = new Application(); + $trashbinApp->boot($this->createMock(IBootContext::class)); $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder); $this->assertTrue($fileinfo instanceof \OC\Files\FileInfo); diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php deleted file mode 100644 index 83f8defccbd..00000000000 --- a/apps/files_trashbin/appinfo/app.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christopher Schäpers <kondou@ts.unde.re> - * @author Florin Peter <github@florin-peter.de> - * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Victor Dubiniuk <dubiniuk@owncloud.com> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -// register hooks -\OCA\Files_Trashbin\Trashbin::registerHooks(); - -\OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_trashbin'); - return [ - 'id' => 'trashbin', - 'appname' => 'files_trashbin', - 'script' => 'list.php', - 'order' => 50, - 'name' => $l->t('Deleted files'), - 'classes' => 'pinned', - ]; -}); diff --git a/apps/files_trashbin/lib/AppInfo/Application.php b/apps/files_trashbin/lib/AppInfo/Application.php index d9f52d21a61..ed78709a5d6 100644 --- a/apps/files_trashbin/lib/AppInfo/Application.php +++ b/apps/files_trashbin/lib/AppInfo/Application.php @@ -27,57 +27,59 @@ namespace OCA\Files_Trashbin\AppInfo; -use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\Connector\Sabre\Principal; use OCA\Files_Trashbin\Capabilities; use OCA\Files_Trashbin\Expiration; use OCA\Files_Trashbin\Trash\ITrashManager; use OCA\Files_Trashbin\Trash\TrashManager; +use OCP\App\IAppManager; use OCP\AppFramework\App; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\ILogger; +use OCP\IServerContainer; -class Application extends App { +class Application extends App implements IBootstrap { public function __construct(array $urlParams = []) { parent::__construct('files_trashbin', $urlParams); + } - $container = $this->getContainer(); - /* - * Register capabilities - */ - $container->registerCapability(Capabilities::class); + public function register(IRegistrationContext $context): void { + $context->registerCapability(Capabilities::class); - /* - * Register expiration - */ - $container->registerAlias('Expiration', Expiration::class); + $context->registerServiceAlias('Expiration', Expiration::class); + $context->registerServiceAlias(ITrashManager::class, TrashManager::class); + /** Register $principalBackend for the DAV collection */ + $context->registerServiceAlias('principalBackend', Principal::class); + } - /* - * Register $principalBackend for the DAV collection - */ - $container->registerService('principalBackend', function () { - return new Principal( - \OC::$server->getUserManager(), - \OC::$server->getGroupManager(), - \OC::$server->getShareManager(), - \OC::$server->getUserSession(), - \OC::$server->getAppManager(), - \OC::$server->query(ProxyMapper::class), - \OC::$server->getConfig() - ); - }); + public function boot(IBootContext $context): void { + $context->injectFn([$this, 'registerTrashBackends']); - $container->registerService(ITrashManager::class, function () { - return new TrashManager(); - }); + // create storage wrapper on setup + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', 'OCA\Files_Trashbin\Storage', 'setupStorage'); + //Listen to delete user signal + \OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook'); + //Listen to post write hook + \OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook'); + // pre and post-rename, disable trash logic for the copy+unlink case + \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook'); - $this->registerTrashBackends(); + \OCA\Files\App::getNavigationManager()->add(function () { + $l = \OC::$server->getL10N('files_trashbin'); + return [ + 'id' => 'trashbin', + 'appname' => 'files_trashbin', + 'script' => 'list.php', + 'order' => 50, + 'name' => $l->t('Deleted files'), + 'classes' => 'pinned', + ]; + }); } - public function registerTrashBackends() { - $server = $this->getContainer()->getServer(); - $logger = $server->getLogger(); - $appManager = $server->getAppManager(); - /** @var ITrashManager $trashManager */ - $trashManager = $this->getContainer()->getServer()->query(ITrashManager::class); + public function registerTrashBackends(IServerContainer $serverContainer, ILogger $logger, IAppManager $appManager, ITrashManager $trashManager) { foreach ($appManager->getInstalledApps() as $app) { $appInfo = $appManager->getAppInfo($app); if (isset($appInfo['trash'])) { @@ -87,7 +89,7 @@ class Application extends App { $for = $backend['@attributes']['for']; try { - $backendObject = $server->query($class); + $backendObject = $serverContainer->query($class); $trashManager->registerBackend($for, $backendObject); } catch (\Exception $e) { $logger->logException($e); diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index f73cc1f4aa6..46bdc08ce3a 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -1009,20 +1009,6 @@ class Trashbin { } /** - * register hooks - */ - public static function registerHooks() { - // create storage wrapper on setup - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', 'OCA\Files_Trashbin\Storage', 'setupStorage'); - //Listen to delete user signal - \OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook'); - //Listen to post write hook - \OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook'); - // pre and post-rename, disable trash logic for the copy+unlink case - \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook'); - } - - /** * check if trash bin is empty for a given user * * @param string $user diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index 2efdf1b8958..36628cb08b9 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -34,9 +34,11 @@ namespace OCA\Files_Trashbin\Tests; use OC\Files\Filesystem; use OC\Files\Storage\Temporary; +use OCA\Files_Trashbin\AppInfo\Application; use OCA\Files_Trashbin\Events\MoveToTrashEvent; use OCA\Files_Trashbin\Storage; use OCA\Files_Trashbin\Trash\ITrashManager; +use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\Cache\ICache; use OCP\Files\Folder; @@ -75,7 +77,9 @@ class StorageTest extends \Test\TestCase { parent::setUp(); \OC_Hook::clear(); - \OCA\Files_Trashbin\Trashbin::registerHooks(); + // register trashbin hooks + $trashbinApp = new Application(); + $trashbinApp->boot($this->createMock(IBootContext::class)); $this->user = $this->getUniqueId('user'); \OC::$server->getUserManager()->createUser($this->user, $this->user); diff --git a/apps/files_trashbin/tests/TrashbinTest.php b/apps/files_trashbin/tests/TrashbinTest.php index 7dfa93bb044..96a76e1e2fe 100644 --- a/apps/files_trashbin/tests/TrashbinTest.php +++ b/apps/files_trashbin/tests/TrashbinTest.php @@ -30,6 +30,9 @@ */ use OCA\Files_Sharing\AppInfo\Application; +use OCA\Files_Trashbin\AppInfo\Application as TrashbinApplication; +use OC\AppFramework\Bootstrap\BootContext; +use OC\AppFramework\DependencyInjection\DIContainer; use OCP\Share\IShare; /** @@ -83,8 +86,9 @@ class TrashbinTest extends \Test\TestCase { $expiration = \OC::$server->query(\OCA\Files_Trashbin\Expiration::class); $expiration->setRetentionObligation('auto, 2'); - // register hooks - \OCA\Files_Trashbin\Trashbin::registerHooks(); + // register trashbin hooks + $trashbinApp = new TrashbinApplication(); + $trashbinApp->boot(new BootContext(new DIContainer('', [], \OC::$server))); // create test user self::loginHelper(self::TEST_TRASHBIN_USER2, true); |