diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Accounts/AccountManager.php | 14 | ||||
-rw-r--r-- | lib/private/Collaboration/Resources/Listener.php | 50 | ||||
-rw-r--r-- | lib/private/EventDispatcher/GenericEventWrapper.php | 124 | ||||
-rw-r--r-- | lib/private/EventDispatcher/SymfonyAdapter.php | 208 | ||||
-rw-r--r-- | lib/private/Files/Node/Node.php | 6 | ||||
-rw-r--r-- | lib/private/Server.php | 17 | ||||
-rw-r--r-- | lib/private/Share20/LegacyHooks.php | 73 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 51 | ||||
-rw-r--r-- | lib/private/User/Session.php | 6 | ||||
-rw-r--r-- | lib/private/legacy/OC_App.php | 2 |
10 files changed, 80 insertions, 471 deletions
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 43d18a0d941..95199d8380c 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -41,6 +41,7 @@ use libphonenumber\NumberParseException; use libphonenumber\PhoneNumberFormat; use libphonenumber\PhoneNumberUtil; use OC\Profile\TProfileHelper; +use OCP\Accounts\UserUpdatedEvent; use OCP\Cache\CappedMemoryCache; use OCA\Settings\BackgroundJobs\VerifyUserData; use OCP\Accounts\IAccount; @@ -51,6 +52,7 @@ use OCP\Accounts\PropertyDoesNotExistException; use OCP\BackgroundJob\IJobList; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Defaults; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IDBConnection; use OCP\IL10N; @@ -62,8 +64,6 @@ use OCP\Security\ICrypto; use OCP\Security\VerificationToken\IVerificationToken; use OCP\Util; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; use function array_flip; use function iterator_to_array; use function json_decode; @@ -109,7 +109,7 @@ class AccountManager implements IAccountManager { public function __construct( private IDBConnection $connection, private IConfig $config, - private EventDispatcherInterface $eventDispatcher, + private IEventDispatcher $dispatcher, private IJobList $jobList, private LoggerInterface $logger, private IVerificationToken $verificationToken, @@ -255,10 +255,10 @@ class AccountManager implements IAccountManager { } if ($updated) { - $this->eventDispatcher->dispatch( - 'OC\AccountManager::userUpdated', - new GenericEvent($user, $data) - ); + $this->dispatcher->dispatchTyped(new UserUpdatedEvent( + $user, + $data, + )); } return $data; diff --git a/lib/private/Collaboration/Resources/Listener.php b/lib/private/Collaboration/Resources/Listener.php index 2263f5d3b1a..4330f3570bc 100644 --- a/lib/private/Collaboration/Resources/Listener.php +++ b/lib/private/Collaboration/Resources/Listener.php @@ -26,27 +26,29 @@ declare(strict_types=1); */ namespace OC\Collaboration\Resources; -use OC\EventDispatcher\SymfonyAdapter; use OCP\Collaboration\Resources\IManager; -use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent; use OCP\EventDispatcher\IEventDispatcher; -use OCP\IGroup; -use OCP\IUser; +use OCP\Group\Events\BeforeGroupDeletedEvent; +use OCP\Group\Events\UserAddedEvent; +use OCP\Group\Events\UserRemovedEvent; use OCP\User\Events\UserDeletedEvent; -use Symfony\Component\EventDispatcher\GenericEvent; class Listener { - public static function register(SymfonyAdapter $symfonyDispatcher, IEventDispatcher $eventDispatcher): void { - $listener = function (GenericEvent $event) { - /** @var IUser $user */ - $user = $event->getArgument('user'); + public static function register(IEventDispatcher $eventDispatcher): void { + $eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) { + $user = $event->getUser(); /** @var IManager $resourceManager */ $resourceManager = \OCP\Server::get(IManager::class); $resourceManager->invalidateAccessCacheForUser($user); - }; - $symfonyDispatcher->addListener(IGroup::class . '::postAddUser', $listener); - $symfonyDispatcher->addListener(IGroup::class . '::postRemoveUser', $listener); + }); + $eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) { + $user = $event->getUser(); + /** @var IManager $resourceManager */ + $resourceManager = \OCP\Server::get(IManager::class); + + $resourceManager->invalidateAccessCacheForUser($user); + }); $eventDispatcher->addListener(UserDeletedEvent::class, function (UserDeletedEvent $event) { $user = $event->getUser(); @@ -56,9 +58,8 @@ class Listener { $resourceManager->invalidateAccessCacheForUser($user); }); - $symfonyDispatcher->addListener(IGroup::class . '::preDelete', function (GenericEvent $event) { - /** @var IGroup $group */ - $group = $event->getSubject(); + $eventDispatcher->addListener(BeforeGroupDeletedEvent::class, function (BeforeGroupDeletedEvent $event) { + $group = $event->getGroup(); /** @var IManager $resourceManager */ $resourceManager = \OCP\Server::get(IManager::class); @@ -66,24 +67,5 @@ class Listener { $resourceManager->invalidateAccessCacheForUser($user); } }); - - // Stay backward compatible with the legacy event for now - $fallbackEventRunning = false; - $symfonyDispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () use ($eventDispatcher, &$fallbackEventRunning) { - if ($fallbackEventRunning) { - return; - } - $fallbackEventRunning = true; - $eventDispatcher->dispatchTyped(new LoadAdditionalScriptsEvent()); - $fallbackEventRunning = false; - }); - $eventDispatcher->addListener(LoadAdditionalScriptsEvent::class, static function () use ($symfonyDispatcher, &$fallbackEventRunning) { - if ($fallbackEventRunning) { - return; - } - $fallbackEventRunning = true; - $symfonyDispatcher->dispatch('\OCP\Collaboration\Resources::loadAdditionalScripts'); - $fallbackEventRunning = false; - }); } } diff --git a/lib/private/EventDispatcher/GenericEventWrapper.php b/lib/private/EventDispatcher/GenericEventWrapper.php deleted file mode 100644 index f0807b57a8b..00000000000 --- a/lib/private/EventDispatcher/GenericEventWrapper.php +++ /dev/null @@ -1,124 +0,0 @@ -<?php - -declare(strict_types=1); - -/** - * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -namespace OC\EventDispatcher; - -use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\GenericEvent; - -class GenericEventWrapper extends GenericEvent { - private LoggerInterface $logger; - - /** @var GenericEvent */ - private $event; - - /** @var string */ - private $eventName; - - /** @var bool */ - private $deprecationNoticeLogged = false; - - public function __construct(LoggerInterface $logger, string $eventName, ?GenericEvent $event) { - parent::__construct($eventName); - $this->logger = $logger; - $this->event = $event; - $this->eventName = $eventName; - } - - private function log() { - if ($this->deprecationNoticeLogged) { - return; - } - - $class = ($this->event !== null && is_object($this->event)) ? get_class($this->event) : 'null'; - $this->logger->debug( - 'Deprecated event type for {name}: {class} is used', - [ 'name' => $this->eventName, 'class' => $class] - ); - $this->deprecationNoticeLogged = true; - } - - public function isPropagationStopped(): bool { - $this->log(); - return $this->event->isPropagationStopped(); - } - - public function stopPropagation(): void { - $this->log(); - $this->event->stopPropagation(); - } - - public function getSubject() { - $this->log(); - return $this->event->getSubject(); - } - - public function getArgument($key) { - $this->log(); - return $this->event->getArgument($key); - } - - public function setArgument($key, $value) { - $this->log(); - return $this->event->setArgument($key, $value); - } - - public function getArguments() { - return $this->event->getArguments(); - } - - public function setArguments(array $args = []) { - return $this->event->setArguments($args); - } - - public function hasArgument($key) { - return $this->event->hasArgument($key); - } - - /** - * @return mixed - */ - #[\ReturnTypeWillChange] - public function offsetGet($key) { - return $this->event->offsetGet($key); - } - - public function offsetSet($key, $value): void { - $this->event->offsetSet($key, $value); - } - - public function offsetUnset($key): void { - $this->event->offsetUnset($key); - } - - public function offsetExists($key): bool { - return $this->event->offsetExists($key); - } - - public function getIterator() { - return$this->event->getIterator(); - } -} diff --git a/lib/private/EventDispatcher/SymfonyAdapter.php b/lib/private/EventDispatcher/SymfonyAdapter.php deleted file mode 100644 index 139f444ce44..00000000000 --- a/lib/private/EventDispatcher/SymfonyAdapter.php +++ /dev/null @@ -1,208 +0,0 @@ -<?php - -declare(strict_types=1); - -/** - * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -namespace OC\EventDispatcher; - -use OCP\EventDispatcher\Event; -use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\EventDispatcher\GenericEvent; -use function is_callable; -use function is_object; -use function is_string; - -/** - * @deprecated 20.0.0 use \OCP\EventDispatcher\IEventDispatcher - */ -class SymfonyAdapter implements EventDispatcherInterface { - /** @var EventDispatcher */ - private $eventDispatcher; - private LoggerInterface $logger; - - /** - * @deprecated 20.0.0 - */ - public function __construct(EventDispatcher $eventDispatcher, LoggerInterface $logger) { - $this->eventDispatcher = $eventDispatcher; - $this->logger = $logger; - } - - private static function detectEventAndName($a, $b) { - if (is_object($a) && (is_string($b) || $b === null)) { - // a is the event, the other one is the optional name - return [$a, $b]; - } - if (is_object($b) && (is_string($a) || $a === null)) { - // b is the event, the other one is the optional name - return [$b, $a]; - } - if (is_string($a) && $b === null) { - // a is a payload-less event - return [null, $a]; - } - if (is_string($b) && $a === null) { - // b is a payload-less event - return [null, $b]; - } - - // Anything else we can't detect - return [$a, $b]; - } - - /** - * Dispatches an event to all registered listeners. - * - * @param string $eventName The name of the event to dispatch. The name of - * the event is the name of the method that is - * invoked on listeners. - * @param Event|null $event The event to pass to the event handlers/listeners - * If not supplied, an empty Event instance is created - * - * @return object the emitted event - * @deprecated 20.0.0 - */ - public function dispatch($eventName, $event = null): object { - [$event, $eventName] = self::detectEventAndName($event, $eventName); - - // type hinting is not possible, due to usage of GenericEvent - if ($event instanceof Event && $eventName === null) { - $this->eventDispatcher->dispatchTyped($event); - return $event; - } - if ($event instanceof Event) { - $this->eventDispatcher->dispatch($eventName, $event); - return $event; - } - - if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) { - $newEvent = new GenericEventWrapper($this->logger, $eventName, $event); - } else { - $newEvent = $event; - - // Legacy event - $this->logger->debug( - 'Deprecated event type for {name}: {class}', - ['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null'] - ); - } - - // Event with no payload (object) need special handling - if ($newEvent === null) { - $newEvent = new Event(); - } - - // Flip the argument order for Symfony to prevent a trigger_error - return $this->eventDispatcher->getSymfonyDispatcher()->dispatch($newEvent, $eventName); - } - - /** - * Adds an event listener that listens on the specified events. - * - * @param string $eventName The event to listen on - * @param callable $listener The listener - * @param int $priority The higher this value, the earlier an event - * listener will be triggered in the chain (defaults to 0) - * @deprecated 20.0.0 - */ - public function addListener($eventName, $listener, $priority = 0) { - if (is_callable($listener)) { - $this->eventDispatcher->addListener($eventName, $listener, $priority); - } else { - // Legacy listener - $this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority); - } - } - - /** - * Adds an event subscriber. - * - * The subscriber is asked for all the events it is - * interested in and added as a listener for these events. - * @deprecated 20.0.0 - */ - public function addSubscriber(EventSubscriberInterface $subscriber) { - $this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber); - } - - /** - * Removes an event listener from the specified events. - * - * @param string $eventName The event to remove a listener from - * @param callable $listener The listener to remove - * @deprecated 20.0.0 - */ - public function removeListener($eventName, $listener) { - $this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener); - } - - /** - * @deprecated 20.0.0 - */ - public function removeSubscriber(EventSubscriberInterface $subscriber) { - $this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber); - } - - /** - * Gets the listeners of a specific event or all listeners sorted by descending priority. - * - * @param string|null $eventName The name of the event - * - * @return array The event listeners for the specified event, or all event listeners by event name - * @deprecated 20.0.0 - */ - public function getListeners($eventName = null) { - return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName); - } - - /** - * Gets the listener priority for a specific event. - * - * Returns null if the event or the listener does not exist. - * - * @param string $eventName The name of the event - * @param callable $listener The listener - * - * @return int|null The event listener priority - * @deprecated 20.0.0 - */ - public function getListenerPriority($eventName, $listener) { - return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener); - } - - /** - * Checks whether an event has any registered listeners. - * - * @param string|null $eventName The name of the event - * - * @return bool true if the specified event has any listeners, false otherwise - * @deprecated 20.0.0 - */ - public function hasListeners($eventName = null) { - return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName); - } -} diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index 4ba2c472c67..61ae762638f 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -32,6 +32,8 @@ namespace OC\Files\Node; use OC\Files\Filesystem; use OC\Files\Mount\MoveableMount; use OC\Files\Utils\PathHelper; +use OCP\EventDispatcher\GenericEvent; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\FileInfo; use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; @@ -40,7 +42,6 @@ use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\Lock\LockedException; use OCP\PreConditionNotMetException; -use Symfony\Component\EventDispatcher\GenericEvent; // FIXME: this class really should be abstract class Node implements INode { @@ -127,7 +128,8 @@ class Node implements INode { */ protected function sendHooks($hooks, array $args = null) { $args = !empty($args) ? $args : [$this]; - $dispatcher = \OC::$server->getEventDispatcher(); + /** @var IEventDispatcher $dispatcher */ + $dispatcher = \OC::$server->get(IEventDispatcher::class); foreach ($hooks as $hook) { if (method_exists($this->root, 'emit')) { $this->root->emit('\OC\Files', $hook, $args); diff --git a/lib/private/Server.php b/lib/private/Server.php index 8640fa3e38c..e9966e83cae 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -82,7 +82,6 @@ use OC\DB\Connection; use OC\DB\ConnectionAdapter; use OC\Diagnostics\EventLogger; use OC\Diagnostics\QueryLogger; -use OC\EventDispatcher\SymfonyAdapter; use OC\Federation\CloudFederationFactory; use OC\Federation\CloudFederationProviderManager; use OC\Federation\CloudIdManager; @@ -257,7 +256,6 @@ use OCP\User\Events\UserLoggedOutEvent; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use OCA\Files_External\Service\UserStoragesService; use OCA\Files_External\Service\UserGlobalStoragesService; use OCA\Files_External\Service\GlobalStoragesService; @@ -1181,9 +1179,6 @@ class Server extends ServerContainer implements IServerContainer { ); }); $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); - /** @deprecated 19.0.0 */ - $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); $this->registerService('CryptoWrapper', function (ContainerInterface $c) { // FIXME: Instantiated here due to cyclic dependency @@ -1237,7 +1232,6 @@ class Server extends ServerContainer implements IServerContainer { $factory, $c->get(IUserManager::class), $c->get(IRootFolder::class), - $c->get(SymfonyAdapter::class), $c->get(IMailer::class), $c->get(IURLGenerator::class), $c->get('ThemingDefaults'), @@ -2046,17 +2040,6 @@ class Server extends ServerContainer implements IServerContainer { } /** - * Get the EventDispatcher - * - * @return EventDispatcherInterface - * @since 8.2.0 - * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher - */ - public function getEventDispatcher() { - return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); - } - - /** * Get the Notification Manager * * @return \OCP\Notification\IManager diff --git a/lib/private/Share20/LegacyHooks.php b/lib/private/Share20/LegacyHooks.php index 688b2273384..24d07167fbd 100644 --- a/lib/private/Share20/LegacyHooks.php +++ b/lib/private/Share20/LegacyHooks.php @@ -29,8 +29,12 @@ namespace OC\Share20; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; use OCP\Share; +use OCP\Share\Events\BeforeShareCreatedEvent; +use OCP\Share\Events\BeforeShareDeletedEvent; +use OCP\Share\Events\ShareCreatedEvent; +use OCP\Share\Events\ShareDeletedEvent; +use OCP\Share\Events\ShareDeletedFromSelfEvent; use OCP\Share\IShare; -use Symfony\Component\EventDispatcher\GenericEvent; class LegacyHooks { /** @var IEventDispatcher */ @@ -39,62 +43,41 @@ class LegacyHooks { public function __construct(IEventDispatcher $eventDispatcher) { $this->eventDispatcher = $eventDispatcher; - $this->eventDispatcher->addListener('OCP\Share::preUnshare', function ($event) { - if ($event instanceof GenericEvent) { - $this->preUnshare($event); - } + $this->eventDispatcher->addListener(BeforeShareDeletedEvent::class, function (BeforeShareDeletedEvent $event) { + $this->preUnshare($event); }); - $this->eventDispatcher->addListener('OCP\Share::postUnshare', function ($event) { - if ($event instanceof GenericEvent) { - $this->postUnshare($event); - } + $this->eventDispatcher->addListener(ShareDeletedEvent::class, function (ShareDeletedEvent $event) { + $this->postUnshare($event); }); - $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', function ($event) { - if ($event instanceof GenericEvent) { - $this->postUnshareFromSelf($event); - } + $this->eventDispatcher->addListener(ShareDeletedFromSelfEvent::class, function (ShareDeletedFromSelfEvent $event) { + $this->postUnshareFromSelf($event); }); - $this->eventDispatcher->addListener('OCP\Share::preShare', function ($event) { - if ($event instanceof GenericEvent) { - $this->preShare($event); - } + $this->eventDispatcher->addListener(BeforeShareCreatedEvent::class, function (BeforeShareCreatedEvent $event) { + $this->preShare($event); }); - $this->eventDispatcher->addListener('OCP\Share::postShare', function ($event) { - if ($event instanceof GenericEvent) { - $this->postShare($event); - } + $this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) { + $this->postShare($event); }); } - public function preUnshare(GenericEvent $e) { - /** @var IShare $share */ - $share = $e->getSubject(); + public function preUnshare(BeforeShareDeletedEvent $e) { + $share = $e->getShare(); $formatted = $this->formatHookParams($share); \OC_Hook::emit(Share::class, 'pre_unshare', $formatted); } - public function postUnshare(GenericEvent $e) { - /** @var IShare $share */ - $share = $e->getSubject(); + public function postUnshare(ShareDeletedEvent $e) { + $share = $e->getShare(); $formatted = $this->formatHookParams($share); - - /** @var IShare[] $deletedShares */ - $deletedShares = $e->getArgument('deletedShares'); - - $formattedDeletedShares = array_map(function ($share) { - return $this->formatHookParams($share); - }, $deletedShares); - - $formatted['deletedShares'] = $formattedDeletedShares; + $formatted['deletedShares'] = [$formatted]; \OC_Hook::emit(Share::class, 'post_unshare', $formatted); } - public function postUnshareFromSelf(GenericEvent $e) { - /** @var IShare $share */ - $share = $e->getSubject(); + public function postUnshareFromSelf(ShareDeletedFromSelfEvent $e) { + $share = $e->getShare(); $formatted = $this->formatHookParams($share); $formatted['itemTarget'] = $formatted['fileTarget']; @@ -127,9 +110,8 @@ class LegacyHooks { return $hookParams; } - public function preShare(GenericEvent $e) { - /** @var IShare $share */ - $share = $e->getSubject(); + public function preShare(BeforeShareCreatedEvent $e) { + $share = $e->getShare(); // Pre share hook $run = true; @@ -151,16 +133,15 @@ class LegacyHooks { \OC_Hook::emit(Share::class, 'pre_shared', $preHookData); if ($run === false) { - $e->setArgument('error', $error); + $e->setError($error); $e->stopPropagation(); } return $e; } - public function postShare(GenericEvent $e) { - /** @var IShare $share */ - $share = $e->getSubject(); + public function postShare(ShareCreatedEvent $e) { + $share = $e->getShare(); $postHookData = [ 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 3f5dbd7cd28..9360046bc24 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -67,6 +67,11 @@ use OCP\Security\Events\ValidatePasswordPolicyEvent; use OCP\Security\IHasher; use OCP\Security\ISecureRandom; use OCP\Share; +use OCP\Share\Events\BeforeShareDeletedEvent; +use OCP\Share\Events\ShareAcceptedEvent; +use OCP\Share\Events\ShareCreatedEvent; +use OCP\Share\Events\ShareDeletedEvent; +use OCP\Share\Events\ShareDeletedFromSelfEvent; use OCP\Share\Exceptions\AlreadySharedException; use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\ShareNotFound; @@ -75,8 +80,6 @@ use OCP\Share\IProviderFactory; use OCP\Share\IShare; use OCP\Share\IShareProvider; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; /** * This class is the communication hub for all sharing related operations. @@ -105,8 +108,6 @@ class Manager implements IManager { private $rootFolder; /** @var CappedMemoryCache */ private $sharingDisabledForUsersCache; - /** @var EventDispatcherInterface */ - private $legacyDispatcher; /** @var LegacyHooks */ private $legacyHooks; /** @var IMailer */ @@ -134,7 +135,6 @@ class Manager implements IManager { IProviderFactory $factory, IUserManager $userManager, IRootFolder $rootFolder, - EventDispatcherInterface $legacyDispatcher, IMailer $mailer, IURLGenerator $urlGenerator, \OC_Defaults $defaults, @@ -153,7 +153,6 @@ class Manager implements IManager { $this->factory = $factory; $this->userManager = $userManager; $this->rootFolder = $rootFolder; - $this->legacyDispatcher = $legacyDispatcher; $this->sharingDisabledForUsersCache = new CappedMemoryCache(); // The constructor of LegacyHooks registers the listeners of share events // do not remove if those are not properly migrated @@ -806,10 +805,10 @@ class Manager implements IManager { $share->setTarget($target); // Pre share event - $event = new GenericEvent($share); - $this->legacyDispatcher->dispatch('OCP\Share::preShare', $event); - if ($event->isPropagationStopped() && $event->hasArgument('error')) { - throw new \Exception($event->getArgument('error')); + $event = new Share\Events\BeforeShareCreatedEvent($share); + $this->dispatcher->dispatchTyped($event); + if ($event->isPropagationStopped() && $event->getError()) { + throw new \Exception($event->getError()); } $oldShare = $share; @@ -833,10 +832,7 @@ class Manager implements IManager { } // Post share event - $event = new GenericEvent($share); - $this->legacyDispatcher->dispatch('OCP\Share::postShare', $event); - - $this->dispatcher->dispatchTyped(new Share\Events\ShareCreatedEvent($share)); + $this->dispatcher->dispatchTyped(new ShareCreatedEvent($share)); if ($this->config->getSystemValueBool('sharing.enable_share_mail', true) && $share->getShareType() === IShare::TYPE_USER) { @@ -1122,8 +1118,9 @@ class Manager implements IManager { throw new \InvalidArgumentException('Share provider does not support accepting'); } $provider->acceptShare($share, $recipientId); - $event = new GenericEvent($share); - $this->legacyDispatcher->dispatch('OCP\Share::postAcceptShare', $event); + + $event = new ShareAcceptedEvent($share); + $this->dispatcher->dispatchTyped($event); return $share; } @@ -1206,11 +1203,13 @@ class Manager implements IManager { $provider = $this->factory->getProviderForType($share->getShareType()); foreach ($provider->getChildren($share) as $child) { + $this->dispatcher->dispatchTyped(new BeforeShareDeletedEvent($child)); + $deletedChildren = $this->deleteChildren($child); $deletedShares = array_merge($deletedShares, $deletedChildren); $provider->delete($child); - $this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($child)); + $this->dispatcher->dispatchTyped(new ShareDeletedEvent($child)); $deletedShares[] = $child; } @@ -1231,24 +1230,16 @@ class Manager implements IManager { throw new \InvalidArgumentException('Share does not have a full id'); } - $event = new GenericEvent($share); - $this->legacyDispatcher->dispatch('OCP\Share::preUnshare', $event); + $this->dispatcher->dispatchTyped(new BeforeShareDeletedEvent($share)); // Get all children and delete them as well - $deletedShares = $this->deleteChildren($share); + $this->deleteChildren($share); // Do the actual delete $provider = $this->factory->getProviderForType($share->getShareType()); $provider->delete($share); - $this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($share)); - - // All the deleted shares caused by this delete - $deletedShares[] = $share; - - // Emit post hook - $event->setArgument('deletedShares', $deletedShares); - $this->legacyDispatcher->dispatch('OCP\Share::postUnshare', $event); + $this->dispatcher->dispatchTyped(new ShareDeletedEvent($share)); } @@ -1266,8 +1257,8 @@ class Manager implements IManager { $provider = $this->factory->getProvider($providerId); $provider->deleteFromSelf($share, $recipientId); - $event = new GenericEvent($share); - $this->legacyDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); + $event = new ShareDeletedFromSelfEvent($share); + $this->dispatcher->dispatchTyped($event); } public function restoreShare(IShare $share, string $recipientId): IShare { diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index 840a3c04373..e7075bce47a 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -51,6 +51,7 @@ use OC_User; use OC_Util; use OCA\DAV\Connector\Sabre\Auth; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\EventDispatcher\GenericEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\NotPermittedException; use OCP\IConfig; @@ -63,9 +64,9 @@ use OCP\Security\Bruteforce\IThrottler; use OCP\Security\ISecureRandom; use OCP\Session\Exceptions\SessionNotAvailableException; use OCP\User\Events\PostLoginEvent; +use OCP\User\Events\UserFirstTimeLoggedInEvent; use OCP\Util; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\GenericEvent; /** * Class Session @@ -561,7 +562,8 @@ class Session implements IUserSession, Emitter { } // trigger any other initialization - \OC::$server->getEventDispatcher()->dispatch(IUser::class . '::firstLogin', new GenericEvent($this->getUser())); + \OC::$server->get(IEventDispatcher::class)->dispatch(IUser::class . '::firstLogin', new GenericEvent($this->getUser())); + \OC::$server->get(IEventDispatcher::class)->dispatchTyped(new UserFirstTimeLoggedInEvent($this->getUser())); } } diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 9337492e775..ac449a62a4f 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -802,7 +802,7 @@ class OC_App { \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version); \OC::$server->get(IEventDispatcher::class)->dispatchTyped(new AppUpdateEvent($appId)); - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( + \OC::$server->get(IEventDispatcher::class)->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( ManagerEvent::EVENT_APP_UPDATE, $appId )); |