]> source.dussan.org Git - nextcloud-server.git/commitdiff
only gather dependencies for trashbin wrapper once
authorRobin Appelman <robin@icewind.nl>
Tue, 15 Aug 2023 14:51:35 +0000 (16:51 +0200)
committerRobin Appelman <robin@icewind.nl>
Fri, 18 Aug 2023 09:14:52 +0000 (11:14 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_trashbin/lib/Storage.php
apps/files_trashbin/tests/StorageTest.php

index 68d0951b6947ca7bc8f2c466651f6c3ede738d1d..31304935c26d8466e1da4d3b4290ee0b5c797fe0 100644 (file)
@@ -40,35 +40,24 @@ use OCP\Files\Node;
 use OCP\Files\Storage\IStorage;
 use OCP\ILogger;
 use OCP\IUserManager;
+use Psr\Log\LoggerInterface;
 
 class Storage extends Wrapper {
-       /** @var IMountPoint */
-       private $mountPoint;
-
-       /** @var  IUserManager */
-       private $userManager;
-
-       /** @var ILogger */
-       private $logger;
-
-       /** @var IEventDispatcher */
-       private $eventDispatcher;
-
-       /** @var IRootFolder */
-       private $rootFolder;
-
-       /** @var ITrashManager */
-       private $trashManager;
-
-       private $trashEnabled = true;
+       private string $mountPoint;
+       private  IUserManager$userManager;
+       private LoggerInterface $logger;
+       private IEventDispatcher $eventDispatcher;
+       private IRootFolder $rootFolder;
+       private ITrashManager $trashManager;
+       private bool $trashEnabled = true;
 
        /**
         * Storage constructor.
         *
         * @param array $parameters
-        * @param ITrashManager $trashManager
+        * @param ITrashManager|null $trashManager
         * @param IUserManager|null $userManager
-        * @param ILogger|null $logger
+        * @param LoggerInterface|null $logger
         * @param IEventDispatcher|null $eventDispatcher
         * @param IRootFolder|null $rootFolder
         */
@@ -76,7 +65,7 @@ class Storage extends Wrapper {
                $parameters,
                ITrashManager $trashManager = null,
                IUserManager $userManager = null,
-               ILogger $logger = null,
+               LoggerInterface $logger = null,
                IEventDispatcher $eventDispatcher = null,
                IRootFolder $rootFolder = null
        ) {
@@ -209,19 +198,27 @@ class Storage extends Wrapper {
        }
 
        /**
-        * Setup the storate wrapper callback
+        * Setup the storage wrapper callback
         */
        public static function setupStorage() {
-               \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) {
-                       return new \OCA\Files_Trashbin\Storage(
-                               ['storage' => $storage, 'mountPoint' => $mountPoint],
-                               \OC::$server->query(ITrashManager::class),
-                               \OC::$server->getUserManager(),
-                               \OC::$server->getLogger(),
-                               \OC::$server->get(IEventDispatcher::class),
-                               \OC::$server->getLazyRootFolder()
-                       );
-               }, 1);
+               $trashManager = \OC::$server->get(ITrashManager::class);
+               $userManager = \OC::$server->get(IUserManager::class);
+               $logger = \OC::$server->get(LoggerInterface::class);
+               $eventDispatcher = \OC::$server->get(IEventDispatcher::class);
+               $rootFolder = \OC::$server->get(IRootFolder::class);
+               Filesystem::addStorageWrapper(
+                       'oc_trashbin',
+                       function (string $mountPoint, IStorage $storage) use ($trashManager, $userManager, $logger, $eventDispatcher, $rootFolder) {
+                               return new Storage(
+                                       ['storage' => $storage, 'mountPoint' => $mountPoint],
+                                       $trashManager,
+                                       $userManager,
+                                       $logger,
+                                       $eventDispatcher,
+                                       $rootFolder,
+                               );
+                       },
+               1);
        }
 
        public function getMountPoint() {
index b4b995c3ae59043d1ef2ff98da55c2b2f9404e75..1b9c23f778d9137d35fddc9e9b3a1d6905dcb0ef 100644 (file)
@@ -51,6 +51,7 @@ use OCP\ILogger;
 use OCP\IUserManager;
 use OCP\Lock\ILockingProvider;
 use OCP\Share\IShare;
+use Psr\Log\LoggerInterface;
 use Test\Traits\MountProviderTrait;
 
 class TemporaryNoCross extends Temporary {
@@ -606,7 +607,7 @@ class StorageTest extends \Test\TestCase {
                        ->disableOriginalConstructor()->getMock();
                $userManager->expects($this->any())
                        ->method('userExists')->willReturn($userExists);
-               $logger = $this->getMockBuilder(ILogger::class)->getMock();
+               $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
                $eventDispatcher = $this->createMock(IEventDispatcher::class);
                $rootFolder = $this->createMock(IRootFolder::class);
                $userFolder = $this->createMock(Folder::class);