mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
Merge pull request #39605 from nextcloud/bugfix/noid/final-events-cleanup
fix!: Final round of moving to IEventDispatcher
This commit is contained in:
commit
44b4c16a09
43 changed files with 709 additions and 956 deletions
|
|
@ -69,6 +69,7 @@ use OCA\DAV\Events\CardDeletedEvent;
|
|||
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;
|
||||
|
|
@ -224,13 +225,10 @@ class Application extends App implements IBootstrap {
|
|||
}
|
||||
});
|
||||
|
||||
$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());
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ return array(
|
|||
'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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ use OCA\Files\Controller\ApiController;
|
|||
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;
|
||||
|
|
@ -57,6 +56,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap;
|
|||
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;
|
||||
|
|
@ -110,7 +110,7 @@ class Application extends App implements IBootstrap {
|
|||
$c->get(IActivityManager::class),
|
||||
$c->get(ITagManager::class)->load(self::APP_ID),
|
||||
$server->getUserFolder(),
|
||||
$server->getEventDispatcher()
|
||||
$c->get(IEventDispatcher::class),
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -120,7 +120,6 @@ class Application extends App implements IBootstrap {
|
|||
$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);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,12 +28,15 @@ namespace OCA\Files\Collaboration\Resources;
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
* @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 OCA\Files\Listener;
|
||||
|
||||
use OC\EventDispatcher\SymfonyAdapter;
|
||||
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
class LegacyLoadAdditionalScriptsAdapter implements IEventListener {
|
||||
|
||||
/** @var SymfonyAdapter */
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(SymfonyAdapter $dispatcher) {
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if (!($event instanceof LoadAdditionalScriptsEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$legacyEvent = new GenericEvent(null, ['hiddenFields' => []]);
|
||||
$this->dispatcher->dispatch('OCA\Files::loadAdditionalScripts', $legacyEvent);
|
||||
|
||||
$hiddenFields = $legacyEvent->getArgument('hiddenFields');
|
||||
foreach ($hiddenFields as $name => $value) {
|
||||
$event->addHiddenField($name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,12 +26,13 @@ namespace OCA\Files\Service;
|
|||
|
||||
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.
|
||||
|
|
@ -46,7 +47,7 @@ class TagService {
|
|||
private $tagger;
|
||||
/** @var Folder|null */
|
||||
private $homeFolder;
|
||||
/** @var EventDispatcherInterface */
|
||||
/** @var IEventDispatcher */
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(
|
||||
|
|
@ -54,7 +55,7 @@ class TagService {
|
|||
IManager $activityManager,
|
||||
?ITags $tagger,
|
||||
?Folder $homeFolder,
|
||||
EventDispatcherInterface $dispatcher
|
||||
IEventDispatcher $dispatcher,
|
||||
) {
|
||||
$this->userSession = $userSession;
|
||||
$this->activityManager = $activityManager;
|
||||
|
|
@ -120,12 +121,12 @@ class TagService {
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ namespace OCA\Files\Tests\Service;
|
|||
|
||||
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
|
||||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -90,7 +90,7 @@ class TagServiceTest extends \Test\TestCase {
|
|||
->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']);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ use OCA\Files_External\Lib\Backend\Backend;
|
|||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -112,7 +113,7 @@ class BackendService {
|
|||
private function callForRegistrations() {
|
||||
static $eventSent = false;
|
||||
if (!$eventSent) {
|
||||
\OC::$server->getEventDispatcher()->dispatch(
|
||||
\OC::$server->get(IEventDispatcher::class)->dispatch(
|
||||
'OCA\\Files_External::loadAdditionalBackends',
|
||||
new GenericEvent()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ return array(
|
|||
'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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
|
|||
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;
|
||||
|
|
@ -133,7 +132,6 @@ class Application extends App implements IBootstrap {
|
|||
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);
|
||||
|
|
@ -143,10 +141,7 @@ class Application extends App implements IBootstrap {
|
|||
});
|
||||
|
||||
// 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);
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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 OCA\Files_Sharing\Listener;
|
||||
|
||||
use OC\EventDispatcher\SymfonyAdapter;
|
||||
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
class LegacyBeforeTemplateRenderedListener implements IEventListener {
|
||||
|
||||
/** @var SymfonyAdapter */
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(SymfonyAdapter $dispatcher) {
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if (!($event instanceof BeforeTemplateRenderedEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$eventName = 'OCA\Files_Sharing::loadAdditionalScripts';
|
||||
|
||||
if ($event->getScope() !== null) {
|
||||
$eventName .= '::' . $event->getScope();
|
||||
}
|
||||
|
||||
$legacyEvent = new GenericEvent(null, ['share' => $event->getShare()]);
|
||||
$this->dispatcher->dispatch($eventName, $legacyEvent);
|
||||
}
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@ use OCP\IGroupManager;
|
|||
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;
|
||||
|
|
@ -54,12 +55,8 @@ class Listener {
|
|||
$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) {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ use OCP\Security\IHasher;
|
|||
use OCP\Security\ISecureRandom;
|
||||
use OCP\Share\IProviderFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* Class CapabilitiesTest
|
||||
|
|
@ -90,7 +89,6 @@ class CapabilitiesTest extends \Test\TestCase {
|
|||
$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),
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ namespace OCA\LookupServerConnector\AppInfo;
|
|||
|
||||
use Closure;
|
||||
use OCA\LookupServerConnector\UpdateLookupServer;
|
||||
use OCP\Accounts\UserUpdatedEvent;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
|
|
@ -58,15 +59,10 @@ class Application extends App implements IBootstrap {
|
|||
*/
|
||||
private function registerEventListeners(IEventDispatcher $dispatcher,
|
||||
ContainerInterface $appContainer): void {
|
||||
$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);
|
||||
}
|
||||
$dispatcher->addListener(UserUpdatedEvent::class, function (UserUpdatedEvent $event) use ($appContainer) {
|
||||
/** @var UpdateLookupServer $updateLookupServer */
|
||||
$updateLookupServer = $appContainer->get(UpdateLookupServer::class);
|
||||
$updateLookupServer->userUpdated($event->getUser());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace OCA\SystemTags\AppInfo;
|
||||
|
||||
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
||||
use OCA\SystemTags\Search\TagSearchProvider;
|
||||
use OCA\SystemTags\Activity\Listener;
|
||||
use OCP\AppFramework\App;
|
||||
|
|
@ -52,7 +53,7 @@ class Application extends App implements IBootstrap {
|
|||
* @todo move the OCP events and then move the registration to `register`
|
||||
*/
|
||||
$dispatcher->addListener(
|
||||
'OCA\Files::loadAdditionalScripts',
|
||||
LoadAdditionalScriptsEvent::class,
|
||||
function () {
|
||||
\OCP\Util::addScript('core', 'systemtags');
|
||||
\OCP\Util::addScript(self::APP_ID, 'systemtags');
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ declare(strict_types=1);
|
|||
*/
|
||||
|
||||
use OC\Encryption\HookManager;
|
||||
use OC\EventDispatcher\SymfonyAdapter;
|
||||
use OC\Share20\Hooks;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Group\Events\UserRemovedEvent;
|
||||
|
|
@ -939,7 +938,7 @@ class OC {
|
|||
}
|
||||
|
||||
private static function registerResourceCollectionHooks(): void {
|
||||
\OC\Collaboration\Resources\Listener::register(Server::get(SymfonyAdapter::class), Server::get(IEventDispatcher::class));
|
||||
\OC\Collaboration\Resources\Listener::register(Server::get(IEventDispatcher::class));
|
||||
}
|
||||
|
||||
private static function registerFileReferenceEventListener(): void {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ return array(
|
|||
'OCP\\Accounts\\IAccountProperty' => $baseDir . '/lib/public/Accounts/IAccountProperty.php',
|
||||
'OCP\\Accounts\\IAccountPropertyCollection' => $baseDir . '/lib/public/Accounts/IAccountPropertyCollection.php',
|
||||
'OCP\\Accounts\\PropertyDoesNotExistException' => $baseDir . '/lib/public/Accounts/PropertyDoesNotExistException.php',
|
||||
'OCP\\Accounts\\UserUpdatedEvent' => $baseDir . '/lib/public/Accounts/UserUpdatedEvent.php',
|
||||
'OCP\\Activity\\ActivitySettings' => $baseDir . '/lib/public/Activity/ActivitySettings.php',
|
||||
'OCP\\Activity\\IConsumer' => $baseDir . '/lib/public/Activity/IConsumer.php',
|
||||
'OCP\\Activity\\IEvent' => $baseDir . '/lib/public/Activity/IEvent.php',
|
||||
|
|
@ -309,7 +310,9 @@ return array(
|
|||
'OCP\\Files\\Events\\FolderScannedEvent' => $baseDir . '/lib/public/Files/Events/FolderScannedEvent.php',
|
||||
'OCP\\Files\\Events\\InvalidateMountCacheEvent' => $baseDir . '/lib/public/Files/Events/InvalidateMountCacheEvent.php',
|
||||
'OCP\\Files\\Events\\NodeAddedToCache' => $baseDir . '/lib/public/Files/Events/NodeAddedToCache.php',
|
||||
'OCP\\Files\\Events\\NodeAddedToFavorite' => $baseDir . '/lib/public/Files/Events/NodeAddedToFavorite.php',
|
||||
'OCP\\Files\\Events\\NodeRemovedFromCache' => $baseDir . '/lib/public/Files/Events/NodeRemovedFromCache.php',
|
||||
'OCP\\Files\\Events\\NodeRemovedFromFavorite' => $baseDir . '/lib/public/Files/Events/NodeRemovedFromFavorite.php',
|
||||
'OCP\\Files\\Events\\Node\\AbstractNodeEvent' => $baseDir . '/lib/public/Files/Events/Node/AbstractNodeEvent.php',
|
||||
'OCP\\Files\\Events\\Node\\AbstractNodesEvent' => $baseDir . '/lib/public/Files/Events/Node/AbstractNodesEvent.php',
|
||||
'OCP\\Files\\Events\\Node\\BeforeNodeCopiedEvent' => $baseDir . '/lib/public/Files/Events/Node/BeforeNodeCopiedEvent.php',
|
||||
|
|
@ -583,8 +586,12 @@ return array(
|
|||
'OCP\\Settings\\ISettings' => $baseDir . '/lib/public/Settings/ISettings.php',
|
||||
'OCP\\Settings\\ISubAdminSettings' => $baseDir . '/lib/public/Settings/ISubAdminSettings.php',
|
||||
'OCP\\Share' => $baseDir . '/lib/public/Share.php',
|
||||
'OCP\\Share\\Events\\BeforeShareCreatedEvent' => $baseDir . '/lib/public/Share/Events/BeforeShareCreatedEvent.php',
|
||||
'OCP\\Share\\Events\\BeforeShareDeletedEvent' => $baseDir . '/lib/public/Share/Events/BeforeShareDeletedEvent.php',
|
||||
'OCP\\Share\\Events\\ShareAcceptedEvent' => $baseDir . '/lib/public/Share/Events/ShareAcceptedEvent.php',
|
||||
'OCP\\Share\\Events\\ShareCreatedEvent' => $baseDir . '/lib/public/Share/Events/ShareCreatedEvent.php',
|
||||
'OCP\\Share\\Events\\ShareDeletedEvent' => $baseDir . '/lib/public/Share/Events/ShareDeletedEvent.php',
|
||||
'OCP\\Share\\Events\\ShareDeletedFromSelfEvent' => $baseDir . '/lib/public/Share/Events/ShareDeletedFromSelfEvent.php',
|
||||
'OCP\\Share\\Events\\VerifyMountPointEvent' => $baseDir . '/lib/public/Share/Events/VerifyMountPointEvent.php',
|
||||
'OCP\\Share\\Exceptions\\AlreadySharedException' => $baseDir . '/lib/public/Share/Exceptions/AlreadySharedException.php',
|
||||
'OCP\\Share\\Exceptions\\GenericShareException' => $baseDir . '/lib/public/Share/Exceptions/GenericShareException.php',
|
||||
|
|
@ -682,6 +689,7 @@ return array(
|
|||
'OCP\\User\\Events\\UserChangedEvent' => $baseDir . '/lib/public/User/Events/UserChangedEvent.php',
|
||||
'OCP\\User\\Events\\UserCreatedEvent' => $baseDir . '/lib/public/User/Events/UserCreatedEvent.php',
|
||||
'OCP\\User\\Events\\UserDeletedEvent' => $baseDir . '/lib/public/User/Events/UserDeletedEvent.php',
|
||||
'OCP\\User\\Events\\UserFirstTimeLoggedInEvent' => $baseDir . '/lib/public/User/Events/UserFirstTimeLoggedInEvent.php',
|
||||
'OCP\\User\\Events\\UserLiveStatusEvent' => $baseDir . '/lib/public/User/Events/UserLiveStatusEvent.php',
|
||||
'OCP\\User\\Events\\UserLoggedInEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInEvent.php',
|
||||
'OCP\\User\\Events\\UserLoggedInWithCookieEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInWithCookieEvent.php',
|
||||
|
|
@ -1223,9 +1231,7 @@ return array(
|
|||
'OC\\Encryption\\Update' => $baseDir . '/lib/private/Encryption/Update.php',
|
||||
'OC\\Encryption\\Util' => $baseDir . '/lib/private/Encryption/Util.php',
|
||||
'OC\\EventDispatcher\\EventDispatcher' => $baseDir . '/lib/private/EventDispatcher/EventDispatcher.php',
|
||||
'OC\\EventDispatcher\\GenericEventWrapper' => $baseDir . '/lib/private/EventDispatcher/GenericEventWrapper.php',
|
||||
'OC\\EventDispatcher\\ServiceEventListener' => $baseDir . '/lib/private/EventDispatcher/ServiceEventListener.php',
|
||||
'OC\\EventDispatcher\\SymfonyAdapter' => $baseDir . '/lib/private/EventDispatcher/SymfonyAdapter.php',
|
||||
'OC\\EventSourceFactory' => $baseDir . '/lib/private/EventSourceFactory.php',
|
||||
'OC\\Federation\\CloudFederationFactory' => $baseDir . '/lib/private/Federation/CloudFederationFactory.php',
|
||||
'OC\\Federation\\CloudFederationNotification' => $baseDir . '/lib/private/Federation/CloudFederationNotification.php',
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Accounts\\IAccountProperty' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccountProperty.php',
|
||||
'OCP\\Accounts\\IAccountPropertyCollection' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccountPropertyCollection.php',
|
||||
'OCP\\Accounts\\PropertyDoesNotExistException' => __DIR__ . '/../../..' . '/lib/public/Accounts/PropertyDoesNotExistException.php',
|
||||
'OCP\\Accounts\\UserUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/Accounts/UserUpdatedEvent.php',
|
||||
'OCP\\Activity\\ActivitySettings' => __DIR__ . '/../../..' . '/lib/public/Activity/ActivitySettings.php',
|
||||
'OCP\\Activity\\IConsumer' => __DIR__ . '/../../..' . '/lib/public/Activity/IConsumer.php',
|
||||
'OCP\\Activity\\IEvent' => __DIR__ . '/../../..' . '/lib/public/Activity/IEvent.php',
|
||||
|
|
@ -342,7 +343,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Files\\Events\\FolderScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FolderScannedEvent.php',
|
||||
'OCP\\Files\\Events\\InvalidateMountCacheEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/InvalidateMountCacheEvent.php',
|
||||
'OCP\\Files\\Events\\NodeAddedToCache' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeAddedToCache.php',
|
||||
'OCP\\Files\\Events\\NodeAddedToFavorite' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeAddedToFavorite.php',
|
||||
'OCP\\Files\\Events\\NodeRemovedFromCache' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeRemovedFromCache.php',
|
||||
'OCP\\Files\\Events\\NodeRemovedFromFavorite' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeRemovedFromFavorite.php',
|
||||
'OCP\\Files\\Events\\Node\\AbstractNodeEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/AbstractNodeEvent.php',
|
||||
'OCP\\Files\\Events\\Node\\AbstractNodesEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/AbstractNodesEvent.php',
|
||||
'OCP\\Files\\Events\\Node\\BeforeNodeCopiedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/BeforeNodeCopiedEvent.php',
|
||||
|
|
@ -616,8 +619,12 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Settings\\ISettings' => __DIR__ . '/../../..' . '/lib/public/Settings/ISettings.php',
|
||||
'OCP\\Settings\\ISubAdminSettings' => __DIR__ . '/../../..' . '/lib/public/Settings/ISubAdminSettings.php',
|
||||
'OCP\\Share' => __DIR__ . '/../../..' . '/lib/public/Share.php',
|
||||
'OCP\\Share\\Events\\BeforeShareCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/BeforeShareCreatedEvent.php',
|
||||
'OCP\\Share\\Events\\BeforeShareDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/BeforeShareDeletedEvent.php',
|
||||
'OCP\\Share\\Events\\ShareAcceptedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/ShareAcceptedEvent.php',
|
||||
'OCP\\Share\\Events\\ShareCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/ShareCreatedEvent.php',
|
||||
'OCP\\Share\\Events\\ShareDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/ShareDeletedEvent.php',
|
||||
'OCP\\Share\\Events\\ShareDeletedFromSelfEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/ShareDeletedFromSelfEvent.php',
|
||||
'OCP\\Share\\Events\\VerifyMountPointEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/VerifyMountPointEvent.php',
|
||||
'OCP\\Share\\Exceptions\\AlreadySharedException' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/AlreadySharedException.php',
|
||||
'OCP\\Share\\Exceptions\\GenericShareException' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/GenericShareException.php',
|
||||
|
|
@ -715,6 +722,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\User\\Events\\UserChangedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserChangedEvent.php',
|
||||
'OCP\\User\\Events\\UserCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserCreatedEvent.php',
|
||||
'OCP\\User\\Events\\UserDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserDeletedEvent.php',
|
||||
'OCP\\User\\Events\\UserFirstTimeLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserFirstTimeLoggedInEvent.php',
|
||||
'OCP\\User\\Events\\UserLiveStatusEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLiveStatusEvent.php',
|
||||
'OCP\\User\\Events\\UserLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLoggedInEvent.php',
|
||||
'OCP\\User\\Events\\UserLoggedInWithCookieEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLoggedInWithCookieEvent.php',
|
||||
|
|
@ -1256,9 +1264,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OC\\Encryption\\Update' => __DIR__ . '/../../..' . '/lib/private/Encryption/Update.php',
|
||||
'OC\\Encryption\\Util' => __DIR__ . '/../../..' . '/lib/private/Encryption/Util.php',
|
||||
'OC\\EventDispatcher\\EventDispatcher' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/EventDispatcher.php',
|
||||
'OC\\EventDispatcher\\GenericEventWrapper' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/GenericEventWrapper.php',
|
||||
'OC\\EventDispatcher\\ServiceEventListener' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/ServiceEventListener.php',
|
||||
'OC\\EventDispatcher\\SymfonyAdapter' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/SymfonyAdapter.php',
|
||||
'OC\\EventSourceFactory' => __DIR__ . '/../../..' . '/lib/private/EventSourceFactory.php',
|
||||
'OC\\Federation\\CloudFederationFactory' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationFactory.php',
|
||||
'OC\\Federation\\CloudFederationNotification' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationNotification.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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
@ -2045,17 +2039,6 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
return $this->get(CapabilitiesManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
));
|
||||
|
||||
|
|
|
|||
58
lib/public/Accounts/UserUpdatedEvent.php
Normal file
58
lib/public/Accounts/UserUpdatedEvent.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 OCP\Accounts;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\IUser;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class UserUpdatedEvent extends Event {
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
protected IUser $user,
|
||||
protected array $data,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getUser(): IUser {
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getData(): array {
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
66
lib/public/Files/Events/NodeAddedToFavorite.php
Normal file
66
lib/public/Files/Events/NodeAddedToFavorite.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 OCP\Files\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\IUser;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class NodeAddedToFavorite extends Event {
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
protected IUser $user,
|
||||
protected int $fileId,
|
||||
protected string $path,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getUser(): IUser {
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getFileId(): int {
|
||||
return $this->fileId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getPath(): string {
|
||||
return $this->path;
|
||||
}
|
||||
}
|
||||
66
lib/public/Files/Events/NodeRemovedFromFavorite.php
Normal file
66
lib/public/Files/Events/NodeRemovedFromFavorite.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 OCP\Files\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\IUser;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class NodeRemovedFromFavorite extends Event {
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
protected IUser $user,
|
||||
protected int $fileId,
|
||||
protected string $path,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getUser(): IUser {
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getFileId(): int {
|
||||
return $this->fileId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getPath(): string {
|
||||
return $this->path;
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,6 @@ use OCP\Federation\ICloudFederationProviderManager;
|
|||
use OCP\Log\ILogFactory;
|
||||
use OCP\Security\IContentSecurityPolicyManager;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* This is a tagging interface for the server container
|
||||
|
|
@ -516,15 +515,6 @@ interface IServerContainer extends ContainerInterface, IContainer {
|
|||
*/
|
||||
public function getMimeTypeLoader();
|
||||
|
||||
/**
|
||||
* Get the EventDispatcher
|
||||
*
|
||||
* @return EventDispatcherInterface
|
||||
* @deprecated 20.0.0 use \OCP\EventDispatcher\IEventDispatcher
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function getEventDispatcher();
|
||||
|
||||
/**
|
||||
* Get the Notification Manager
|
||||
*
|
||||
|
|
|
|||
66
lib/public/Share/Events/BeforeShareCreatedEvent.php
Normal file
66
lib/public/Share/Events/BeforeShareCreatedEvent.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 OCP\Share\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\Share\IShare;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class BeforeShareCreatedEvent extends Event {
|
||||
private ?string $error = null;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
private IShare $share,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getShare(): IShare {
|
||||
return $this->share;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function setError(string $error): void {
|
||||
$this->error = $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getError(): ?string {
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
50
lib/public/Share/Events/BeforeShareDeletedEvent.php
Normal file
50
lib/public/Share/Events/BeforeShareDeletedEvent.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 OCP\Share\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\Share\IShare;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class BeforeShareDeletedEvent extends Event {
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
private IShare $share,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getShare(): IShare {
|
||||
return $this->share;
|
||||
}
|
||||
}
|
||||
50
lib/public/Share/Events/ShareAcceptedEvent.php
Normal file
50
lib/public/Share/Events/ShareAcceptedEvent.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 OCP\Share\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\Share\IShare;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class ShareAcceptedEvent extends Event {
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
private IShare $share,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getShare(): IShare {
|
||||
return $this->share;
|
||||
}
|
||||
}
|
||||
50
lib/public/Share/Events/ShareDeletedFromSelfEvent.php
Normal file
50
lib/public/Share/Events/ShareDeletedFromSelfEvent.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 OCP\Share\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\Share\IShare;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class ShareDeletedFromSelfEvent extends Event {
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
private IShare $share,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getShare(): IShare {
|
||||
return $this->share;
|
||||
}
|
||||
}
|
||||
50
lib/public/User/Events/UserFirstTimeLoggedInEvent.php
Normal file
50
lib/public/User/Events/UserFirstTimeLoggedInEvent.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 OCP\User\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\IUser;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class UserFirstTimeLoggedInEvent extends Event {
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
private IUser $user,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getUser(): IUser {
|
||||
return $this->user;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,8 +28,10 @@ use OC\Accounts\Account;
|
|||
use OC\Accounts\AccountManager;
|
||||
use OCA\Settings\BackgroundJobs\VerifyUserData;
|
||||
use OCP\Accounts\IAccountManager;
|
||||
use OCP\Accounts\UserUpdatedEvent;
|
||||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\Defaults;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IURLGenerator;
|
||||
|
|
@ -40,8 +42,6 @@ use OCP\Security\ICrypto;
|
|||
use OCP\Security\VerificationToken\IVerificationToken;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -70,7 +70,7 @@ class AccountManagerTest extends TestCase {
|
|||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
|
||||
/** @var EventDispatcherInterface|MockObject */
|
||||
/** @var IEventDispatcher|MockObject */
|
||||
private $eventDispatcher;
|
||||
|
||||
/** @var IJobList|MockObject */
|
||||
|
|
@ -86,7 +86,7 @@ class AccountManagerTest extends TestCase {
|
|||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->connection = \OC::$server->get(IDBConnection::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->jobList = $this->createMock(IJobList::class);
|
||||
|
|
@ -502,15 +502,14 @@ class AccountManagerTest extends TestCase {
|
|||
if (!$insertNew && !$updateExisting) {
|
||||
$accountManager->expects($this->never())->method('updateExistingUser');
|
||||
$accountManager->expects($this->never())->method('insertNewUser');
|
||||
$this->eventDispatcher->expects($this->never())->method('dispatch');
|
||||
$this->eventDispatcher->expects($this->never())->method('dispatchTyped');
|
||||
} else {
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatchTyped')
|
||||
->willReturnCallback(
|
||||
function ($eventName, $event) use ($user, $newData) {
|
||||
$this->assertSame('OC\AccountManager::userUpdated', $eventName);
|
||||
$this->assertInstanceOf(GenericEvent::class, $event);
|
||||
$this->assertSame($user, $event->getSubject());
|
||||
$this->assertSame($newData, $event->getArguments());
|
||||
function ($event) use ($user, $newData) {
|
||||
$this->assertInstanceOf(UserUpdatedEvent::class, $event);
|
||||
$this->assertSame($user, $event->getUser());
|
||||
$this->assertSame($newData, $event->getData());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,191 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
*
|
||||
* @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
*
|
||||
* @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 lib\EventDispatcher;
|
||||
|
||||
use OC\EventDispatcher\EventDispatcher;
|
||||
use OC\EventDispatcher\GenericEventWrapper;
|
||||
use OC\EventDispatcher\SymfonyAdapter;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\GenericEvent;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\Event as SymfonyEvent;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent as SymfonyGenericEvent;
|
||||
use Test\TestCase;
|
||||
|
||||
class SymfonyAdapterTest extends TestCase {
|
||||
/** @var EventDispatcher|MockObject */
|
||||
private $eventDispatcher;
|
||||
|
||||
/** @var LoggerInterface|MockObject */
|
||||
private $logger;
|
||||
|
||||
/** @var EventDispatcherInterface */
|
||||
private $adapter;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->eventDispatcher = $this->createMock(EventDispatcher::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$this->adapter = new SymfonyAdapter(
|
||||
$this->eventDispatcher,
|
||||
$this->logger
|
||||
);
|
||||
}
|
||||
|
||||
public function testDispatchTypedEvent(): void {
|
||||
$event = new Event();
|
||||
$eventName = 'symfony';
|
||||
$this->eventDispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
$eventName,
|
||||
$event
|
||||
)
|
||||
->willReturnArgument(0);
|
||||
|
||||
$this->adapter->dispatch($eventName, $event);
|
||||
}
|
||||
|
||||
public function testDispatchSymfonyGenericEvent(): void {
|
||||
$eventName = 'symfony';
|
||||
$event = new SymfonyGenericEvent();
|
||||
$wrapped = new GenericEventWrapper(
|
||||
$this->logger,
|
||||
$eventName,
|
||||
$event
|
||||
);
|
||||
$symfonyDispatcher = $this->createMock(SymfonyDispatcher::class);
|
||||
$this->eventDispatcher->expects(self::once())
|
||||
->method('getSymfonyDispatcher')
|
||||
->willReturn($symfonyDispatcher);
|
||||
$symfonyDispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
self::equalTo($wrapped),
|
||||
$eventName
|
||||
)
|
||||
->willReturnArgument(0);
|
||||
|
||||
$result = $this->adapter->dispatch($eventName, $event);
|
||||
|
||||
self::assertEquals($result, $wrapped);
|
||||
}
|
||||
|
||||
public function testDispatchOldSymfonyEventWithFlippedArgumentOrder(): void {
|
||||
$event = new SymfonyEvent();
|
||||
$eventName = 'symfony';
|
||||
$symfonyDispatcher = $this->createMock(SymfonyDispatcher::class);
|
||||
$this->eventDispatcher->expects(self::once())
|
||||
->method('getSymfonyDispatcher')
|
||||
->willReturn($symfonyDispatcher);
|
||||
$symfonyDispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
$event,
|
||||
$eventName
|
||||
)
|
||||
->willReturnArgument(0);
|
||||
|
||||
$result = $this->adapter->dispatch($event, $eventName);
|
||||
|
||||
self::assertSame($result, $event);
|
||||
}
|
||||
|
||||
public function testDispatchOldSymfonyEvent(): void {
|
||||
$event = new SymfonyEvent();
|
||||
$eventName = 'symfony';
|
||||
$symfonyDispatcher = $this->createMock(SymfonyDispatcher::class);
|
||||
$this->eventDispatcher->expects(self::once())
|
||||
->method('getSymfonyDispatcher')
|
||||
->willReturn($symfonyDispatcher);
|
||||
$symfonyDispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
$event,
|
||||
$eventName
|
||||
)
|
||||
->willReturnArgument(0);
|
||||
|
||||
$result = $this->adapter->dispatch($eventName, $event);
|
||||
|
||||
self::assertSame($result, $event);
|
||||
}
|
||||
|
||||
public function testDispatchCustomGenericEventWithFlippedArgumentOrder(): void {
|
||||
$event = new GenericEvent();
|
||||
$eventName = 'symfony';
|
||||
$this->eventDispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
$eventName,
|
||||
$event
|
||||
)
|
||||
->willReturnArgument(0);
|
||||
|
||||
$result = $this->adapter->dispatch($event, $eventName);
|
||||
|
||||
self::assertSame($result, $event);
|
||||
}
|
||||
|
||||
public function testDispatchCustomGenericEvent(): void {
|
||||
$event = new GenericEvent();
|
||||
$eventName = 'symfony';
|
||||
$this->eventDispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
$eventName,
|
||||
$event
|
||||
);
|
||||
|
||||
$result = $this->adapter->dispatch($eventName, $event);
|
||||
|
||||
self::assertSame($result, $event);
|
||||
}
|
||||
|
||||
public function testDispatchEventWithoutPayload(): void {
|
||||
$eventName = 'symfony';
|
||||
$symfonyDispatcher = $this->createMock(SymfonyDispatcher::class);
|
||||
$this->eventDispatcher->expects(self::once())
|
||||
->method('getSymfonyDispatcher')
|
||||
->willReturn($symfonyDispatcher);
|
||||
$symfonyDispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
$this->anything(),
|
||||
$eventName
|
||||
)
|
||||
->willReturnArgument(0);
|
||||
|
||||
$result = $this->adapter->dispatch($eventName);
|
||||
|
||||
self::assertNotNull($result);
|
||||
}
|
||||
}
|
||||
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
namespace Test\Share20;
|
||||
|
||||
use OC\EventDispatcher\SymfonyAdapter;
|
||||
use OC\Share20\LegacyHooks;
|
||||
use OC\Share20\Manager;
|
||||
use OCP\Constants;
|
||||
|
|
@ -31,9 +30,13 @@ use OCP\EventDispatcher\IEventDispatcher;
|
|||
use OCP\Files\Cache\ICacheEntry;
|
||||
use OCP\Files\File;
|
||||
use OCP\IServerContainer;
|
||||
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 Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
use Test\TestCase;
|
||||
|
||||
class LegacyHooksTest extends TestCase {
|
||||
|
|
@ -51,9 +54,8 @@ class LegacyHooksTest extends TestCase {
|
|||
|
||||
$symfonyDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$eventDispatcher = new \OC\EventDispatcher\EventDispatcher($symfonyDispatcher, \OC::$server->get(IServerContainer::class), $logger);
|
||||
$this->eventDispatcher = new SymfonyAdapter($eventDispatcher, $logger);
|
||||
$this->hooks = new LegacyHooks($eventDispatcher);
|
||||
$this->eventDispatcher = new \OC\EventDispatcher\EventDispatcher($symfonyDispatcher, \OC::$server->get(IServerContainer::class), $logger);
|
||||
$this->hooks = new LegacyHooks($this->eventDispatcher);
|
||||
$this->manager = \OC::$server->getShareManager();
|
||||
}
|
||||
|
||||
|
|
@ -94,8 +96,8 @@ class LegacyHooksTest extends TestCase {
|
|||
->method('pre')
|
||||
->with($hookListnerExpectsPre);
|
||||
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event);
|
||||
$event = new BeforeShareDeletedEvent($share);
|
||||
$this->eventDispatcher->dispatchTyped($event);
|
||||
}
|
||||
|
||||
public function testPostUnshare() {
|
||||
|
|
@ -148,9 +150,8 @@ class LegacyHooksTest extends TestCase {
|
|||
->method('post')
|
||||
->with($hookListnerExpectsPost);
|
||||
|
||||
$event = new GenericEvent($share);
|
||||
$event->setArgument('deletedShares', [$share]);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event);
|
||||
$event = new ShareDeletedEvent($share);
|
||||
$this->eventDispatcher->dispatchTyped($event);
|
||||
}
|
||||
|
||||
public function testPostUnshareFromSelf() {
|
||||
|
|
@ -205,8 +206,8 @@ class LegacyHooksTest extends TestCase {
|
|||
->method('postFromSelf')
|
||||
->with($hookListnerExpectsPostFromSelf);
|
||||
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event);
|
||||
$event = new ShareDeletedFromSelfEvent($share);
|
||||
$this->eventDispatcher->dispatchTyped($event);
|
||||
}
|
||||
|
||||
public function testPreShare() {
|
||||
|
|
@ -253,8 +254,8 @@ class LegacyHooksTest extends TestCase {
|
|||
->method('preShare')
|
||||
->with($expected);
|
||||
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::preShare', $event);
|
||||
$event = new BeforeShareCreatedEvent($share);
|
||||
$this->eventDispatcher->dispatchTyped($event);
|
||||
}
|
||||
|
||||
public function testPreShareError() {
|
||||
|
|
@ -305,11 +306,11 @@ class LegacyHooksTest extends TestCase {
|
|||
$data['error'] = 'I error';
|
||||
});
|
||||
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::preShare', $event);
|
||||
$event = new BeforeShareCreatedEvent($share);
|
||||
$this->eventDispatcher->dispatchTyped($event);
|
||||
|
||||
$this->assertTrue($event->isPropagationStopped());
|
||||
$this->assertSame('I error', $event->getArgument('error'));
|
||||
$this->assertSame('I error', $event->getError());
|
||||
}
|
||||
|
||||
public function testPostShare() {
|
||||
|
|
@ -355,7 +356,7 @@ class LegacyHooksTest extends TestCase {
|
|||
->method('postShare')
|
||||
->with($expected);
|
||||
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::postShare', $event);
|
||||
$event = new ShareCreatedEvent($share);
|
||||
$this->eventDispatcher->dispatchTyped($event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,11 @@ use OCP\Mail\IMailer;
|
|||
use OCP\Security\Events\ValidatePasswordPolicyEvent;
|
||||
use OCP\Security\IHasher;
|
||||
use OCP\Security\ISecureRandom;
|
||||
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\Exceptions\AlreadySharedException;
|
||||
use OCP\Share\Exceptions\ShareNotFound;
|
||||
use OCP\Share\IManager;
|
||||
|
|
@ -60,8 +65,6 @@ use OCP\Share\IShareProvider;
|
|||
use PHPUnit\Framework\MockObject\MockBuilder;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
/**
|
||||
* Class ManagerTest
|
||||
|
|
@ -96,8 +99,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
protected $userManager;
|
||||
/** @var IRootFolder | MockObject */
|
||||
protected $rootFolder;
|
||||
/** @var EventDispatcherInterface | MockObject */
|
||||
protected $eventDispatcher;
|
||||
/** @var IEventDispatcher|MockObject */
|
||||
protected $dispatcher;
|
||||
/** @var IMailer|MockObject */
|
||||
|
|
@ -120,7 +121,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->rootFolder = $this->createMock(IRootFolder::class);
|
||||
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||
$this->mailer = $this->createMock(IMailer::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->defaults = $this->createMock(\OC_Defaults::class);
|
||||
|
|
@ -153,7 +153,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
|
|
@ -184,7 +183,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
|
|
@ -247,17 +245,16 @@ class ManagerTest extends \Test\TestCase {
|
|||
->method('delete')
|
||||
->with($share);
|
||||
|
||||
$this->eventDispatcher->expects($this->exactly(2))
|
||||
->method('dispatch')
|
||||
$this->dispatcher->expects($this->exactly(2))
|
||||
->method('dispatchTyped')
|
||||
->withConsecutive(
|
||||
['OCP\Share::preUnshare',
|
||||
$this->callBack(function (GenericEvent $e) use ($share) {
|
||||
return $e->getSubject() === $share;
|
||||
[
|
||||
$this->callBack(function (BeforeShareDeletedEvent $e) use ($share) {
|
||||
return $e->getShare() === $share;
|
||||
})],
|
||||
['OCP\Share::postUnshare',
|
||||
$this->callBack(function (GenericEvent $e) use ($share) {
|
||||
return $e->getSubject() === $share &&
|
||||
$e->getArgument('deletedShares') === [$share];
|
||||
[
|
||||
$this->callBack(function (ShareDeletedEvent $e) use ($share) {
|
||||
return $e->getShare() === $share;
|
||||
})]
|
||||
);
|
||||
|
||||
|
|
@ -291,17 +288,16 @@ class ManagerTest extends \Test\TestCase {
|
|||
->method('delete')
|
||||
->with($share);
|
||||
|
||||
$this->eventDispatcher->expects($this->exactly(2))
|
||||
->method('dispatch')
|
||||
$this->dispatcher->expects($this->exactly(2))
|
||||
->method('dispatchTyped')
|
||||
->withConsecutive(
|
||||
['OCP\Share::preUnshare',
|
||||
$this->callBack(function (GenericEvent $e) use ($share) {
|
||||
return $e->getSubject() === $share;
|
||||
[
|
||||
$this->callBack(function (BeforeShareDeletedEvent $e) use ($share) {
|
||||
return $e->getShare() === $share;
|
||||
})],
|
||||
['OCP\Share::postUnshare',
|
||||
$this->callBack(function (GenericEvent $e) use ($share) {
|
||||
return $e->getSubject() === $share &&
|
||||
$e->getArgument('deletedShares') === [$share];
|
||||
[
|
||||
$this->callBack(function (ShareDeletedEvent $e) use ($share) {
|
||||
return $e->getShare() === $share;
|
||||
})]
|
||||
);
|
||||
|
||||
|
|
@ -356,18 +352,39 @@ class ManagerTest extends \Test\TestCase {
|
|||
->method('delete')
|
||||
->withConsecutive([$share3], [$share2], [$share1]);
|
||||
|
||||
$this->eventDispatcher->expects($this->exactly(2))
|
||||
->method('dispatch')
|
||||
$this->dispatcher->expects($this->exactly(6))
|
||||
->method('dispatchTyped')
|
||||
->withConsecutive(
|
||||
['OCP\Share::preUnshare',
|
||||
$this->callBack(function (GenericEvent $e) use ($share1) {
|
||||
return $e->getSubject() === $share1;
|
||||
})],
|
||||
['OCP\Share::postUnshare',
|
||||
$this->callBack(function (GenericEvent $e) use ($share1, $share2, $share3) {
|
||||
return $e->getSubject() === $share1 &&
|
||||
$e->getArgument('deletedShares') === [$share3, $share2, $share1];
|
||||
})]
|
||||
[
|
||||
$this->callBack(function (BeforeShareDeletedEvent $e) use ($share1) {
|
||||
return $e->getShare()->getId() === $share1->getId();
|
||||
})
|
||||
],
|
||||
[
|
||||
$this->callBack(function (BeforeShareDeletedEvent $e) use ($share2) {
|
||||
return $e->getShare()->getId() === $share2->getId();
|
||||
})
|
||||
],
|
||||
[
|
||||
$this->callBack(function (BeforeShareDeletedEvent $e) use ($share3) {
|
||||
return $e->getShare()->getId() === $share3->getId();
|
||||
})
|
||||
],
|
||||
[
|
||||
$this->callBack(function (ShareDeletedEvent $e) use ($share3) {
|
||||
return $e->getShare()->getId() === $share3->getId();
|
||||
})
|
||||
],
|
||||
[
|
||||
$this->callBack(function (ShareDeletedEvent $e) use ($share2) {
|
||||
return $e->getShare()->getId() === $share2->getId();
|
||||
})
|
||||
],
|
||||
[
|
||||
$this->callBack(function (ShareDeletedEvent $e) use ($share1) {
|
||||
return $e->getShare()->getId() === $share1->getId();
|
||||
})
|
||||
],
|
||||
);
|
||||
|
||||
$manager->deleteShare($share1);
|
||||
|
|
@ -395,12 +412,11 @@ class ManagerTest extends \Test\TestCase {
|
|||
->method('deleteFromSelf')
|
||||
->with($share, $recipientId);
|
||||
|
||||
$this->eventDispatcher->expects($this->once())
|
||||
->method('dispatch')
|
||||
$this->dispatcher->expects($this->once())
|
||||
->method('dispatchTyped')
|
||||
->with(
|
||||
'OCP\Share::postUnshareFromSelf',
|
||||
$this->callBack(function (GenericEvent $e) use ($share) {
|
||||
return $e->getSubject() === $share;
|
||||
$this->callBack(function (ShareDeletedFromSelfEvent $e) use ($share) {
|
||||
return $e->getShare() === $share;
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -2317,14 +2333,13 @@ class ManagerTest extends \Test\TestCase {
|
|||
return $share->setId(42);
|
||||
});
|
||||
|
||||
$this->eventDispatcher->expects($this->exactly(2))
|
||||
->method('dispatch')
|
||||
$this->dispatcher->expects($this->exactly(2))
|
||||
->method('dispatchTyped')
|
||||
->withConsecutive(
|
||||
// Pre share
|
||||
[$this->equalTo('OCP\Share::preShare'),
|
||||
$this->callback(function (GenericEvent $e) use ($path, $date) {
|
||||
/** @var IShare $share */
|
||||
$share = $e->getSubject();
|
||||
[
|
||||
$this->callback(function (BeforeShareCreatedEvent $e) use ($path, $date) {
|
||||
$share = $e->getShare();
|
||||
|
||||
return $share->getShareType() === IShare::TYPE_LINK &&
|
||||
$share->getNode() === $path &&
|
||||
|
|
@ -2333,12 +2348,12 @@ class ManagerTest extends \Test\TestCase {
|
|||
$share->getExpirationDate() === $date &&
|
||||
$share->getPassword() === 'hashed' &&
|
||||
$share->getToken() === 'token';
|
||||
})],
|
||||
})
|
||||
],
|
||||
// Post share
|
||||
[$this->equalTo('OCP\Share::postShare'),
|
||||
$this->callback(function (GenericEvent $e) use ($path, $date) {
|
||||
/** @var IShare $share */
|
||||
$share = $e->getSubject();
|
||||
[
|
||||
$this->callback(function (ShareCreatedEvent $e) use ($path, $date) {
|
||||
$share = $e->getShare();
|
||||
|
||||
return $share->getShareType() === IShare::TYPE_LINK &&
|
||||
$share->getNode() === $path &&
|
||||
|
|
@ -2349,7 +2364,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$share->getToken() === 'token' &&
|
||||
$share->getId() === '42' &&
|
||||
$share->getTarget() === '/target';
|
||||
})]
|
||||
})
|
||||
]
|
||||
);
|
||||
|
||||
/** @var IShare $share */
|
||||
|
|
@ -2424,13 +2440,12 @@ class ManagerTest extends \Test\TestCase {
|
|||
return $share->setId(42);
|
||||
});
|
||||
|
||||
$this->eventDispatcher->expects($this->exactly(2))
|
||||
->method('dispatch')
|
||||
$this->dispatcher->expects($this->exactly(2))
|
||||
->method('dispatchTyped')
|
||||
->withConsecutive(
|
||||
[$this->equalTo('OCP\Share::preShare'),
|
||||
$this->callback(function (GenericEvent $e) use ($path) {
|
||||
/** @var IShare $share */
|
||||
$share = $e->getSubject();
|
||||
[
|
||||
$this->callback(function (BeforeShareCreatedEvent $e) use ($path) {
|
||||
$share = $e->getShare();
|
||||
|
||||
return $share->getShareType() === IShare::TYPE_EMAIL &&
|
||||
$share->getNode() === $path &&
|
||||
|
|
@ -2439,11 +2454,11 @@ class ManagerTest extends \Test\TestCase {
|
|||
$share->getExpirationDate() === null &&
|
||||
$share->getPassword() === null &&
|
||||
$share->getToken() === 'token';
|
||||
})],
|
||||
[$this->equalTo('OCP\Share::postShare'),
|
||||
$this->callback(function (GenericEvent $e) use ($path) {
|
||||
/** @var IShare $share */
|
||||
$share = $e->getSubject();
|
||||
})
|
||||
],
|
||||
[
|
||||
$this->callback(function (ShareCreatedEvent $e) use ($path) {
|
||||
$share = $e->getShare();
|
||||
|
||||
return $share->getShareType() === IShare::TYPE_EMAIL &&
|
||||
$share->getNode() === $path &&
|
||||
|
|
@ -2454,7 +2469,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$share->getToken() === 'token' &&
|
||||
$share->getId() === '42' &&
|
||||
$share->getTarget() === '/target';
|
||||
})],
|
||||
})
|
||||
],
|
||||
);
|
||||
|
||||
/** @var IShare $share */
|
||||
|
|
@ -2521,13 +2537,12 @@ class ManagerTest extends \Test\TestCase {
|
|||
->with('/target');
|
||||
|
||||
// Pre share
|
||||
$this->eventDispatcher->expects($this->once())
|
||||
->method('dispatch')
|
||||
$this->dispatcher->expects($this->once())
|
||||
->method('dispatchTyped')
|
||||
->with(
|
||||
$this->equalTo('OCP\Share::preShare'),
|
||||
$this->isInstanceOf(GenericEvent::class)
|
||||
)->willReturnCallback(function ($name, GenericEvent $e) {
|
||||
$e->setArgument('error', 'I won\'t let you share!');
|
||||
$this->isInstanceOf(BeforeShareCreatedEvent::class)
|
||||
)->willReturnCallback(function (BeforeShareCreatedEvent $e) {
|
||||
$e->setError('I won\'t let you share!');
|
||||
$e->stopPropagation();
|
||||
}
|
||||
);
|
||||
|
|
@ -2733,7 +2748,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
|
|
@ -2779,7 +2793,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
|
|
@ -2832,7 +2845,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
|
|
@ -4174,7 +4186,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
|
|
@ -4209,7 +4220,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
|
|
@ -4275,7 +4285,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
|
|
@ -4393,7 +4402,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
|
|
@ -4520,7 +4528,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
|
|
|
|||
Loading…
Reference in a new issue