From 0e5a3d190cabee32244cba3056d73b23b0f01628 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 18 Sep 2024 20:48:02 +0200 Subject: [PATCH 1/8] refactor(GroupVersionsExpireManager): Migrate to typed events Signed-off-by: provokateurin --- lib/AppInfo/Application.php | 3 +++ .../ExpireGroup/ExpireGroupVersions.php | 20 +++++++++------- .../ExpireGroup/ExpireGroupVersionsTrash.php | 4 +++- .../GroupVersionsExpireDeleteFileEvent.php | 22 ++++++++++++++++++ .../GroupVersionsExpireDeleteVersionEvent.php | 23 +++++++++++++++++++ .../GroupVersionsExpireEnterFolderEvent.php | 22 ++++++++++++++++++ lib/Versions/GroupVersionsExpireManager.php | 14 ++++++----- 7 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 lib/Event/GroupVersionsExpireDeleteFileEvent.php create mode 100644 lib/Event/GroupVersionsExpireDeleteVersionEvent.php create mode 100644 lib/Event/GroupVersionsExpireEnterFolderEvent.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index b36934212..65222d134 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -42,6 +42,7 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\Events\Node\NodeRenamedEvent; use OCP\Files\Folder; @@ -164,6 +165,7 @@ public function register(IRegistrationContext $context): void { if ($hasVersionApp && $hasTrashApp) { return new ExpireGroupVersionsTrash( $c->get(GroupVersionsExpireManager::class), + $c->get(IEventDispatcher::class), $c->get(TrashBackend::class), $c->get(Expiration::class) ); @@ -172,6 +174,7 @@ public function register(IRegistrationContext $context): void { if ($hasVersionApp) { return new ExpireGroupVersions( $c->get(GroupVersionsExpireManager::class), + $c->get(IEventDispatcher::class), ); } diff --git a/lib/Command/ExpireGroup/ExpireGroupVersions.php b/lib/Command/ExpireGroup/ExpireGroupVersions.php index b4d8031eb..f092d183c 100644 --- a/lib/Command/ExpireGroup/ExpireGroupVersions.php +++ b/lib/Command/ExpireGroup/ExpireGroupVersions.php @@ -8,8 +8,11 @@ namespace OCA\GroupFolders\Command\ExpireGroup; -use OCA\Files_Versions\Versions\IVersion; +use OCA\GroupFolders\Event\GroupVersionsExpireDeleteFileEvent; +use OCA\GroupFolders\Event\GroupVersionsExpireDeleteVersionEvent; +use OCA\GroupFolders\Event\GroupVersionsExpireEnterFolderEvent; use OCA\GroupFolders\Versions\GroupVersionsExpireManager; +use OCP\EventDispatcher\IEventDispatcher; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -19,6 +22,7 @@ class ExpireGroupVersions extends ExpireGroupBase { public function __construct( private GroupVersionsExpireManager $expireManager, + private IEventDispatcher $eventDispatcher, ) { parent::__construct(); } @@ -31,17 +35,17 @@ protected function configure(): void { } protected function execute(InputInterface $input, OutputInterface $output): int { - $this->expireManager->listen(GroupVersionsExpireManager::class, 'enterFolder', function (array $folder) use ($output): void { - $output->writeln("Expiring version in '{$folder['mount_point']}'"); + $this->eventDispatcher->addListener(GroupVersionsExpireEnterFolderEvent::class, function (GroupVersionsExpireEnterFolderEvent $event) use ($output): void { + $output->writeln("Expiring version in '{$event->folder['mount_point']}'"); }); - $this->expireManager->listen(GroupVersionsExpireManager::class, 'deleteVersion', function (IVersion $version) use ($output): void { - $id = $version->getRevisionId(); - $file = $version->getSourceFileName(); + $this->eventDispatcher->addListener(GroupVersionsExpireDeleteVersionEvent::class, function (GroupVersionsExpireDeleteVersionEvent $event) use ($output): void { + $id = $event->version->getRevisionId(); + $file = $event->version->getSourceFileName(); $output->writeln("Expiring version $id for '$file'"); }); - $this->expireManager->listen(GroupVersionsExpireManager::class, 'deleteFile', function (int $id) use ($output): void { - $output->writeln("Cleaning up versions for no longer existing file with id $id"); + $this->eventDispatcher->addListener(GroupVersionsExpireDeleteFileEvent::class, function (GroupVersionsExpireDeleteFileEvent $event) use ($output): void { + $output->writeln('Cleaning up versions for no longer existing file with id ' . $event->fileId . ''); }); $this->expireManager->expireAll(); diff --git a/lib/Command/ExpireGroup/ExpireGroupVersionsTrash.php b/lib/Command/ExpireGroup/ExpireGroupVersionsTrash.php index 4e27e1879..80f73459e 100644 --- a/lib/Command/ExpireGroup/ExpireGroupVersionsTrash.php +++ b/lib/Command/ExpireGroup/ExpireGroupVersionsTrash.php @@ -11,16 +11,18 @@ use OCA\Files_Trashbin\Expiration; use OCA\GroupFolders\Trash\TrashBackend; use OCA\GroupFolders\Versions\GroupVersionsExpireManager; +use OCP\EventDispatcher\IEventDispatcher; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class ExpireGroupVersionsTrash extends ExpireGroupVersions { public function __construct( GroupVersionsExpireManager $expireManager, + IEventDispatcher $eventDispatcher, private TrashBackend $trashBackend, private Expiration $expiration, ) { - parent::__construct($expireManager); + parent::__construct($expireManager, $eventDispatcher); } protected function configure(): void { diff --git a/lib/Event/GroupVersionsExpireDeleteFileEvent.php b/lib/Event/GroupVersionsExpireDeleteFileEvent.php new file mode 100644 index 000000000..439bec2d0 --- /dev/null +++ b/lib/Event/GroupVersionsExpireDeleteFileEvent.php @@ -0,0 +1,22 @@ +folderManager->getAllFolders(); foreach ($folders as $folder) { - $this->emit(self::class, 'enterFolder', [$folder]); + $this->dispatcher->dispatchTyped(new GroupVersionsExpireEnterFolderEvent($folder)); $this->expireFolder($folder); } } public function expireFolders(array $folders): void { foreach ($folders as $folder) { - $this->emit(self::class, 'enterFolder', [$folder]); + $this->dispatcher->dispatchTyped(new GroupVersionsExpireEnterFolderEvent($folder)); $this->expireFolder($folder); } } @@ -64,12 +66,12 @@ public function expireFolder(array $folder): void { $expireVersions = $this->expireManager->getExpiredVersion($versions, $this->timeFactory->getTime(), false); foreach ($expireVersions as $version) { /** @var GroupVersion $version */ - $this->emit(self::class, 'deleteVersion', [$version]); + $this->dispatcher->dispatchTyped(new GroupVersionsExpireDeleteVersionEvent($version)); $view->unlink('/' . $fileId . '/' . $version->getVersionFile()->getName()); } } else { // source file no longer exists - $this->emit(self::class, 'deleteFile', [$fileId]); + $this->dispatcher->dispatchTyped(new GroupVersionsExpireDeleteFileEvent($fileId)); $this->versionsBackend->deleteAllVersionsForFile($folder['id'], $fileId); } } From 6bbb836de5ba219bb92a95f4a95f504dc1489b8a Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 18 Sep 2024 20:48:44 +0200 Subject: [PATCH 2/8] refactor(CacheListener): Switch to non-deprecated event classes Signed-off-by: provokateurin --- lib/CacheListener.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/CacheListener.php b/lib/CacheListener.php index c35136a3e..bb4fb735b 100644 --- a/lib/CacheListener.php +++ b/lib/CacheListener.php @@ -9,8 +9,8 @@ use OCA\GroupFolders\Mount\GroupFolderStorage; use OCP\EventDispatcher\IEventDispatcher; -use OCP\Files\Cache\CacheInsertEvent; -use OCP\Files\Cache\CacheUpdateEvent; +use OCP\Files\Cache\CacheEntryInsertedEvent; +use OCP\Files\Cache\CacheEntryUpdatedEvent; use OCP\Files\Cache\ICacheEvent; class CacheListener { @@ -20,8 +20,8 @@ public function __construct( } public function listen(): void { - $this->eventDispatcher->addListener(CacheInsertEvent::class, $this->onCacheEvent(...), 99999); - $this->eventDispatcher->addListener(CacheUpdateEvent::class, $this->onCacheEvent(...), 99999); + $this->eventDispatcher->addListener(CacheEntryInsertedEvent::class, $this->onCacheEvent(...), 99999); + $this->eventDispatcher->addListener(CacheEntryUpdatedEvent::class, $this->onCacheEvent(...), 99999); } public function onCacheEvent(ICacheEvent $event): void { From 92256e9467c7a690e205f411a3a426ce8d72270e Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 18 Sep 2024 20:49:52 +0200 Subject: [PATCH 3/8] refactor(AuthorizedAdminSettingMiddleware): Migrate RequireGroupFolderAdmin from annotation to attribute Signed-off-by: provokateurin --- lib/Attribute/RequireGroupFolderAdmin.php | 15 +++++++++ lib/AuthorizedAdminSettingMiddleware.php | 11 +++---- lib/Controller/DelegationController.php | 9 +++--- lib/Controller/FolderController.php | 37 +++++++---------------- 4 files changed, 35 insertions(+), 37 deletions(-) create mode 100644 lib/Attribute/RequireGroupFolderAdmin.php diff --git a/lib/Attribute/RequireGroupFolderAdmin.php b/lib/Attribute/RequireGroupFolderAdmin.php new file mode 100644 index 000000000..1558ba6b3 --- /dev/null +++ b/lib/Attribute/RequireGroupFolderAdmin.php @@ -0,0 +1,15 @@ +reflector->hasAnnotation('RequireGroupFolderAdmin')) { - if (!$this->delegatedService->hasApiAccess()) { - throw new Exception('Logged in user must be an admin, a sub admin or gotten special right to access this setting'); - } + $method = new ReflectionMethod($controller, $methodName); + if ($method->getAttributes(RequireGroupFolderAdmin::class) !== [] && !$this->delegatedService->hasApiAccess()) { + throw new Exception('Logged in user must be an admin, a sub admin or gotten special right to access this setting'); } } diff --git a/lib/Controller/DelegationController.php b/lib/Controller/DelegationController.php index 2bead302e..99daf6dbd 100644 --- a/lib/Controller/DelegationController.php +++ b/lib/Controller/DelegationController.php @@ -8,6 +8,7 @@ namespace OCA\GroupFolders\Controller; use OCA\Circles\CirclesManager; +use OCA\GroupFolders\Attribute\RequireGroupFolderAdmin; use OCA\GroupFolders\Service\DelegationService; use OCA\Settings\Service\AuthorizedGroupService; use OCP\App\IAppManager; @@ -38,9 +39,8 @@ public function __construct( /** * Returns the list of all groups - * - * @RequireGroupFolderAdmin */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'GET', url: '/delegation/groups')] public function getAllGroups(): DataResponse { @@ -61,9 +61,8 @@ public function getAllGroups(): DataResponse { /** * Returns the list of all visible circles - * - * @RequireGroupFolderAdmin */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'GET', url: '/delegation/circles')] public function getAllCircles(): DataResponse { @@ -102,8 +101,8 @@ public function getAllCircles(): DataResponse { * - OCA\GroupFolders\Settings\Admin : It's reference to fields in Admin Priveleges. * - OCA\GroupFolders\Controller\DelegationController : It's just to specific the subadmins. * They can only manage groupfolders in which they are added in the Advanced Permissions (groups only) - * @RequireGroupFolderAdmin */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'GET', url: '/delegation/authorized-groups')] public function getAuthorizedGroups(string $classname = ''): DataResponse { diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php index b760098c7..3e70bcd74 100644 --- a/lib/Controller/FolderController.php +++ b/lib/Controller/FolderController.php @@ -8,6 +8,7 @@ namespace OCA\GroupFolders\Controller; use OC\AppFramework\OCS\V1Response; +use OCA\GroupFolders\Attribute\RequireGroupFolderAdmin; use OCA\GroupFolders\Folder\FolderManager; use OCA\GroupFolders\Mount\MountProvider; use OCA\GroupFolders\Service\DelegationService; @@ -136,9 +137,9 @@ private function getRootFolderStorageId(): ?int { } /** - * @RequireGroupFolderAdmin * @throws OCSNotFoundException */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'POST', url: '/folders')] public function addFolder(string $mountpoint): DataResponse { @@ -151,9 +152,7 @@ public function addFolder(string $mountpoint): DataResponse { return new DataResponse($folder); } - /** - * @RequireGroupFolderAdmin - */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'DELETE', url: '/folders/{id}')] public function removeFolder(int $id): DataResponse { @@ -169,9 +168,7 @@ public function removeFolder(int $id): DataResponse { return new DataResponse(['success' => true]); } - /** - * @RequireGroupFolderAdmin - */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'PUT', url: '/folders/{id}')] public function setMountPoint(int $id, string $mountPoint): DataResponse { @@ -179,9 +176,7 @@ public function setMountPoint(int $id, string $mountPoint): DataResponse { return new DataResponse(['success' => true]); } - /** - * @RequireGroupFolderAdmin - */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'POST', url: '/folders/{id}/groups')] public function addGroup(int $id, string $group): DataResponse { @@ -195,9 +190,7 @@ public function addGroup(int $id, string $group): DataResponse { return new DataResponse(['success' => true]); } - /** - * @RequireGroupFolderAdmin - */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'DELETE', url: '/folders/{id}/groups/{group}', requirements: ['group' => '.+'])] public function removeGroup(int $id, string $group): DataResponse { @@ -211,9 +204,7 @@ public function removeGroup(int $id, string $group): DataResponse { return new DataResponse(['success' => true]); } - /** - * @RequireGroupFolderAdmin - */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'POST', url: '/folders/{id}/groups/{group}', requirements: ['group' => '.+'])] public function setPermissions(int $id, string $group, int $permissions): DataResponse { @@ -228,9 +219,9 @@ public function setPermissions(int $id, string $group, int $permissions): DataRe } /** - * @RequireGroupFolderAdmin * @throws \OCP\DB\Exception */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'POST', url: '/folders/{id}/manageACL')] public function setManageACL(int $id, string $mappingType, string $mappingId, bool $manageAcl): DataResponse { @@ -244,9 +235,7 @@ public function setManageACL(int $id, string $mappingType, string $mappingId, bo return new DataResponse(['success' => true]); } - /** - * @RequireGroupFolderAdmin - */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'POST', url: '/folders/{id}/quota')] public function setQuota(int $id, int $quota): DataResponse { @@ -260,9 +249,7 @@ public function setQuota(int $id, int $quota): DataResponse { return new DataResponse(['success' => true]); } - /** - * @RequireGroupFolderAdmin - */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'POST', url: '/folders/{id}/acl')] public function setACL(int $id, bool $acl): DataResponse { @@ -276,9 +263,7 @@ public function setACL(int $id, bool $acl): DataResponse { return new DataResponse(['success' => true]); } - /** - * @RequireGroupFolderAdmin - */ + #[RequireGroupFolderAdmin] #[NoAdminRequired] #[ApiRoute(verb: 'POST', url: '/folders/{id}/mountpoint')] public function renameFolder(int $id, string $mountpoint): DataResponse { From 86043ccc821cf8be67c00a9a6a703fef22c9c301 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 18 Sep 2024 20:56:37 +0200 Subject: [PATCH 4/8] refactor(Migration): Replace deprecated changeColumn() with modifyColumn() Signed-off-by: provokateurin --- lib/Migration/Version19000Date20240903062631.php | 2 +- lib/Migration/Version501000Date20190927102434.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Migration/Version19000Date20240903062631.php b/lib/Migration/Version19000Date20240903062631.php index 6bc8d80ca..0e397385d 100644 --- a/lib/Migration/Version19000Date20240903062631.php +++ b/lib/Migration/Version19000Date20240903062631.php @@ -21,7 +21,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('group_folders')) { $table = $schema->getTable('group_folders'); - $table->changeColumn('quota', [ + $table->modifyColumn('quota', [ 'notnull' => true, 'length' => 6, 'default' => null, diff --git a/lib/Migration/Version501000Date20190927102434.php b/lib/Migration/Version501000Date20190927102434.php index b49f6b31a..a5c09cefe 100644 --- a/lib/Migration/Version501000Date20190927102434.php +++ b/lib/Migration/Version501000Date20190927102434.php @@ -18,7 +18,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $schema = $schemaClosure(); $table = $schema->getTable('group_folders'); - $table->changeColumn('mount_point', [ + $table->modifyColumn('mount_point', [ 'notnull' => true, 'length' => 4000 ]); From e3571ac4232e7bb14837dbd525223b3c30129383 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 19 Sep 2024 11:18:54 +0200 Subject: [PATCH 5/8] refactor: Migrate to \OCP\Server::get() Signed-off-by: provokateurin --- lib/AppInfo/Application.php | 13 +++---------- lib/Command/Trashbin/Cleanup.php | 4 +++- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 65222d134..929d955a3 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -57,6 +57,7 @@ use OCP\IRequest; use OCP\IUserManager; use OCP\IUserSession; +use OCP\Server; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -236,20 +237,12 @@ public function register(IRegistrationContext $context): void { public function boot(IBootContext $context): void { $context->injectFn(function (IMountProviderCollection $mountProviderCollection, CacheListener $cacheListener, Group\Manager $groupManager): void { - $mountProviderCollection->registerProvider($this->getMountProvider()); + $mountProviderCollection->registerProvider(Server::get(MountProvider::class)); $groupManager->listen('\OC\Group', 'postDelete', function (IGroup $group): void { - $this->getFolderManager()->deleteGroup($group->getGID()); + Server::get(FolderManager::class)->deleteGroup($group->getGID()); }); $cacheListener->listen(); }); } - - public function getMountProvider(): MountProvider { - return $this->getContainer()->get(MountProvider::class); - } - - public function getFolderManager(): FolderManager { - return $this->getContainer()->get(FolderManager::class); - } } diff --git a/lib/Command/Trashbin/Cleanup.php b/lib/Command/Trashbin/Cleanup.php index 88b73a911..b6340c907 100644 --- a/lib/Command/Trashbin/Cleanup.php +++ b/lib/Command/Trashbin/Cleanup.php @@ -11,6 +11,8 @@ use OC\Core\Command\Base; use OCA\GroupFolders\Folder\FolderManager; use OCA\GroupFolders\Trash\TrashBackend; +use OCP\App\IAppManager; +use OCP\Server; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -23,7 +25,7 @@ class Cleanup extends Base { public function __construct(FolderManager $folderManager) { parent::__construct(); - if (\OC::$server->getAppManager()->isEnabledForUser('files_trashbin')) { + if (Server::get(IAppManager::class)->isEnabledForUser('files_trashbin')) { $this->trashBackend = \OCP\Server::get(TrashBackend::class); $this->folderManager = $folderManager; } From 9401652623141b909dd0f71f9418e092973e13f2 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 19 Sep 2024 11:22:08 +0200 Subject: [PATCH 6/8] refactor: Migrate to IAppConfig Signed-off-by: provokateurin --- lib/ACL/ACLManagerFactory.php | 6 +++--- lib/AppInfo/Application.php | 12 ++++++------ lib/BackgroundJob/ExpireGroupTrash.php | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/ACL/ACLManagerFactory.php b/lib/ACL/ACLManagerFactory.php index 7a2e571eb..cd5915d3a 100644 --- a/lib/ACL/ACLManagerFactory.php +++ b/lib/ACL/ACLManagerFactory.php @@ -9,7 +9,7 @@ namespace OCA\GroupFolders\ACL; use OCA\GroupFolders\Trash\TrashManager; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\IUser; use Psr\Log\LoggerInterface; @@ -17,7 +17,7 @@ class ACLManagerFactory { public function __construct( private RuleManager $ruleManager, private TrashManager $trashManager, - private IConfig $config, + private IAppConfig $config, private LoggerInterface $logger, private \Closure $rootFolderProvider, ) { @@ -31,7 +31,7 @@ public function getACLManager(IUser $user, ?int $rootStorageId = null): ACLManag $user, $this->rootFolderProvider, $rootStorageId, - $this->config->getAppValue('groupfolders', 'acl-inherit-per-user', 'false') === 'true', + $this->config->getValueString('groupfolders', 'acl-inherit-per-user', 'false') === 'true', ); } } diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 929d955a3..26724ebdf 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -51,7 +51,6 @@ use OCP\Files\NotFoundException; use OCP\IAppConfig; use OCP\ICacheFactory; -use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroup; use OCP\IRequest; @@ -105,9 +104,10 @@ public function register(IRegistrationContext $context): void { $rootProvider = function () use ($c): Folder { return $c->get('GroupAppFolder'); }; - $config = $c->get(IConfig::class); - $allowRootShare = $config->getAppValue('groupfolders', 'allow_root_share', 'true') === 'true'; - $enableEncryption = $config->getAppValue('groupfolders', 'enable_encryption', 'false') === 'true'; + /** @var IAppConfig $config */ + $config = $c->get(IAppConfig::class); + $allowRootShare = $config->getValueString('groupfolders', 'allow_root_share', 'true') === 'true'; + $enableEncryption = $config->getValueString('groupfolders', 'enable_encryption', 'false') === 'true'; return new MountProvider( $c->get(FolderManager::class), @@ -208,7 +208,7 @@ public function register(IRegistrationContext $context): void { return new ExpireGroupTrashJob( $c->get(TrashBackend::class), $c->get(Expiration::class), - $c->get(IConfig::class), + $c->get(IAppConfig::class), $c->get(ITimeFactory::class) ); } @@ -224,7 +224,7 @@ public function register(IRegistrationContext $context): void { return new ACLManagerFactory( $c->get(RuleManager::class), $c->get(TrashManager::class), - $c->get(IConfig::class), + $c->get(IAppConfig::class), $c->get(LoggerInterface::class), $rootFolderProvider ); diff --git a/lib/BackgroundJob/ExpireGroupTrash.php b/lib/BackgroundJob/ExpireGroupTrash.php index 4e538b31c..f42b06e2b 100644 --- a/lib/BackgroundJob/ExpireGroupTrash.php +++ b/lib/BackgroundJob/ExpireGroupTrash.php @@ -12,13 +12,13 @@ use OCA\GroupFolders\Trash\TrashBackend; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; -use OCP\IConfig; +use OCP\IAppConfig; class ExpireGroupTrash extends TimedJob { public function __construct( private TrashBackend $trashBackend, private Expiration $expiration, - private IConfig $config, + private IAppConfig $config, ITimeFactory $timeFactory, ) { parent::__construct($timeFactory); @@ -27,7 +27,7 @@ public function __construct( } protected function run(mixed $argument): void { - $backgroundJob = $this->config->getAppValue('files_trashbin', 'background_job_expire_trash', 'yes'); + $backgroundJob = $this->config->getValueString('files_trashbin', 'background_job_expire_trash', 'yes'); if ($backgroundJob === 'no') { return; } From 05c6bcd23d108ae053cae044f2e0699032340c4b Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 19 Sep 2024 11:31:57 +0200 Subject: [PATCH 7/8] refactor(Application): Migrate to typed GroupDeletedEvent event Signed-off-by: provokateurin --- lib/AppInfo/Application.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 26724ebdf..52d556233 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -7,7 +7,6 @@ namespace OCA\GroupFolders\AppInfo; use OC\Files\Node\LazyFolder; -use OC\Group; use OCA\Circles\Events\CircleDestroyedEvent; use OCA\DAV\Connector\Sabre\Principal; use OCA\Files\Event\LoadAdditionalScriptsEvent; @@ -49,10 +48,10 @@ use OCP\Files\IMimeTypeLoader; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; +use OCP\Group\Events\GroupDeletedEvent; use OCP\IAppConfig; use OCP\ICacheFactory; use OCP\IDBConnection; -use OCP\IGroup; use OCP\IRequest; use OCP\IUserManager; use OCP\IUserSession; @@ -236,11 +235,11 @@ public function register(IRegistrationContext $context): void { } public function boot(IBootContext $context): void { - $context->injectFn(function (IMountProviderCollection $mountProviderCollection, CacheListener $cacheListener, Group\Manager $groupManager): void { + $context->injectFn(function (IMountProviderCollection $mountProviderCollection, CacheListener $cacheListener, IEventDispatcher $eventDispatcher): void { $mountProviderCollection->registerProvider(Server::get(MountProvider::class)); - $groupManager->listen('\OC\Group', 'postDelete', function (IGroup $group): void { - Server::get(FolderManager::class)->deleteGroup($group->getGID()); + $eventDispatcher->addListener(GroupDeletedEvent::class, function (GroupDeletedEvent $event): void { + Server::get(FolderManager::class)->deleteGroup($event->getGroup()->getGID()); }); $cacheListener->listen(); }); From 950d0ecfa27c0c96656e98e5f67bff90c35861da Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 19 Sep 2024 11:33:42 +0200 Subject: [PATCH 8/8] build(psalm): Forbid using deprecated code Signed-off-by: provokateurin --- psalm.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/psalm.xml b/psalm.xml index e388246ff..20f52ff37 100644 --- a/psalm.xml +++ b/psalm.xml @@ -127,5 +127,12 @@ + + + + + + +