From 63de669c687565e808becb0d79d72b92d0531e0c Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 4 Sep 2025 14:07:14 +0200 Subject: [PATCH] refactor: Commands and background jobs for the trashbin - Use modern node and SetupManager API - Avoid passing the user by id and instead use IUser Signed-off-by: Carl Schwan --- .../lib/BackgroundJob/ExpireTrash.php | 2 +- apps/files_trashbin/lib/Command/CleanUp.php | 62 +++++++++++-------- apps/files_trashbin/lib/Command/Expire.php | 37 +++++++++-- .../lib/Command/ExpireTrash.php | 52 ++++++++-------- .../lib/Command/RestoreAllFiles.php | 15 +++-- apps/files_trashbin/lib/Command/Size.php | 6 +- .../lib/Listener/EventListener.php | 22 ++++++- apps/files_trashbin/lib/Trashbin.php | 46 +++++--------- .../tests/Command/CleanUpTest.php | 42 +++++++++---- .../tests/Command/ExpireTrashTest.php | 6 +- build/psalm-baseline.xml | 44 ------------- 11 files changed, 177 insertions(+), 157 deletions(-) diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php index 8d3dad4a17a02..e73d37ec15928 100644 --- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php +++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php @@ -109,7 +109,7 @@ private function getNextOffset(): int { } - private function resetOffset() { + private function resetOffset(): void { $this->runMutexOperation(function () { $this->appConfig->setValueInt(Application::APP_ID, self::OFFSET_CONFIG_KEY_NAME, 0); }); diff --git a/apps/files_trashbin/lib/Command/CleanUp.php b/apps/files_trashbin/lib/Command/CleanUp.php index e9b4fa8ae6035..ae1a91072a7a4 100644 --- a/apps/files_trashbin/lib/Command/CleanUp.php +++ b/apps/files_trashbin/lib/Command/CleanUp.php @@ -7,29 +7,36 @@ */ namespace OCA\Files_Trashbin\Command; +use OC\Core\Command\Base; +use OC\Files\SetupManager; +use OC\User\LazyUser; use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OCP\IDBConnection; +use OCP\IUser; use OCP\IUserBackend; use OCP\IUserManager; use OCP\Util; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -class CleanUp extends Command { +class CleanUp extends Base { public function __construct( protected IRootFolder $rootFolder, protected IUserManager $userManager, protected IDBConnection $dbConnection, + protected SetupManager $setupManager, ) { parent::__construct(); } protected function configure() { + parent::configure(); $this ->setName('trashbin:cleanup') ->setDescription('Remove deleted files') @@ -53,9 +60,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int throw new InvalidOptionException('Either specify a user_id or --all-users'); } elseif (!empty($users)) { foreach ($users as $user) { - if ($this->userManager->userExists($user)) { + $userObject = $this->userManager->get($user); + if ($userObject) { $output->writeln("Remove deleted files of $user"); - $this->removeDeletedFiles($user, $output, $verbose); + $this->removeDeletedFiles($userObject, $output, $verbose); } else { $output->writeln("Unknown user $user"); return 1; @@ -75,7 +83,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $users = $backend->getUsers('', $limit, $offset); foreach ($users as $user) { $output->writeln(" $user"); - $this->removeDeletedFiles($user, $output, $verbose); + $userObject = new LazyUser($user, $this->userManager, null, $backend); + $this->removeDeletedFiles($userObject, $output, $verbose); } $offset += $limit; } while (count($users) >= $limit); @@ -89,30 +98,31 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** * remove deleted files for the given user */ - protected function removeDeletedFiles(string $uid, OutputInterface $output, bool $verbose): void { - \OC_Util::tearDownFS(); - \OC_Util::setupFS($uid); - $path = '/' . $uid . '/files_trashbin'; - if ($this->rootFolder->nodeExists($path)) { + protected function removeDeletedFiles(IUser $user, OutputInterface $output, bool $verbose): void { + $this->setupManager->tearDown(); + $this->setupManager->setupForUser($user); + $path = '/' . $user->getUID() . '/files_trashbin'; + try { $node = $this->rootFolder->get($path); - - if ($verbose) { - $output->writeln('Deleting ' . Util::humanFileSize($node->getSize()) . " in trash for $uid."); - } - $node->delete(); - if ($this->rootFolder->nodeExists($path)) { - $output->writeln('Trash folder sill exists after attempting to delete it'); - return; - } - $query = $this->dbConnection->getQueryBuilder(); - $query->delete('files_trash') - ->where($query->expr()->eq('user', $query->createParameter('uid'))) - ->setParameter('uid', $uid); - $query->executeStatement(); - } else { + } catch (NotFoundException|NotPermittedException) { if ($verbose) { - $output->writeln("No trash found for $uid"); + $output->writeln("No trash found for {$user->getUID()}"); } + return; + } + + if ($verbose) { + $output->writeln('Deleting ' . Util::humanFileSize($node->getSize()) . " in trash for {$user->getUID()}."); + } + $node->delete(); + if ($this->rootFolder->nodeExists($path)) { + $output->writeln('Trash folder sill exists after attempting to delete it'); + return; } + $query = $this->dbConnection->getQueryBuilder(); + $query->delete('files_trash') + ->where($query->expr()->eq('user', $query->createParameter('uid'))) + ->setParameter('uid', $user->getUID()); + $query->executeStatement(); } } diff --git a/apps/files_trashbin/lib/Command/Expire.php b/apps/files_trashbin/lib/Command/Expire.php index 73a42cd4749d7..9904db0e7580b 100644 --- a/apps/files_trashbin/lib/Command/Expire.php +++ b/apps/files_trashbin/lib/Command/Expire.php @@ -8,8 +8,14 @@ namespace OCA\Files_Trashbin\Command; use OC\Command\FileAccess; +use OC\Files\SetupManager; use OCA\Files_Trashbin\Trashbin; use OCP\Command\ICommand; +use OCP\Files\Folder; +use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; +use OCP\IUser; use OCP\IUserManager; use OCP\Server; @@ -26,14 +32,35 @@ public function __construct( public function handle() { $userManager = Server::get(IUserManager::class); - if (!$userManager->userExists($this->user)) { + $userObject = $userManager->get($this->user); + if (!$userObject) { // User has been deleted already return; } - \OC_Util::tearDownFS(); - \OC_Util::setupFS($this->user); - Trashbin::expire($this->user); - \OC_Util::tearDownFS(); + $rootFolder = $this->getTrashRoot($userObject); + if (!$rootFolder) { + return; + } + + Trashbin::expire($rootFolder, $userObject); + $setupManager = Server::get(SetupManager::class); + $setupManager->tearDown(); + } + + protected function getTrashRoot(IUser $user): ?Folder { + $setupManager = Server::get(SetupManager::class); + $rootFolder = Server::get(IRootFolder::class); + $setupManager->tearDown(); + $setupManager->setupForUser($user); + + try { + /** @var Folder $folder */ + $folder = $rootFolder->getUserFolder($user->getUID())->getParent()->get('files_trashbin'); + return $folder; + } catch (NotFoundException|NotPermittedException) { + $setupManager->tearDown(); + return null; + } } } diff --git a/apps/files_trashbin/lib/Command/ExpireTrash.php b/apps/files_trashbin/lib/Command/ExpireTrash.php index 422d83799845f..2ef78d6697ec6 100644 --- a/apps/files_trashbin/lib/Command/ExpireTrash.php +++ b/apps/files_trashbin/lib/Command/ExpireTrash.php @@ -7,33 +7,36 @@ */ namespace OCA\Files_Trashbin\Command; -use OC\Files\View; +use OC\Core\Command\Base; +use OC\Files\SetupManager; use OCA\Files_Trashbin\Expiration; use OCA\Files_Trashbin\Trashbin; +use OCP\Files\Folder; +use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OCP\IUser; use OCP\IUserManager; use Psr\Log\LoggerInterface; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ExpireTrash extends Command { +class ExpireTrash extends Base { - /** - * @param IUserManager|null $userManager - * @param Expiration|null $expiration - */ public function __construct( - private LoggerInterface $logger, - private ?IUserManager $userManager = null, - private ?Expiration $expiration = null, + readonly private LoggerInterface $logger, + readonly private ?IUserManager $userManager, + readonly private ?Expiration $expiration, + readonly private SetupManager $setupManager, + readonly private IRootFolder $rootFolder, ) { parent::__construct(); } protected function configure() { + parent::configure(); $this ->setName('trashbin:expire') ->setDescription('Expires the users trashbin') @@ -81,31 +84,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int public function expireTrashForUser(IUser $user) { try { - $uid = $user->getUID(); - if (!$this->setupFS($uid)) { + $trashRoot = $this->getTrashRoot($user); + if (!$trashRoot) { return; } - Trashbin::expire($uid); + Trashbin::expire($trashRoot, $user); } catch (\Throwable $e) { $this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]); } } - /** - * Act on behalf on trash item owner - * @param string $user - * @return boolean - */ - protected function setupFS($user) { - \OC_Util::tearDownFS(); - \OC_Util::setupFS($user); + protected function getTrashRoot(IUser $user): ?Folder { + $this->setupManager->tearDown(); + $this->setupManager->setupForUser($user); - // Check if this user has a trashbin directory - $view = new View('/' . $user); - if (!$view->is_dir('/files_trashbin/files')) { - return false; + try { + /** @var Folder $folder */ + $folder = $this->rootFolder->getUserFolder($user->getUID())->getParent()->get('files_trashbin'); + return $folder; + } catch (NotFoundException|NotPermittedException) { + return null; } - - return true; } } diff --git a/apps/files_trashbin/lib/Command/RestoreAllFiles.php b/apps/files_trashbin/lib/Command/RestoreAllFiles.php index ce31f759c0eca..938a98b36bfdf 100644 --- a/apps/files_trashbin/lib/Command/RestoreAllFiles.php +++ b/apps/files_trashbin/lib/Command/RestoreAllFiles.php @@ -7,6 +7,7 @@ namespace OCA\Files_Trashbin\Command; use OC\Core\Command\Base; +use OC\Files\SetupManager; use OCA\Files_Trashbin\Trash\ITrashManager; use OCA\Files_Trashbin\Trash\TrashItem; use OCP\Files\IRootFolder; @@ -14,6 +15,7 @@ use OCP\IL10N; use OCP\IUserBackend; use OCP\IUserManager; +use OCP\IUserSession; use OCP\L10N\IFactory; use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Input\InputArgument; @@ -48,6 +50,8 @@ public function __construct( protected IUserManager $userManager, protected IDBConnection $dbConnection, protected ITrashManager $trashManager, + protected SetupManager $setupManager, + protected IUserSession $userSession, IFactory $l10nFactory, ) { parent::__construct(); @@ -140,17 +144,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int * Restore deleted files for the given user according to the given filters */ protected function restoreDeletedFiles(string $uid, int $scope, ?int $since, ?int $until, bool $dryRun, OutputInterface $output): void { - \OC_Util::tearDownFS(); - \OC_Util::setupFS($uid); - \OC_User::setUserId($uid); - $user = $this->userManager->get($uid); - - if ($user === null) { + if (!$user) { $output->writeln("Unknown user $uid"); return; } + $this->setupManager->tearDown(); + $this->setupManager->setupForUser($user); + $this->userSession->setUser($user); + $userTrashItems = $this->filterTrashItems( $this->trashManager->listTrashRoot($user), $scope, diff --git a/apps/files_trashbin/lib/Command/Size.php b/apps/files_trashbin/lib/Command/Size.php index 9c19d4d92b358..aeb1b63498900 100644 --- a/apps/files_trashbin/lib/Command/Size.php +++ b/apps/files_trashbin/lib/Command/Size.php @@ -10,6 +10,7 @@ use OC\Core\Command\Base; use OCP\Command\IBus; +use OCP\IAppConfig; use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; @@ -21,6 +22,7 @@ class Size extends Base { public function __construct( + private IAppConfig $appConfig, private IConfig $config, private IUserManager $userManager, private IBus $commandBus, @@ -55,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->config->setUserValue($user, 'files_trashbin', 'trashbin_size', (string)$parsedSize); $this->commandBus->push(new Expire($user)); } else { - $this->config->setAppValue('files_trashbin', 'trashbin_size', (string)$parsedSize); + $this->appConfig->setValueInt('files_trashbin', 'trashbin_size', $parsedSize); $output->writeln('Warning: changing the default trashbin size will automatically trigger cleanup of existing trashbins,'); $output->writeln('a users trashbin can exceed the configured size until they move a new file to the trashbin.'); } @@ -67,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } private function printTrashbinSize(InputInterface $input, OutputInterface $output, ?string $user) { - $globalSize = (int)$this->config->getAppValue('files_trashbin', 'trashbin_size', '-1'); + $globalSize = $this->appConfig->getValueInt('files_trashbin', 'trashbin_size', -1); if ($globalSize < 0) { $globalHumanSize = 'default (50% of available space)'; } else { diff --git a/apps/files_trashbin/lib/Listener/EventListener.php b/apps/files_trashbin/lib/Listener/EventListener.php index 63ecc9c81f73e..06f8f48e7bb9f 100644 --- a/apps/files_trashbin/lib/Listener/EventListener.php +++ b/apps/files_trashbin/lib/Listener/EventListener.php @@ -15,11 +15,18 @@ use OCP\EventDispatcher\IEventListener; use OCP\Files\Events\BeforeFileSystemSetupEvent; use OCP\Files\Events\Node\NodeWrittenEvent; +use OCP\Files\Folder; +use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; +use OCP\IUserManager; use OCP\User\Events\BeforeUserDeletedEvent; /** @template-implements IEventListener */ class EventListener implements IEventListener { public function __construct( + private IUserManager $userManager, + private IRootFolder $rootFolder, private ?string $userId = null, ) { } @@ -27,8 +34,19 @@ public function __construct( public function handle(Event $event): void { if ($event instanceof NodeWrittenEvent) { // Resize trash - if (!empty($this->userId)) { - Trashbin::resizeTrash($this->userId); + if (empty($this->userId)) { + return; + } + try { + /** @var Folder $trashRoot */ + $trashRoot = $this->rootFolder->get('/' . $this->userId . '/files_trashbin'); + } catch (NotFoundException|NotPermittedException) { + return; + } + + $user = $this->userManager->get($this->userId); + if ($user) { + Trashbin::resizeTrash($trashRoot, $user); } } diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index dd71e8ec28e46..accccf08211a2 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -42,6 +42,7 @@ use OCP\IConfig; use OCP\IDBConnection; use OCP\IURLGenerator; +use OCP\IUser; use OCP\IUserManager; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; @@ -764,24 +765,19 @@ public static function deleteUser($uid) { } /** - * calculate remaining free space for trash bin + * Calculate remaining free space for trash bin * * @param int|float $trashbinSize current size of the trash bin - * @param string $user * @return int|float available free space for trash bin */ - private static function calculateFreeSpace(int|float $trashbinSize, string $user): int|float { - $configuredTrashbinSize = static::getConfiguredTrashbinSize($user); + private static function calculateFreeSpace(Folder $userFolder, int|float $trashbinSize, IUser $user): int|float { + $configuredTrashbinSize = static::getConfiguredTrashbinSize($user->getUID()); if ($configuredTrashbinSize > -1) { return $configuredTrashbinSize - $trashbinSize; } - $userObject = Server::get(IUserManager::class)->get($user); - if (is_null($userObject)) { - return 0; - } $softQuota = true; - $quota = $userObject->getQuota(); + $quota = $user->getQuota(); if ($quota === null || $quota === 'none') { $quota = Filesystem::free_space('/'); $softQuota = false; @@ -800,10 +796,6 @@ private static function calculateFreeSpace(int|float $trashbinSize, string $user // calculate available space for trash bin // subtract size of files and current trash bin size from quota if ($softQuota) { - $userFolder = \OC::$server->getUserFolder($user); - if (is_null($userFolder)) { - return 0; - } $free = $quota - $userFolder->getSize(false); // remaining free space for user if ($free > 0) { $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $trashbinSize; // how much space can be used for versions @@ -818,38 +810,34 @@ private static function calculateFreeSpace(int|float $trashbinSize, string $user } /** - * resize trash bin if necessary after a new file was added to Nextcloud - * - * @param string $user user id + * Resize trash bin if necessary after a new file was added to Nextcloud */ - public static function resizeTrash($user) { - $size = self::getTrashbinSize($user); + public static function resizeTrash(Folder $trashRoot, IUser $user): void { + $trashBinSize = $trashRoot->getSize(); - $freeSpace = self::calculateFreeSpace($size, $user); + $freeSpace = self::calculateFreeSpace($trashRoot->getParent(), $trashBinSize, $user); if ($freeSpace < 0) { - self::scheduleExpire($user); + self::scheduleExpire($user->getUID()); } } /** - * clean up the trash bin - * - * @param string $user + * Clean up the trash bin */ - public static function expire($user) { - $trashBinSize = self::getTrashbinSize($user); - $availableSpace = self::calculateFreeSpace($trashBinSize, $user); + public static function expire(Folder $trashRoot, IUser $user): void { + $trashBinSize = $trashRoot->getSize(); + $availableSpace = self::calculateFreeSpace($trashRoot->getParent(), $trashBinSize, $user); - $dirContent = Helper::getTrashFiles('/', $user, 'mtime'); + $dirContent = Helper::getTrashFiles('/', $user->getUID(), 'mtime'); // delete all files older then $retention_obligation - [$delSize, $count] = self::deleteExpiredFiles($dirContent, $user); + [$delSize, $count] = self::deleteExpiredFiles($dirContent, $user->getUID()); $availableSpace += $delSize; // delete files from trash until we meet the trash bin size limit again - self::deleteFiles(array_slice($dirContent, $count), $user, $availableSpace); + self::deleteFiles(array_slice($dirContent, $count), $user->getUID(), $availableSpace); } /** diff --git a/apps/files_trashbin/tests/Command/CleanUpTest.php b/apps/files_trashbin/tests/Command/CleanUpTest.php index 41ed0e1e960d8..045860897877b 100644 --- a/apps/files_trashbin/tests/Command/CleanUpTest.php +++ b/apps/files_trashbin/tests/Command/CleanUpTest.php @@ -8,9 +8,12 @@ */ namespace OCA\Files_Trashbin\Tests\Command; +use OC\Files\SetupManager; use OCA\Files_Trashbin\Command\CleanUp; use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; use OCP\IDBConnection; +use OCP\IUser; use OCP\IUserManager; use OCP\Server; use OCP\UserInterface; @@ -34,16 +37,22 @@ class CleanUpTest extends TestCase { protected IDBConnection $dbConnection; protected CleanUp $cleanup; protected string $trashTable = 'files_trash'; - protected string $user0 = 'user0'; + protected IUser&MockObject $user0; + protected SetupManager&MockObject $setupManager; protected function setUp(): void { parent::setUp(); + + $this->user0 = $this->createMock(IUser::class); + $this->user0->method('getUID')->willReturn('user0'); + $this->rootFolder = $this->createMock(IRootFolder::class); $this->userManager = $this->createMock(IUserManager::class); $this->dbConnection = Server::get(IDBConnection::class); + $this->setupManager = $this->createMock(SetupManager::class); - $this->cleanup = new CleanUp($this->rootFolder, $this->userManager, $this->dbConnection); + $this->cleanup = new CleanUp($this->rootFolder, $this->userManager, $this->dbConnection, $this->setupManager); } /** @@ -74,17 +83,20 @@ public function testRemoveDeletedFiles(bool $nodeExists): void { $this->initTable(); $this->rootFolder ->method('nodeExists') - ->with('/' . $this->user0 . '/files_trashbin') - ->willReturnOnConsecutiveCalls($nodeExists, false); + ->with('/' . $this->user0->getUID() . '/files_trashbin') + ->willReturn(false); if ($nodeExists) { $this->rootFolder ->method('get') - ->with('/' . $this->user0 . '/files_trashbin') + ->with('/' . $this->user0->getUID() . '/files_trashbin') ->willReturn($this->rootFolder); $this->rootFolder ->method('delete'); } else { - $this->rootFolder->expects($this->never())->method('get'); + $this->rootFolder + ->method('get') + ->with('/' . $this->user0->getUID() . '/files_trashbin') + ->willThrowException(new NotFoundException()); $this->rootFolder->expects($this->never())->method('delete'); } self::invokePrivate($this->cleanup, 'removeDeletedFiles', [$this->user0, new NullOutput(), false]); @@ -129,15 +141,19 @@ public function testExecuteDeleteListOfUsers(): void { $userIds = ['user1', 'user2', 'user3']; $instance = $this->getMockBuilder(CleanUp::class) ->onlyMethods(['removeDeletedFiles']) - ->setConstructorArgs([$this->rootFolder, $this->userManager, $this->dbConnection]) + ->setConstructorArgs([$this->rootFolder, $this->userManager, $this->dbConnection, $this->setupManager]) ->getMock(); $instance->expects($this->exactly(count($userIds))) ->method('removeDeletedFiles') - ->willReturnCallback(function ($user) use ($userIds): void { - $this->assertTrue(in_array($user, $userIds)); + ->willReturnCallback(function (IUser $user) use ($userIds): void { + $this->assertTrue(in_array($user->getUID(), $userIds)); }); $this->userManager->expects($this->exactly(count($userIds))) - ->method('userExists')->willReturn(true); + ->method('get')->willReturnCallback(function (string $userId): IUser { + $user = $this->createMock(IUser::class); + $user->method('getUID')->willReturn($userId); + return $user; + }); $inputInterface = $this->createMock(\Symfony\Component\Console\Input\InputInterface::class); $inputInterface->method('getArgument') ->with('user_id') @@ -159,7 +175,7 @@ public function testExecuteAllUsers(): void { $backendUsers = ['user1', 'user2']; $instance = $this->getMockBuilder(CleanUp::class) ->onlyMethods(['removeDeletedFiles']) - ->setConstructorArgs([$this->rootFolder, $this->userManager, $this->dbConnection]) + ->setConstructorArgs([$this->rootFolder, $this->userManager, $this->dbConnection, $this->setupManager]) ->getMock(); $backend = $this->createMock(UserInterface::class); $backend->method('getUsers') @@ -167,8 +183,8 @@ public function testExecuteAllUsers(): void { ->willReturn($backendUsers); $instance->expects($this->exactly(count($backendUsers))) ->method('removeDeletedFiles') - ->willReturnCallback(function ($user) use ($backendUsers): void { - $this->assertTrue(in_array($user, $backendUsers)); + ->willReturnCallback(function (IUser $user) use ($backendUsers): void { + $this->assertTrue(in_array($user->getUID(), $backendUsers)); }); $inputInterface = $this->createMock(InputInterface::class); $inputInterface->method('getArgument') diff --git a/apps/files_trashbin/tests/Command/ExpireTrashTest.php b/apps/files_trashbin/tests/Command/ExpireTrashTest.php index 0d0ee98ca7a23..9ca18524a87af 100644 --- a/apps/files_trashbin/tests/Command/ExpireTrashTest.php +++ b/apps/files_trashbin/tests/Command/ExpireTrashTest.php @@ -6,6 +6,7 @@ */ namespace OCA\Files_Trashbin\Tests\Command; +use OC\Files\SetupManager; use OCA\Files_Trashbin\Command\ExpireTrash; use OCA\Files_Trashbin\Expiration; use OCA\Files_Trashbin\Helper; @@ -36,7 +37,6 @@ class ExpireTrashTest extends TestCase { private IUser $user; private ITimeFactory $timeFactory; - protected function setUp(): void { parent::setUp(); @@ -101,7 +101,9 @@ public function testRetentionObligation(string $obligation, string $quota, int $ $command = new ExpireTrash( Server::get(LoggerInterface::class), Server::get(IUserManager::class), - $this->expiration + $this->expiration, + Server::get(SetupManager::class), + Server::get(IRootFolder::class), ); $this->invokePrivate($command, 'execute', [$inputInterface, $outputInterface]); diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 3082ec0f958f2..19e4486b1db15 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -1754,50 +1754,6 @@ - - - - - - - - - - - - user)]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -