From a6bf93501deb1d2d01535e586388aeb5e6ee93f5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Jul 2023 11:27:29 +0200 Subject: [PATCH 1/3] fix(files_trashbin): Migrate to IEventDispatcher and emit as typed event Signed-off-by: Joas Schilling --- apps/files_trashbin/lib/Events/MoveToTrashEvent.php | 1 + apps/files_trashbin/lib/Storage.php | 11 ++++++----- apps/files_trashbin/tests/StorageTest.php | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/files_trashbin/lib/Events/MoveToTrashEvent.php b/apps/files_trashbin/lib/Events/MoveToTrashEvent.php index 3dce70f96bdd8..c07d7822e3acb 100644 --- a/apps/files_trashbin/lib/Events/MoveToTrashEvent.php +++ b/apps/files_trashbin/lib/Events/MoveToTrashEvent.php @@ -33,6 +33,7 @@ * Event to allow other apps to disable the trash bin for specific files * * @package OCA\Files_Trashbin\Events + * @since 28.0.0 Dispatched as a typed event */ class MoveToTrashEvent extends Event { diff --git a/apps/files_trashbin/lib/Storage.php b/apps/files_trashbin/lib/Storage.php index f08d8d25a55a9..68d0951b6947c 100644 --- a/apps/files_trashbin/lib/Storage.php +++ b/apps/files_trashbin/lib/Storage.php @@ -33,13 +33,13 @@ use OCA\Files_Trashbin\Events\MoveToTrashEvent; use OCA\Files_Trashbin\Trash\ITrashManager; use OCP\Encryption\Exceptions\GenericEncryptionException; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\Node; use OCP\Files\Storage\IStorage; use OCP\ILogger; use OCP\IUserManager; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; class Storage extends Wrapper { /** @var IMountPoint */ @@ -51,7 +51,7 @@ class Storage extends Wrapper { /** @var ILogger */ private $logger; - /** @var EventDispatcherInterface */ + /** @var IEventDispatcher */ private $eventDispatcher; /** @var IRootFolder */ @@ -69,7 +69,7 @@ class Storage extends Wrapper { * @param ITrashManager $trashManager * @param IUserManager|null $userManager * @param ILogger|null $logger - * @param EventDispatcherInterface|null $eventDispatcher + * @param IEventDispatcher|null $eventDispatcher * @param IRootFolder|null $rootFolder */ public function __construct( @@ -77,7 +77,7 @@ public function __construct( ITrashManager $trashManager = null, IUserManager $userManager = null, ILogger $logger = null, - EventDispatcherInterface $eventDispatcher = null, + IEventDispatcher $eventDispatcher = null, IRootFolder $rootFolder = null ) { $this->mountPoint = $parameters['mountPoint']; @@ -153,6 +153,7 @@ protected function shouldMoveToTrash($path) { foreach ($nodes as $node) { $event = $this->createMoveToTrashEvent($node); + $this->eventDispatcher->dispatchTyped($event); $this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event); if ($event->shouldMoveToTrashBin() === false) { return false; @@ -217,7 +218,7 @@ public static function setupStorage() { \OC::$server->query(ITrashManager::class), \OC::$server->getUserManager(), \OC::$server->getLogger(), - \OC::$server->getEventDispatcher(), + \OC::$server->get(IEventDispatcher::class), \OC::$server->getLazyRootFolder() ); }, 1); diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index 15b47385d4554..b4b995c3ae590 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -41,6 +41,7 @@ use OCA\Files_Trashbin\Trash\ITrashManager; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICache; use OCP\Files\Folder; use OCP\Files\IRootFolder; @@ -50,7 +51,6 @@ use OCP\IUserManager; use OCP\Lock\ILockingProvider; use OCP\Share\IShare; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\Traits\MountProviderTrait; class TemporaryNoCross extends Temporary { @@ -607,7 +607,7 @@ public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisab $userManager->expects($this->any()) ->method('userExists')->willReturn($userExists); $logger = $this->getMockBuilder(ILogger::class)->getMock(); - $eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $eventDispatcher = $this->createMock(IEventDispatcher::class); $rootFolder = $this->createMock(IRootFolder::class); $userFolder = $this->createMock(Folder::class); $node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock(); From 4877d0b62e1be0a3b726c901e9a1f986fa1a11c5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Jul 2023 11:28:02 +0200 Subject: [PATCH 2/3] fix(loopup_server_connector): Migrate to IEventDispatcher Signed-off-by: Joas Schilling --- .../lib/AppInfo/Application.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/lookup_server_connector/lib/AppInfo/Application.php b/apps/lookup_server_connector/lib/AppInfo/Application.php index edc2757c0a6c1..8d6700c0eaad8 100644 --- a/apps/lookup_server_connector/lib/AppInfo/Application.php +++ b/apps/lookup_server_connector/lib/AppInfo/Application.php @@ -34,9 +34,9 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IUser; use Psr\Container\ContainerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; class Application extends App implements IBootstrap { @@ -56,15 +56,17 @@ public function boot(IBootContext $context): void { /** * @todo move the OCP events and then move the registration to `register` */ - private function registerEventListeners(EventDispatcherInterface $dispatcher, + private function registerEventListeners(IEventDispatcher $dispatcher, ContainerInterface $appContainer): void { - $dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($appContainer) { - /** @var IUser $user */ - $user = $event->getSubject(); + $dispatcher->addListener('OC\AccountManager::userUpdated', function ($event) use ($appContainer) { + if ($event instanceof GenericEvent) { + /** @var IUser $user */ + $user = $event->getSubject(); - /** @var UpdateLookupServer $updateLookupServer */ - $updateLookupServer = $appContainer->get(UpdateLookupServer::class); - $updateLookupServer->userUpdated($user); + /** @var UpdateLookupServer $updateLookupServer */ + $updateLookupServer = $appContainer->get(UpdateLookupServer::class); + $updateLookupServer->userUpdated($user); + } }); } } From aa039c986a3e8aaa97569d65ff1afd47a9b94a53 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Jul 2023 11:30:58 +0200 Subject: [PATCH 3/3] fix(workflowengine): Remove legacy event (deprecated since 17) Signed-off-by: Joas Schilling --- apps/workflowengine/lib/Manager.php | 10 ---------- apps/workflowengine/tests/ManagerTest.php | 12 ++++-------- lib/public/WorkflowEngine/IManager.php | 15 --------------- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php index 674cfc653136a..7d55cff446ee6 100644 --- a/apps/workflowengine/lib/Manager.php +++ b/apps/workflowengine/lib/Manager.php @@ -66,8 +66,6 @@ use OCP\WorkflowEngine\IManager; use OCP\WorkflowEngine\IOperation; use OCP\WorkflowEngine\IRuleMatcher; -use Symfony\Component\EventDispatcher\EventDispatcherInterface as LegacyDispatcher; -use Symfony\Component\EventDispatcher\GenericEvent; class Manager implements IManager { /** @var IStorage */ @@ -94,9 +92,6 @@ class Manager implements IManager { /** @var IL10N */ protected $l; - /** @var LegacyDispatcher */ - protected $legacyEventDispatcher; - /** @var IEntity[] */ protected $registeredEntities = []; @@ -126,7 +121,6 @@ public function __construct( IDBConnection $connection, IServerContainer $container, IL10N $l, - LegacyDispatcher $eventDispatcher, ILogger $logger, IUserSession $session, IEventDispatcher $dispatcher, @@ -136,7 +130,6 @@ public function __construct( $this->connection = $connection; $this->container = $container; $this->l = $l; - $this->legacyEventDispatcher = $eventDispatcher; $this->logger = $logger; $this->operationsByScope = new CappedMemoryCache(64); $this->session = $session; @@ -694,7 +687,6 @@ public function formatOperation(array $operation): array { */ public function getEntitiesList(): array { $this->dispatcher->dispatchTyped(new RegisterEntitiesEvent($this)); - $this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_ENTITY, new GenericEvent($this)); return array_values(array_merge($this->getBuildInEntities(), $this->registeredEntities)); } @@ -704,7 +696,6 @@ public function getEntitiesList(): array { */ public function getOperatorList(): array { $this->dispatcher->dispatchTyped(new RegisterOperationsEvent($this)); - $this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_OPERATION, new GenericEvent($this)); return array_merge($this->getBuildInOperators(), $this->registeredOperators); } @@ -714,7 +705,6 @@ public function getOperatorList(): array { */ public function getCheckList(): array { $this->dispatcher->dispatchTyped(new RegisterChecksEvent($this)); - $this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_CHECK, new GenericEvent($this)); return array_merge($this->getBuildInChecks(), $this->registeredChecks); } diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php index 543b4550ca6aa..dee6b50845439 100644 --- a/apps/workflowengine/tests/ManagerTest.php +++ b/apps/workflowengine/tests/ManagerTest.php @@ -45,6 +45,7 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\SystemTag\ISystemTagManager; +use OCP\WorkflowEngine\Events\RegisterEntitiesEvent; use OCP\WorkflowEngine\ICheck; use OCP\WorkflowEngine\IEntity; use OCP\WorkflowEngine\IEntityEvent; @@ -67,8 +68,6 @@ class ManagerTest extends TestCase { protected $db; /** @var \PHPUnit\Framework\MockObject\MockObject|ILogger */ protected $logger; - /** @var \PHPUnit\Framework\MockObject\MockObject|EventDispatcherInterface */ - protected $legacyDispatcher; /** @var MockObject|IServerContainer */ protected $container; /** @var MockObject|IUserSession */ @@ -94,7 +93,6 @@ protected function setUp(): void { return vsprintf($text, $parameters); }); - $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class); $this->logger = $this->createMock(ILogger::class); $this->session = $this->createMock(IUserSession::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); @@ -105,7 +103,6 @@ protected function setUp(): void { \OC::$server->getDatabaseConnection(), $this->container, $this->l, - $this->legacyDispatcher, $this->logger, $this->session, $this->dispatcher, @@ -532,10 +529,9 @@ public function testGetEntitiesList() { /** @var MockObject|IEntity $extraEntity */ $extraEntity = $this->createMock(IEntity::class); - $this->legacyDispatcher->expects($this->once()) - ->method('dispatch') - ->with('OCP\WorkflowEngine::registerEntities', $this->anything()) - ->willReturnCallback(function () use ($extraEntity) { + $this->dispatcher->expects($this->once()) + ->method('dispatchTyped') + ->willReturnCallback(function (RegisterEntitiesEvent $e) use ($extraEntity) { $this->manager->registerEntity($extraEntity); }); diff --git a/lib/public/WorkflowEngine/IManager.php b/lib/public/WorkflowEngine/IManager.php index f09d51eb15923..abdcdfa107a32 100644 --- a/lib/public/WorkflowEngine/IManager.php +++ b/lib/public/WorkflowEngine/IManager.php @@ -44,21 +44,6 @@ interface IManager { */ public const MAX_OPERATION_VALUE_BYTES = 4096; - /** - * @deprecated 17.0.0 Will be removed in NC19. Use the dedicated events in OCP\WorkflowEngine\Events - */ - public const EVENT_NAME_REG_OPERATION = 'OCP\WorkflowEngine::registerOperations'; - - /** - * @deprecated 17.0.0 - */ - public const EVENT_NAME_REG_ENTITY = 'OCP\WorkflowEngine::registerEntities'; - - /** - * @deprecated 17.0.0 - */ - public const EVENT_NAME_REG_CHECK = 'OCP\WorkflowEngine::registerChecks'; - /** * Listen to `OCP\WorkflowEngine\Events\RegisterEntitiesEvent` at the * IEventDispatcher for registering your entities.