diff --git a/lib/private/Files/Node/HookConnector.php b/lib/private/Files/Node/HookConnector.php index c61e098c22771..a8e76d95c22c4 100644 --- a/lib/private/Files/Node/HookConnector.php +++ b/lib/private/Files/Node/HookConnector.php @@ -46,7 +46,6 @@ use OCP\Files\FileInfo; use OCP\Files\IRootFolder; use OCP\Util; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; class HookConnector { /** @var IRootFolder */ @@ -58,26 +57,15 @@ class HookConnector { /** @var FileInfo[] */ private $deleteMetaCache = []; - /** @var EventDispatcherInterface */ - private $legacyDispatcher; - /** @var IEventDispatcher */ private $dispatcher; - /** - * HookConnector constructor. - * - * @param Root $root - * @param View $view - */ public function __construct( IRootFolder $root, View $view, - EventDispatcherInterface $legacyDispatcher, IEventDispatcher $dispatcher) { $this->root = $root; $this->view = $view; - $this->legacyDispatcher = $legacyDispatcher; $this->dispatcher = $dispatcher; } @@ -106,7 +94,7 @@ public function viewToNode() { public function write($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'preWrite', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::preWrite', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::preWrite', new GenericEvent($node)); $event = new BeforeNodeWrittenEvent($node); $this->dispatcher->dispatchTyped($event); @@ -115,7 +103,7 @@ public function write($arguments) { public function postWrite($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'postWrite', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::postWrite', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::postWrite', new GenericEvent($node)); $event = new NodeWrittenEvent($node); $this->dispatcher->dispatchTyped($event); @@ -124,7 +112,7 @@ public function postWrite($arguments) { public function create($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'preCreate', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::preCreate', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::preCreate', new GenericEvent($node)); $event = new BeforeNodeCreatedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -133,7 +121,7 @@ public function create($arguments) { public function postCreate($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'postCreate', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::postCreate', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::postCreate', new GenericEvent($node)); $event = new NodeCreatedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -143,7 +131,7 @@ public function delete($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->deleteMetaCache[$node->getPath()] = $node->getFileInfo(); $this->root->emit('\OC\Files', 'preDelete', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::preDelete', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::preDelete', new GenericEvent($node)); $event = new BeforeNodeDeletedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -153,7 +141,7 @@ public function postDelete($arguments) { $node = $this->getNodeForPath($arguments['path']); unset($this->deleteMetaCache[$node->getPath()]); $this->root->emit('\OC\Files', 'postDelete', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::postDelete', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::postDelete', new GenericEvent($node)); $event = new NodeDeletedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -162,7 +150,7 @@ public function postDelete($arguments) { public function touch($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'preTouch', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::preTouch', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::preTouch', new GenericEvent($node)); $event = new BeforeNodeTouchedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -171,7 +159,7 @@ public function touch($arguments) { public function postTouch($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'postTouch', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::postTouch', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::postTouch', new GenericEvent($node)); $event = new NodeTouchedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -181,7 +169,7 @@ public function rename($arguments) { $source = $this->getNodeForPath($arguments['oldpath']); $target = $this->getNodeForPath($arguments['newpath']); $this->root->emit('\OC\Files', 'preRename', [$source, $target]); - $this->legacyDispatcher->dispatch('\OCP\Files::preRename', new GenericEvent([$source, $target])); + $this->dispatcher->dispatch('\OCP\Files::preRename', new GenericEvent([$source, $target])); $event = new BeforeNodeRenamedEvent($source, $target); $this->dispatcher->dispatchTyped($event); @@ -191,7 +179,7 @@ public function postRename($arguments) { $source = $this->getNodeForPath($arguments['oldpath']); $target = $this->getNodeForPath($arguments['newpath']); $this->root->emit('\OC\Files', 'postRename', [$source, $target]); - $this->legacyDispatcher->dispatch('\OCP\Files::postRename', new GenericEvent([$source, $target])); + $this->dispatcher->dispatch('\OCP\Files::postRename', new GenericEvent([$source, $target])); $event = new NodeRenamedEvent($source, $target); $this->dispatcher->dispatchTyped($event); @@ -201,7 +189,7 @@ public function copy($arguments) { $source = $this->getNodeForPath($arguments['oldpath']); $target = $this->getNodeForPath($arguments['newpath']); $this->root->emit('\OC\Files', 'preCopy', [$source, $target]); - $this->legacyDispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target])); + $this->dispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target])); $event = new BeforeNodeCopiedEvent($source, $target); $this->dispatcher->dispatchTyped($event); @@ -211,7 +199,7 @@ public function postCopy($arguments) { $source = $this->getNodeForPath($arguments['oldpath']); $target = $this->getNodeForPath($arguments['newpath']); $this->root->emit('\OC\Files', 'postCopy', [$source, $target]); - $this->legacyDispatcher->dispatch('\OCP\Files::postCopy', new GenericEvent([$source, $target])); + $this->dispatcher->dispatch('\OCP\Files::postCopy', new GenericEvent([$source, $target])); $event = new NodeCopiedEvent($source, $target); $this->dispatcher->dispatchTyped($event); @@ -220,7 +208,7 @@ public function postCopy($arguments) { public function read($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'read', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::read', new GenericEvent([$node])); + $this->dispatcher->dispatch('\OCP\Files::read', new GenericEvent([$node])); $event = new BeforeNodeReadEvent($node); $this->dispatcher->dispatchTyped($event); diff --git a/lib/private/Server.php b/lib/private/Server.php index 520c1f1d249e3..86f5192a39df9 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -465,7 +465,6 @@ public function __construct($webRoot, \OC\Config $config) { return new HookConnector( $c->get(IRootFolder::class), new View(), - $c->get(\OC\EventDispatcher\SymfonyAdapter::class), $c->get(IEventDispatcher::class) ); }); diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php index 9704c7b89f120..0501c175a5f6a 100644 --- a/tests/lib/Files/Node/HookConnectorTest.php +++ b/tests/lib/Files/Node/HookConnectorTest.php @@ -31,9 +31,7 @@ use OCP\Files\Events\Node\NodeWrittenEvent; use OCP\Files\Node; use OCP\IUserManager; -use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; use Test\TestCase; use Test\Traits\MountProviderTrait; @@ -50,9 +48,6 @@ class HookConnectorTest extends TestCase { use UserTrait; use MountProviderTrait; - /** @var EventDispatcherInterface|MockObject */ - protected $legacyDispatcher; - /** @var IEventDispatcher */ protected $eventDispatcher; @@ -82,7 +77,6 @@ protected function setUp(): void { $this->createMock(IUserManager::class), $this->createMock(IEventDispatcher::class) ); - $this->legacyDispatcher = \OC::$server->getEventDispatcher(); $this->eventDispatcher = \OC::$server->query(IEventDispatcher::class); } @@ -149,7 +143,7 @@ public function viewToNodeProvider() { * @dataProvider viewToNodeProvider */ public function testViewToNode(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent) { - $connector = new HookConnector($this->root, $this->view, $this->legacyDispatcher, $this->eventDispatcher); + $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookNode */ @@ -163,7 +157,7 @@ public function testViewToNode(callable $operation, $expectedHook, $expectedLega $dispatcherCalled = false; /** @var Node $dispatcherNode */ $dispatcherNode = null; - $this->legacyDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherCalled, &$dispatcherNode) { + $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherCalled, &$dispatcherNode) { /** @var GenericEvent|APIGenericEvent $event */ $dispatcherCalled = true; $dispatcherNode = $event->getSubject(); @@ -218,7 +212,7 @@ public function viewToNodeProviderCopyRename() { * @dataProvider viewToNodeProviderCopyRename */ public function testViewToNodeCopyRename(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent) { - $connector = new HookConnector($this->root, $this->view, $this->legacyDispatcher, $this->eventDispatcher); + $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookSourceNode */ @@ -237,7 +231,7 @@ public function testViewToNodeCopyRename(callable $operation, $expectedHook, $ex $dispatcherSourceNode = null; /** @var Node $dispatcherTargetNode */ $dispatcherTargetNode = null; - $this->legacyDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled) { + $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled) { /** @var GenericEvent|APIGenericEvent $event */ $dispatcherCalled = true; [$dispatcherSourceNode, $dispatcherTargetNode] = $event->getSubject(); @@ -273,7 +267,7 @@ public function testViewToNodeCopyRename(callable $operation, $expectedHook, $ex } public function testPostDeleteMeta() { - $connector = new HookConnector($this->root, $this->view, $this->legacyDispatcher, $this->eventDispatcher); + $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookNode */ @@ -287,7 +281,7 @@ public function testPostDeleteMeta() { $dispatcherCalled = false; /** @var Node $dispatcherNode */ $dispatcherNode = null; - $this->legacyDispatcher->addListener('\OCP\Files::postDelete', function ($event) use (&$dispatcherCalled, &$dispatcherNode) { + $this->eventDispatcher->addListener('\OCP\Files::postDelete', function ($event) use (&$dispatcherCalled, &$dispatcherNode) { /** @var GenericEvent|APIGenericEvent $event */ $dispatcherCalled = true; $dispatcherNode = $event->getSubject();