Skip to content

Commit

Permalink
Merge pull request #39605 from nextcloud/bugfix/noid/final-events-cle…
Browse files Browse the repository at this point in the history
…anup

fix!: Final round of moving to IEventDispatcher
  • Loading branch information
nickvergessen authored Aug 4, 2023
2 parents f8bd676 + 3962cd0 commit 44b4c16
Show file tree
Hide file tree
Showing 43 changed files with 709 additions and 956 deletions.
12 changes: 5 additions & 7 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
use OCA\DAV\Events\CardUpdatedEvent;
use OCA\DAV\Events\SubscriptionCreatedEvent;
use OCA\DAV\Events\SubscriptionDeletedEvent;
use OCP\Accounts\UserUpdatedEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\Events\TrustedServerRemovedEvent;
use OCA\DAV\HookManager;
Expand Down Expand Up @@ -224,13 +225,10 @@ public function registerHooks(HookManager $hm,
}
});

$dispatcher->addListener('OC\AccountManager::userUpdated', function ($event) use ($container) {
if ($event instanceof GenericEvent) {
$user = $event->getSubject();
/** @var SyncService $syncService */
$syncService = $container->query(SyncService::class);
$syncService->updateUser($user);
}
$dispatcher->addListener(UserUpdatedEvent::class, function (UserUpdatedEvent $event) use ($container) {
/** @var SyncService $syncService */
$syncService = \OCP\Server::get(SyncService::class);
$syncService->updateUser($event->getUser());
});


Expand Down
1 change: 0 additions & 1 deletion apps/files/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
'OCA\\Files\\Event\\LoadSidebar' => $baseDir . '/../lib/Event/LoadSidebar.php',
'OCA\\Files\\Exception\\TransferOwnershipException' => $baseDir . '/../lib/Exception/TransferOwnershipException.php',
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Listener\\RenderReferenceEventListener' => $baseDir . '/../lib/Listener/RenderReferenceEventListener.php',
'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php',
Expand Down
1 change: 0 additions & 1 deletion apps/files/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class ComposerStaticInitFiles
'OCA\\Files\\Event\\LoadSidebar' => __DIR__ . '/..' . '/../lib/Event/LoadSidebar.php',
'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__ . '/..' . '/../lib/Exception/TransferOwnershipException.php',
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Listener\\RenderReferenceEventListener' => __DIR__ . '/..' . '/../lib/Listener/RenderReferenceEventListener.php',
'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php',
Expand Down
5 changes: 2 additions & 3 deletions apps/files/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
use OCA\Files\DirectEditingCapabilities;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
use OCA\Files\Listener\LoadSidebarListener;
use OCA\Files\Listener\RenderReferenceEventListener;
use OCA\Files\Notification\Notifier;
Expand All @@ -57,6 +56,7 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\Collaboration\Resources\IProviderManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IPreview;
Expand Down Expand Up @@ -110,7 +110,7 @@ public function register(IRegistrationContext $context): void {
$c->get(IActivityManager::class),
$c->get(ITagManager::class)->load(self::APP_ID),
$server->getUserFolder(),
$server->getEventDispatcher()
$c->get(IEventDispatcher::class),
);
});

Expand All @@ -120,7 +120,6 @@ public function register(IRegistrationContext $context): void {
$context->registerCapability(Capabilities::class);
$context->registerCapability(DirectEditingCapabilities::class);

$context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
$context->registerEventListener(RenderReferenceEvent::class, RenderReferenceEventListener::class);

Expand Down
9 changes: 6 additions & 3 deletions apps/files/lib/Collaboration/Resources/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Server;
use OCP\Collaboration\Resources\IManager;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\Events\ShareDeletedEvent;
use OCP\Share\Events\ShareDeletedFromSelfEvent;

class Listener {
public static function register(IEventDispatcher $dispatcher): void {
$dispatcher->addListener('OCP\Share::postShare', [self::class, 'shareModification']);
$dispatcher->addListener('OCP\Share::postUnshare', [self::class, 'shareModification']);
$dispatcher->addListener('OCP\Share::postUnshareFromSelf', [self::class, 'shareModification']);
$dispatcher->addListener(ShareCreatedEvent::class, [self::class, 'shareModification']);
$dispatcher->addListener(ShareDeletedEvent::class, [self::class, 'shareModification']);
$dispatcher->addListener(ShareDeletedFromSelfEvent::class, [self::class, 'shareModification']);
}

public static function shareModification(): void {
Expand Down
57 changes: 0 additions & 57 deletions apps/files/lib/Listener/LegacyLoadAdditionalScriptsAdapter.php

This file was deleted.

21 changes: 11 additions & 10 deletions apps/files/lib/Service/TagService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@

use OCA\Files\Activity\FavoriteProvider;
use OCP\Activity\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\NodeAddedToFavorite;
use OCP\Files\Events\NodeRemovedFromFavorite;
use OCP\Files\Folder;
use OCP\ITags;
use OCP\IUser;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* Service class to manage tags on files.
Expand All @@ -46,15 +47,15 @@ class TagService {
private $tagger;
/** @var Folder|null */
private $homeFolder;
/** @var EventDispatcherInterface */
/** @var IEventDispatcher */
private $dispatcher;

public function __construct(
IUserSession $userSession,
IManager $activityManager,
?ITags $tagger,
?Folder $homeFolder,
EventDispatcherInterface $dispatcher
IEventDispatcher $dispatcher,
) {
$this->userSession = $userSession;
$this->activityManager = $activityManager;
Expand Down Expand Up @@ -120,12 +121,12 @@ protected function addActivity($addToFavorite, $fileId, $path) {
return;
}

$eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite';
$this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [
'userId' => $user->getUID(),
'fileId' => $fileId,
'path' => $path,
]));
if ($addToFavorite) {
$event = new NodeAddedToFavorite($user, $fileId, $path);
} else {
$event = new NodeRemovedFromFavorite($user, $fileId, $path);
}
$this->dispatcher->dispatchTyped($event);

$event = $this->activityManager->generateEvent();
try {
Expand Down
6 changes: 3 additions & 3 deletions apps/files/tests/Service/TagServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@

use OCA\Files\Service\TagService;
use OCP\Activity\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ITags;
use OCP\IUser;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Class TagServiceTest
Expand All @@ -59,7 +59,7 @@ class TagServiceTest extends \Test\TestCase {
*/
private $root;

/** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
private $dispatcher;

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ protected function setUp(): void {
->willReturn($user);

$this->root = \OC::$server->getUserFolder();
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);

$this->tagger = \OC::$server->getTagManager()->load('files');
$this->tagService = $this->getTagService(['addActivity']);
Expand Down
3 changes: 2 additions & 1 deletion apps/files_external/lib/Service/BackendService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCA\Files_External\Lib\Config\IAuthMechanismProvider;
use OCA\Files_External\Lib\Config\IBackendProvider;
use OCP\EventDispatcher\GenericEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;

/**
Expand Down Expand Up @@ -112,7 +113,7 @@ public function registerBackendProvider(IBackendProvider $provider) {
private function callForRegistrations() {
static $eventSent = false;
if (!$eventSent) {
\OC::$server->getEventDispatcher()->dispatch(
\OC::$server->get(IEventDispatcher::class)->dispatch(
'OCA\\Files_External::loadAdditionalBackends',
new GenericEvent()
);
Expand Down
1 change: 0 additions & 1 deletion apps/files_sharing/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
'OCA\\Files_Sharing\\Helper' => $baseDir . '/../lib/Helper.php',
'OCA\\Files_Sharing\\Hooks' => $baseDir . '/../lib/Hooks.php',
'OCA\\Files_Sharing\\ISharedStorage' => $baseDir . '/../lib/ISharedStorage.php',
'OCA\\Files_Sharing\\Listener\\LegacyBeforeTemplateRenderedListener' => $baseDir . '/../lib/Listener/LegacyBeforeTemplateRenderedListener.php',
'OCA\\Files_Sharing\\Listener\\LoadAdditionalListener' => $baseDir . '/../lib/Listener/LoadAdditionalListener.php',
'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files_Sharing\\Listener\\ShareInteractionListener' => $baseDir . '/../lib/Listener/ShareInteractionListener.php',
Expand Down
1 change: 0 additions & 1 deletion apps/files_sharing/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class ComposerStaticInitFiles_Sharing
'OCA\\Files_Sharing\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
'OCA\\Files_Sharing\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php',
'OCA\\Files_Sharing\\ISharedStorage' => __DIR__ . '/..' . '/../lib/ISharedStorage.php',
'OCA\\Files_Sharing\\Listener\\LegacyBeforeTemplateRenderedListener' => __DIR__ . '/..' . '/../lib/Listener/LegacyBeforeTemplateRenderedListener.php',
'OCA\\Files_Sharing\\Listener\\LoadAdditionalListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalListener.php',
'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files_Sharing\\Listener\\ShareInteractionListener' => __DIR__ . '/..' . '/../lib/Listener/ShareInteractionListener.php',
Expand Down
7 changes: 1 addition & 6 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use OCA\Files_Sharing\External\Manager;
use OCA\Files_Sharing\External\MountProvider as ExternalMountProvider;
use OCA\Files_Sharing\Helper;
use OCA\Files_Sharing\Listener\LegacyBeforeTemplateRenderedListener;
use OCA\Files_Sharing\Listener\LoadAdditionalListener;
use OCA\Files_Sharing\Listener\LoadSidebarListener;
use OCA\Files_Sharing\Listener\ShareInteractionListener;
Expand Down Expand Up @@ -133,7 +132,6 @@ public function registerMountProviders(IMountProviderCollection $mountProviderCo
public function registerEventsScripts(IEventDispatcher $dispatcher): void {
// sidebar and files scripts
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
$dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class);
$dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class);
$dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class);
$dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class);
Expand All @@ -143,10 +141,7 @@ public function registerEventsScripts(IEventDispatcher $dispatcher): void {
});

// notifications api to accept incoming user shares
$dispatcher->addListener('OCP\Share::postShare', function ($event) {
if (!$event instanceof OldGenericEvent) {
return;
}
$dispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
/** @var Listener $listener */
$listener = $this->getContainer()->query(Listener::class);
$listener->shareNotification($event);
Expand Down

This file was deleted.

9 changes: 3 additions & 6 deletions apps/files_sharing/lib/Notification/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\IUser;
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\GenericEvent;
Expand All @@ -54,12 +55,8 @@ public function __construct(
$this->groupManager = $groupManager;
}

/**
* @param GenericEvent $event
*/
public function shareNotification(GenericEvent $event): void {
/** @var IShare $share */
$share = $event->getSubject();
public function shareNotification(ShareCreatedEvent $event): void {
$share = $event->getShare();
$notification = $this->instantiateNotification($share);

if ($share->getShareType() === IShare::TYPE_USER) {
Expand Down
2 changes: 0 additions & 2 deletions apps/files_sharing/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
use OCP\Security\ISecureRandom;
use OCP\Share\IProviderFactory;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Class CapabilitiesTest
Expand Down Expand Up @@ -90,7 +89,6 @@ private function getResults(array $map) {
$this->createMock(IProviderFactory::class),
$this->createMock(IUserManager::class),
$this->createMock(IRootFolder::class),
$this->createMock(EventDispatcherInterface::class),
$this->createMock(IMailer::class),
$this->createMock(IURLGenerator::class),
$this->createMock(\OC_Defaults::class),
Expand Down
Loading

0 comments on commit 44b4c16

Please sign in to comment.