Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c8c8f93
Move createSubscription and deleteSubscription event handlers to
tcitworld Dec 17, 2021
bfdfd3e
Remove uses of LegacyDispatcher for create/delete subscriptions
tcitworld Dec 17, 2021
dfa2cc3
Move every event to listeners and remove all uses of legacy dispatcher
tcitworld Dec 17, 2021
10af3ab
Add tests for new Listeners
tcitworld Dec 17, 2021
180e695
Remove usages of legacyDispatcher in CardDAVBackend
tcitworld Dec 19, 2021
ab07629
Update some depreciated calls
tcitworld Dec 19, 2021
08abaae
Fix doctype of param passed to deleteContact
tcitworld Dec 19, 2021
4827bc7
Improve OCA\DAV\Connector\Sabre\Principal
tcitworld Dec 19, 2021
aa7994f
Improve OCA\DAV\Tests\unit\CardDAV\AddressBookImplTest
tcitworld Dec 19, 2021
3a3a1a0
Move uses of ILogger to LoggerInterface
tcitworld Dec 19, 2021
fed15f9
Move some events to IEventDispatcher
tcitworld Dec 19, 2021
c304561
Replace calls to Sabre's depreciated getPropertiesForPath with getPro…
tcitworld Jan 16, 2022
981b99c
Remove more depreciated calls
tcitworld Jan 20, 2022
dcc9c70
Remove HookManager and replace with UserChangeListener
tcitworld Jan 20, 2022
7a5f4af
Modernize endpoints
tcitworld Jan 20, 2022
d739f92
Modernize Sabre Connector
tcitworld Jan 20, 2022
244aaa7
Add @template-implements metadata for listeners
tcitworld Jan 20, 2022
57ddf28
Remove CalendarManager registration
tcitworld Jan 20, 2022
fccc89d
Various fixes
tcitworld Jan 20, 2022
041526d
Improve tests
tcitworld Jan 26, 2022
3d42336
Improve CommentsEntityEvent
tcitworld Jan 26, 2022
9246d06
Use PHP 7.4 typed properties
tcitworld Feb 14, 2022
6d6008d
Rebasing, cs and more typing
tcitworld Mar 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move some events to IEventDispatcher
Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld committed Mar 31, 2022
commit fed15f9e1e2986ac3431744fa86419633dc84f6a
2 changes: 1 addition & 1 deletion apps/comments/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function register(IRegistrationContext $context): void {
LoadSidebarScripts::class
);
$context->registerEventListener(
CommentsEntityEvent::EVENT_ENTITY,
CommentsEntityEvent::class,
CommentsEntityEventListener::class
);
$context->registerSearchProvider(CommentsSearchProvider::class);
Expand Down
4 changes: 4 additions & 0 deletions apps/dav/appinfo/v1/webdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*
*/
// no php execution timeout for webdav
use OCA\DAV\Events\SabreAddPluginEvent;

if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
@set_time_limit(0);
}
Expand Down Expand Up @@ -75,7 +77,9 @@
});

$dispatcher = \OC::$server->getEventDispatcher();
$newDispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
// allow setup of additional plugins
$newDispatcher->dispatchTyped(new SabreAddPluginEvent($server));
$event = new \OCP\SabrePluginEvent($server);
$dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);

Expand Down
12 changes: 6 additions & 6 deletions apps/dav/lib/Comments/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

use OCP\Comments\CommentsEntityEvent;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUserManager;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotAuthenticated;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class RootCollection implements ICollection {

Expand All @@ -55,21 +55,21 @@ class RootCollection implements ICollection {
/** @var IUserSession */
protected $userSession;

/** @var EventDispatcherInterface */
/** @var IEventDispatcher */
protected $dispatcher;

/**
* @param ICommentsManager $commentsManager
* @param IUserManager $userManager
* @param IUserSession $userSession
* @param EventDispatcherInterface $dispatcher
* @param IEventDispatcher $dispatcher
* @param LoggerInterface $logger
*/
public function __construct(
ICommentsManager $commentsManager,
IUserManager $userManager,
IUserSession $userSession,
EventDispatcherInterface $dispatcher,
IEventDispatcher $dispatcher,
LoggerInterface $logger) {
$this->commentsManager = $commentsManager;
$this->logger = $logger;
Expand All @@ -94,8 +94,8 @@ protected function initCollections() {
throw new NotAuthenticated();
}

$event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY);
$this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
$event = new CommentsEntityEvent(CommentsEntityEvent::class);
$this->dispatcher->dispatchTyped($event);

$this->entityTypeCollections = [];
foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
Expand Down
10 changes: 6 additions & 4 deletions apps/dav/lib/Connector/Sabre/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCA\DAV\Files\BrowserErrorPagePlugin;
use OCP\App\IAppManager;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Mount\IMountManager;
use OCP\IConfig;
use OCP\IDBConnection;
Expand All @@ -51,7 +52,6 @@
use OCP\SystemTag\ISystemTagObjectMapper;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Auth\Plugin;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class ServerFactory {
/** @var IConfig */
Expand All @@ -70,7 +70,7 @@ class ServerFactory {
private $request;
/** @var IPreview */
private $previewManager;
/** @var EventDispatcherInterface */
/** @var IEventDispatcher */
private $eventDispatcher;
/** @var IL10N */
private $l10n;
Expand All @@ -84,6 +84,8 @@ class ServerFactory {
* @param ITagManager $tagManager
* @param IRequest $request
* @param IPreview $previewManager
* @param IEventDispatcher $eventDispatcher
* @param IL10N $l10n
*/
public function __construct(
IConfig $config,
Expand All @@ -94,7 +96,7 @@ public function __construct(
ITagManager $tagManager,
IRequest $request,
IPreview $previewManager,
EventDispatcherInterface $eventDispatcher,
IEventDispatcher $eventDispatcher,
IL10N $l10n
) {
$this->config = $config;
Expand Down Expand Up @@ -222,7 +224,7 @@ public function createServer($baseUri,

// Load dav plugins from apps
$event = new SabrePluginEvent($server);
$this->eventDispatcher->dispatch($event);
$this->eventDispatcher->dispatchTyped($event);
$pluginManager = new PluginManager(
\OC::$server,
\OC::$server->get(IAppManager::class)
Expand Down
55 changes: 55 additions & 0 deletions apps/dav/lib/Events/SabreAddPluginEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2021, Thomas Citharel <[email protected]>
*
* @author Thomas Citharel <[email protected]>
*
* @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\DAV\Events;

use OCP\EventDispatcher\Event;
use Sabre\DAV\Server;

/**
* This event is triggered during the setup of the SabreDAV server to allow the
* registration of additional Sabre plugins
*
* @since 24.0.0
*/
class SabreAddPluginEvent extends Event {

/** @var Server */
private $server;

/**
* @since 20.0.0
*/
public function __construct(Server $server) {
$this->server = $server;
}

/**
* @since 20.0.0
*/
public function getServer(): Server {
return $this->server;
}
}
1 change: 0 additions & 1 deletion apps/dav/lib/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*/
namespace OCA\DAV;

use OC\EventDispatcher\SymfonyAdapter;
use OC\KnownUser\KnownUserService;
use OCA\DAV\AppInfo\PluginManager;
use OCA\DAV\CalDAV\CalDavBackend;
Expand Down
6 changes: 3 additions & 3 deletions apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\Diagnostics\IEventLogger;
use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager;
use OC\Security\Bruteforce\Throttler;
use OCA\DAV\Events\SabreAddPluginEvent;
use OCP\App\IAppManager;
use OCP\Comments\ICommentsManager;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -87,7 +88,6 @@
use OCA\DAV\Upload\ChunkingPlugin;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest;
use OCP\SabrePluginEvent;
use Sabre\CardDAV\VCFExportPlugin;
use Sabre\DAV\Auth\Plugin;
use Sabre\DAV\UUIDUtil;
Expand Down Expand Up @@ -138,8 +138,6 @@ public function __construct(IRequest $request, $baseUri) {
$this->server->addPlugin($authPlugin);

// allow setup of additional auth backends
$event = new SabrePluginEvent($this->server);
$dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);

$newAuthEvent = new SabrePluginAuthInitEvent($this->server);
$newDispatcher->dispatchTyped($newAuthEvent);
Expand Down Expand Up @@ -226,6 +224,8 @@ public function __construct(IRequest $request, $baseUri) {
$this->server->addPlugin(new ChunkingPlugin());

// allow setup of additional plugins
$newDispatcher->dispatchTyped(new SabreAddPluginEvent($this->server));
$event = new \OCP\SabrePluginEvent($this->server);
$dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);

// Some WebDAV clients do require Class 2 WebDAV support (locking), since
Expand Down
8 changes: 4 additions & 4 deletions apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
*/
namespace OCA\DAV\SystemTag;

use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\IUserSession;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\SystemTag\SystemTagsEntityEvent;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\SimpleCollection;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class SystemTagsRelationsCollection extends SimpleCollection {

Expand All @@ -44,14 +44,14 @@ class SystemTagsRelationsCollection extends SimpleCollection {
* @param ISystemTagObjectMapper $tagMapper
* @param IUserSession $userSession
* @param IGroupManager $groupManager
* @param EventDispatcherInterface $dispatcher
* @param IEventDispatcher $dispatcher
*/
public function __construct(
ISystemTagManager $tagManager,
ISystemTagObjectMapper $tagMapper,
IUserSession $userSession,
IGroupManager $groupManager,
EventDispatcherInterface $dispatcher
IEventDispatcher $dispatcher
) {
$children = [
new SystemTagsObjectTypeCollection(
Expand All @@ -68,7 +68,7 @@ function ($name) {
];

$event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY);
$dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event);
$dispatcher->dispatchTyped($event);

foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
$children[] = new SystemTagsObjectTypeCollection(
Expand Down
18 changes: 6 additions & 12 deletions apps/dav/tests/unit/Comments/RootCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
*/
namespace OCA\DAV\Tests\unit\Comments;

use OC\EventDispatcher\EventDispatcher;
use OC\EventDispatcher\SymfonyAdapter;
use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation;
use OCP\Comments\CommentsEntityEvent;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
Expand Down Expand Up @@ -72,21 +71,16 @@ protected function setUp(): void {
$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
$this->dispatcher = new SymfonyAdapter(
new EventDispatcher(
new \Symfony\Component\EventDispatcher\EventDispatcher(),
\OC::$server,
$this->logger
),
$this->logger
);
$this->dispatcher = $this->getMockBuilder(IEventDispatcher::class)
->disableOriginalConstructor()
->getMock();

$this->collection = new \OCA\DAV\Comments\RootCollection(
$this->commentsManager,
$this->userManager,
$this->userSession,
$this->dispatcher,
$this->createMock(ILogger::class)
$this->logger
);
}

Expand All @@ -99,7 +93,7 @@ protected function prepareForInitCollections() {
->method('getUser')
->willReturn($this->user);

$this->dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) {
$this->dispatcher->addListener(CommentsEntityEvent::class, function (CommentsEntityEvent $event) {
$event->addEntityCollection('files', function () {
return true;
});
Expand Down