Skip to content

Commit

Permalink
only gather dependencies for trashbin wrapper once
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Aug 18, 2023
1 parent 9ea03a9 commit 36f9ebb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
63 changes: 30 additions & 33 deletions apps/files_trashbin/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,43 +40,32 @@
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
*/
public function __construct(
$parameters,
ITrashManager $trashManager = null,
IUserManager $userManager = null,
ILogger $logger = null,
LoggerInterface $logger = null,
IEventDispatcher $eventDispatcher = null,
IRootFolder $rootFolder = null
) {
Expand Down Expand Up @@ -209,19 +198,27 @@ private function doDelete($path, $method) {
}

/**
* 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() {
Expand Down
3 changes: 2 additions & 1 deletion apps/files_trashbin/tests/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;
use Test\Traits\MountProviderTrait;

class TemporaryNoCross extends Temporary {
Expand Down Expand Up @@ -606,7 +607,7 @@ public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisab
->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);
Expand Down

0 comments on commit 36f9ebb

Please sign in to comment.