]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use IBootstrap for the files_trashbin app 21954/head
authorMorris Jobke <hey@morrisjobke.de>
Wed, 22 Jul 2020 20:11:01 +0000 (22:11 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Thu, 23 Jul 2020 20:03:14 +0000 (22:03 +0200)
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
apps/files_sharing/tests/SharedStorageTest.php
apps/files_sharing/tests/UpdaterTest.php
apps/files_trashbin/appinfo/app.php [deleted file]
apps/files_trashbin/lib/AppInfo/Application.php
apps/files_trashbin/lib/Trashbin.php
apps/files_trashbin/tests/StorageTest.php
apps/files_trashbin/tests/TrashbinTest.php

index fb8207a3c1d0fa468d5fde9e204d72df6c6a29e5..e3e57cc73a43cf9c7e63270f873de1f2e6167b55 100644 (file)
@@ -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';
index 30efbac533dd3c26ef0c5cc70d26f494e69affce..344c08bea48bdc1ab9684c411fd778a51fb5af38 100644 (file)
@@ -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 (file)
index 83f8def..0000000
+++ /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',
-       ];
-});
index d9f52d21a612213d0a2904d7f0e4aaf6d68d583d..ed78709a5d65bcea2dd28db9b1d3811b42cd8163 100644 (file)
 
 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);
index f73cc1f4aa6affe1718fdfd8ba5a1c6c213b5515..46bdc08ce3acd9b087bf8c0d605dc08ce0ca3974 100644 (file)
@@ -1008,20 +1008,6 @@ class Trashbin {
                return isset($fileInfo['size']) ? $fileInfo['size'] : 0;
        }
 
-       /**
-        * 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
         *
index 2efdf1b8958d371f1967e6e745526f01e55ee24e..36628cb08b9e6f0bcb1c0ff971d9daf8ac6ff883 100644 (file)
@@ -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);
index 7dfa93bb0445e83f3d76bed2634ade4fb106be0f..96a76e1e2fe8484d2c87bfdf16d8c869dbf391b1 100644 (file)
@@ -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);