Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2022-06-10 16:57:35 +0300
committerGitHub <noreply@github.com>2022-06-10 16:57:35 +0300
commit8e61671b828ec5b963bf9e05ed6f6c443b933af2 (patch)
treee6d246a032fda878b33dfce753ab81062c946ba1 /apps
parent148498bba574587d66bc18c0f1685ec5e332f3ba (diff)
parent28b0da59ce84eec55d3e6f38fe64ea40560cc0df (diff)
Merge pull request #32364 from nextcloud/dav-listeners
🧹 Remove all legacy event dispatchers from CalDAV & CardDAV backends
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/appinfo/v1/caldav.php2
-rw-r--r--apps/dav/appinfo/v1/carddav.php3
-rw-r--r--apps/dav/composer/composer/autoload_classmap.php5
-rw-r--r--apps/dav/composer/composer/autoload_static.php5
-rw-r--r--apps/dav/lib/AppInfo/Application.php114
-rw-r--r--apps/dav/lib/CalDAV/Activity/Backend.php2
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php117
-rw-r--r--apps/dav/lib/CardDAV/AddressBookImpl.php3
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php60
-rw-r--r--apps/dav/lib/Command/CreateCalendar.php2
-rw-r--r--apps/dav/lib/Events/CalendarPublishedEvent.php13
-rw-r--r--apps/dav/lib/Events/CalendarUnpublishedEvent.php9
-rw-r--r--apps/dav/lib/Listener/BirthdayListener.php54
-rw-r--r--apps/dav/lib/Listener/CalendarPublicationListener.php65
-rw-r--r--apps/dav/lib/Listener/CalendarShareUpdateListener.php62
-rw-r--r--apps/dav/lib/Listener/ClearPhotoCacheListener.php48
-rw-r--r--apps/dav/lib/Listener/SubscriptionListener.php85
-rw-r--r--apps/dav/lib/RootCollection.php7
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php8
-rw-r--r--apps/dav/tests/unit/CalDAV/CalDavBackendTest.php3
-rw-r--r--apps/dav/tests/unit/CalDAV/Listener/CalendarPublicationListenerTest.php79
-rw-r--r--apps/dav/tests/unit/CalDAV/Listener/CalendarShareUpdateListenerTest.php70
-rw-r--r--apps/dav/tests/unit/CalDAV/Listener/SubscriptionListenerTest.php95
-rw-r--r--apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php3
-rw-r--r--apps/dav/tests/unit/CardDAV/CardDavBackendTest.php66
25 files changed, 648 insertions, 332 deletions
diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php
index 6a496a992e6..1961df5f62b 100644
--- a/apps/dav/appinfo/v1/caldav.php
+++ b/apps/dav/appinfo/v1/caldav.php
@@ -61,7 +61,6 @@ $userManager = \OC::$server->getUserManager();
$random = \OC::$server->getSecureRandom();
$logger = \OC::$server->get(LoggerInterface::class);
$dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
-$legacyDispatcher = \OC::$server->getEventDispatcher();
$config = \OC::$server->get(\OCP\IConfig::class);
$calDavBackend = new CalDavBackend(
@@ -72,7 +71,6 @@ $calDavBackend = new CalDavBackend(
$random,
$logger,
$dispatcher,
- $legacyDispatcher,
$config,
true
);
diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php
index a0306118781..afb4c78f5f9 100644
--- a/apps/dav/appinfo/v1/carddav.php
+++ b/apps/dav/appinfo/v1/carddav.php
@@ -8,6 +8,7 @@
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @license AGPL-3.0
@@ -60,7 +61,7 @@ $principalBackend = new Principal(
'principals/'
);
$db = \OC::$server->getDatabaseConnection();
-$cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->getEventDispatcher());
+$cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class));
$debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php
index 3ff76788403..f40917fbd01 100644
--- a/apps/dav/composer/composer/autoload_classmap.php
+++ b/apps/dav/composer/composer/autoload_classmap.php
@@ -236,10 +236,15 @@ return array(
'OCA\\DAV\\HookManager' => $baseDir . '/../lib/HookManager.php',
'OCA\\DAV\\Listener\\ActivityUpdaterListener' => $baseDir . '/../lib/Listener/ActivityUpdaterListener.php',
'OCA\\DAV\\Listener\\AddressbookListener' => $baseDir . '/../lib/Listener/AddressbookListener.php',
+ 'OCA\\DAV\\Listener\\BirthdayListener' => $baseDir . '/../lib/Listener/BirthdayListener.php',
'OCA\\DAV\\Listener\\CalendarContactInteractionListener' => $baseDir . '/../lib/Listener/CalendarContactInteractionListener.php',
'OCA\\DAV\\Listener\\CalendarDeletionDefaultUpdaterListener' => $baseDir . '/../lib/Listener/CalendarDeletionDefaultUpdaterListener.php',
'OCA\\DAV\\Listener\\CalendarObjectReminderUpdaterListener' => $baseDir . '/../lib/Listener/CalendarObjectReminderUpdaterListener.php',
+ 'OCA\\DAV\\Listener\\CalendarPublicationListener' => $baseDir . '/../lib/Listener/CalendarPublicationListener.php',
+ 'OCA\\DAV\\Listener\\CalendarShareUpdateListener' => $baseDir . '/../lib/Listener/CalendarShareUpdateListener.php',
'OCA\\DAV\\Listener\\CardListener' => $baseDir . '/../lib/Listener/CardListener.php',
+ 'OCA\\DAV\\Listener\\ClearPhotoCacheListener' => $baseDir . '/../lib/Listener/ClearPhotoCacheListener.php',
+ 'OCA\\DAV\\Listener\\SubscriptionListener' => $baseDir . '/../lib/Listener/SubscriptionListener.php',
'OCA\\DAV\\Migration\\BuildCalendarSearchIndex' => $baseDir . '/../lib/Migration/BuildCalendarSearchIndex.php',
'OCA\\DAV\\Migration\\BuildCalendarSearchIndexBackgroundJob' => $baseDir . '/../lib/Migration/BuildCalendarSearchIndexBackgroundJob.php',
'OCA\\DAV\\Migration\\BuildSocialSearchIndex' => $baseDir . '/../lib/Migration/BuildSocialSearchIndex.php',
diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php
index 8bde133122a..60b437c9fac 100644
--- a/apps/dav/composer/composer/autoload_static.php
+++ b/apps/dav/composer/composer/autoload_static.php
@@ -251,10 +251,15 @@ class ComposerStaticInitDAV
'OCA\\DAV\\HookManager' => __DIR__ . '/..' . '/../lib/HookManager.php',
'OCA\\DAV\\Listener\\ActivityUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/ActivityUpdaterListener.php',
'OCA\\DAV\\Listener\\AddressbookListener' => __DIR__ . '/..' . '/../lib/Listener/AddressbookListener.php',
+ 'OCA\\DAV\\Listener\\BirthdayListener' => __DIR__ . '/..' . '/../lib/Listener/BirthdayListener.php',
'OCA\\DAV\\Listener\\CalendarContactInteractionListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarContactInteractionListener.php',
'OCA\\DAV\\Listener\\CalendarDeletionDefaultUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarDeletionDefaultUpdaterListener.php',
'OCA\\DAV\\Listener\\CalendarObjectReminderUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarObjectReminderUpdaterListener.php',
+ 'OCA\\DAV\\Listener\\CalendarPublicationListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarPublicationListener.php',
+ 'OCA\\DAV\\Listener\\CalendarShareUpdateListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarShareUpdateListener.php',
'OCA\\DAV\\Listener\\CardListener' => __DIR__ . '/..' . '/../lib/Listener/CardListener.php',
+ 'OCA\\DAV\\Listener\\ClearPhotoCacheListener' => __DIR__ . '/..' . '/../lib/Listener/ClearPhotoCacheListener.php',
+ 'OCA\\DAV\\Listener\\SubscriptionListener' => __DIR__ . '/..' . '/../lib/Listener/SubscriptionListener.php',
'OCA\\DAV\\Migration\\BuildCalendarSearchIndex' => __DIR__ . '/..' . '/../lib/Migration/BuildCalendarSearchIndex.php',
'OCA\\DAV\\Migration\\BuildCalendarSearchIndexBackgroundJob' => __DIR__ . '/..' . '/../lib/Migration/BuildCalendarSearchIndexBackgroundJob.php',
'OCA\\DAV\\Migration\\BuildSocialSearchIndex' => __DIR__ . '/..' . '/../lib/Migration/BuildSocialSearchIndex.php',
diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php
index 580918a6450..e4eeed61dbe 100644
--- a/apps/dav/lib/AppInfo/Application.php
+++ b/apps/dav/lib/AppInfo/Application.php
@@ -35,18 +35,14 @@ namespace OCA\DAV\AppInfo;
use Exception;
use OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob;
use OCA\DAV\CalDAV\Activity\Backend;
-use OCA\DAV\CalDAV\BirthdayService;
-use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\CalendarManager;
use OCA\DAV\CalDAV\CalendarProvider;
-use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\AudioProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
use OCA\DAV\CalDAV\Reminder\Notifier;
-use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
use OCA\DAV\Capabilities;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\ContactsManager;
@@ -64,19 +60,28 @@ use OCA\DAV\Events\CalendarObjectDeletedEvent;
use OCA\DAV\Events\CalendarObjectMovedToTrashEvent;
use OCA\DAV\Events\CalendarObjectRestoredEvent;
use OCA\DAV\Events\CalendarObjectUpdatedEvent;
+use OCA\DAV\Events\CalendarPublishedEvent;
use OCA\DAV\Events\CalendarRestoredEvent;
use OCA\DAV\Events\CalendarShareUpdatedEvent;
+use OCA\DAV\Events\CalendarUnpublishedEvent;
use OCA\DAV\Events\CalendarUpdatedEvent;
use OCA\DAV\Events\CardCreatedEvent;
use OCA\DAV\Events\CardDeletedEvent;
use OCA\DAV\Events\CardUpdatedEvent;
+use OCA\DAV\Events\SubscriptionCreatedEvent;
+use OCA\DAV\Events\SubscriptionDeletedEvent;
use OCA\DAV\HookManager;
use OCA\DAV\Listener\ActivityUpdaterListener;
use OCA\DAV\Listener\AddressbookListener;
+use OCA\DAV\Listener\BirthdayListener;
use OCA\DAV\Listener\CalendarContactInteractionListener;
use OCA\DAV\Listener\CalendarDeletionDefaultUpdaterListener;
use OCA\DAV\Listener\CalendarObjectReminderUpdaterListener;
+use OCA\DAV\Listener\CalendarPublicationListener;
+use OCA\DAV\Listener\CalendarShareUpdateListener;
use OCA\DAV\Listener\CardListener;
+use OCA\DAV\Listener\ClearPhotoCacheListener;
+use OCA\DAV\Listener\SubscriptionListener;
use OCA\DAV\Search\ContactsSearchProvider;
use OCA\DAV\Search\EventsSearchProvider;
use OCA\DAV\Search\TasksSearchProvider;
@@ -154,6 +159,12 @@ class Application extends App implements IBootstrap {
$context->registerEventListener(CalendarObjectRestoredEvent::class, ActivityUpdaterListener::class);
$context->registerEventListener(CalendarObjectRestoredEvent::class, CalendarObjectReminderUpdaterListener::class);
$context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarContactInteractionListener::class);
+ $context->registerEventListener(CalendarPublishedEvent::class, CalendarPublicationListener::class);
+ $context->registerEventListener(CalendarUnpublishedEvent::class, CalendarPublicationListener::class);
+ $context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarShareUpdateListener::class);
+
+ $context->registerEventListener(SubscriptionCreatedEvent::class, SubscriptionListener::class);
+ $context->registerEventListener(SubscriptionDeletedEvent::class, SubscriptionListener::class);
$context->registerEventListener(AddressBookCreatedEvent::class, AddressbookListener::class);
@@ -163,6 +174,11 @@ class Application extends App implements IBootstrap {
$context->registerEventListener(CardCreatedEvent::class, CardListener::class);
$context->registerEventListener(CardDeletedEvent::class, CardListener::class);
$context->registerEventListener(CardUpdatedEvent::class, CardListener::class);
+ $context->registerEventListener(CardCreatedEvent::class, BirthdayListener::class);
+ $context->registerEventListener(CardDeletedEvent::class, BirthdayListener::class);
+ $context->registerEventListener(CardUpdatedEvent::class, BirthdayListener::class);
+ $context->registerEventListener(CardDeletedEvent::class, ClearPhotoCacheListener::class);
+ $context->registerEventListener(CardUpdatedEvent::class, ClearPhotoCacheListener::class);
$context->registerNotifierService(Notifier::class);
@@ -195,44 +211,6 @@ class Application extends App implements IBootstrap {
}
});
- $birthdayListener = function ($event) use ($container): void {
- if ($event instanceof GenericEvent) {
- /** @var BirthdayService $b */
- $b = $container->query(BirthdayService::class);
- $b->onCardChanged(
- (int) $event->getArgument('addressBookId'),
- (string) $event->getArgument('cardUri'),
- (string) $event->getArgument('cardData')
- );
- }
- };
-
- $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener);
- $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener);
- $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) use ($container) {
- if ($event instanceof GenericEvent) {
- /** @var BirthdayService $b */
- $b = $container->query(BirthdayService::class);
- $b->onCardDeleted(
- (int) $event->getArgument('addressBookId'),
- (string) $event->getArgument('cardUri')
- );
- }
- });
-
- $clearPhotoCache = function ($event) use ($container): void {
- if ($event instanceof GenericEvent) {
- /** @var PhotoCache $p */
- $p = $container->query(PhotoCache::class);
- $p->delete(
- $event->getArgument('addressBookId'),
- $event->getArgument('cardUri')
- );
- }
- };
- $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
- $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
-
$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($container) {
$user = $event->getSubject();
/** @var SyncService $syncService */
@@ -254,16 +232,6 @@ class Application extends App implements IBootstrap {
// Here we should recalculate if reminders should be sent to new or old sharees
});
- $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) use ($container) {
- /** @var Backend $backend */
- $backend = $container->query(Backend::class);
- $backend->onCalendarPublication(
- $event->getArgument('calendarData'),
- $event->getArgument('public')
- );
- });
-
-
$dispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
function (GenericEvent $event) {
/** @var CardDavBackend $cardDavBackend */
@@ -276,48 +244,6 @@ class Application extends App implements IBootstrap {
}
);
- $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createSubscription',
- function (GenericEvent $event) use ($container, $serverContainer) {
- $jobList = $serverContainer->getJobList();
- $subscriptionData = $event->getArgument('subscriptionData');
-
- /**
- * Initial subscription refetch
- *
- * @var RefreshWebcalService $refreshWebcalService
- */
- $refreshWebcalService = $container->query(RefreshWebcalService::class);
- $refreshWebcalService->refreshSubscription(
- (string) $subscriptionData['principaluri'],
- (string) $subscriptionData['uri']
- );
-
- $jobList->add(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
- 'principaluri' => $subscriptionData['principaluri'],
- 'uri' => $subscriptionData['uri']
- ]);
- }
- );
-
- $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription',
- function (GenericEvent $event) use ($container, $serverContainer) {
- $jobList = $serverContainer->getJobList();
- $subscriptionData = $event->getArgument('subscriptionData');
-
- $jobList->remove(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
- 'principaluri' => $subscriptionData['principaluri'],
- 'uri' => $subscriptionData['uri']
- ]);
-
- /** @var CalDavBackend $calDavBackend */
- $calDavBackend = $container->get(CalDavBackend::class);
- $calDavBackend->purgeAllCachedEventsForSubscription($subscriptionData['id']);
- /** @var ReminderBackend $calDavBackend */
- $reminderBackend = $container->get(ReminderBackend::class);
- $reminderBackend->cleanRemindersForCalendar((int) $subscriptionData['id']);
- }
- );
-
$eventHandler = function () use ($container, $serverContainer): void {
try {
/** @var UpdateCalendarResourcesRoomsBackgroundJob $job */
diff --git a/apps/dav/lib/CalDAV/Activity/Backend.php b/apps/dav/lib/CalDAV/Activity/Backend.php
index 84ba50b8c37..af2d790e10d 100644
--- a/apps/dav/lib/CalDAV/Activity/Backend.php
+++ b/apps/dav/lib/CalDAV/Activity/Backend.php
@@ -119,7 +119,7 @@ class Backend {
* @param array $calendarData
* @param bool $publishStatus
*/
- public function onCalendarPublication(array $calendarData, $publishStatus) {
+ public function onCalendarPublication(array $calendarData, bool $publishStatus): void {
$this->triggerCalendarActivity($publishStatus ? Calendar::SUBJECT_PUBLISH : Calendar::SUBJECT_UNPUBLISH, $calendarData);
}
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index 8bdc084cd7b..f445382ce8c 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -95,8 +95,6 @@ use Sabre\VObject\ParseException;
use Sabre\VObject\Property;
use Sabre\VObject\Reader;
use Sabre\VObject\Recur\EventIterator;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
use function array_column;
use function array_merge;
use function array_values;
@@ -150,7 +148,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @var array
* @psalm-var array<string, string[]>
*/
- public $propertyMap = [
+ public array $propertyMap = [
'{DAV:}displayname' => ['displayname', 'string'],
'{urn:ietf:params:xml:ns:caldav}calendar-description' => ['description', 'string'],
'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => ['timezone', 'string'],
@@ -164,7 +162,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
*
* @var array
*/
- public $subscriptionPropertyMap = [
+ public array $subscriptionPropertyMap = [
'{DAV:}displayname' => ['displayname', 'string'],
'{http://apple.com/ns/ical/}refreshrate' => ['refreshrate', 'string'],
'{http://apple.com/ns/ical/}calendar-order' => ['calendarorder', 'int'],
@@ -195,7 +193,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
];
/** @var array parameters to index */
- public static $indexParameters = [
+ public static array $indexParameters = [
'ATTENDEE' => ['CN'],
'ORGANIZER' => ['CN'],
];
@@ -203,43 +201,19 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
/**
* @var string[] Map of uid => display name
*/
- protected $userDisplayNames;
-
- /** @var IDBConnection */
- private $db;
-
- /** @var Backend */
- private $calendarSharingBackend;
-
- /** @var Principal */
- private $principalBackend;
-
- /** @var IUserManager */
- private $userManager;
-
- /** @var ISecureRandom */
- private $random;
+ protected array $userDisplayNames;
+ private IDBConnection $db;
+ private Backend $calendarSharingBackend;
+ private Principal $principalBackend;
+ private IUserManager $userManager;
+ private ISecureRandom $random;
private LoggerInterface $logger;
+ private IEventDispatcher $dispatcher;
+ private IConfig $config;
+ private bool $legacyEndpoint;
+ private string $dbObjectPropertiesTable = 'calendarobjects_props';
- /** @var IEventDispatcher */
- private $dispatcher;
-
- /** @var EventDispatcherInterface */
- private $legacyDispatcher;
-
- /** @var IConfig */
- private $config;
-
- /** @var bool */
- private $legacyEndpoint;
-
- /** @var string */
- private $dbObjectPropertiesTable = 'calendarobjects_props';
-
- /**
- * CalDavBackend constructor.
- */
public function __construct(IDBConnection $db,
Principal $principalBackend,
IUserManager $userManager,
@@ -247,7 +221,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
ISecureRandom $random,
LoggerInterface $logger,
IEventDispatcher $dispatcher,
- EventDispatcherInterface $legacyDispatcher,
IConfig $config,
bool $legacyEndpoint = false) {
$this->db = $db;
@@ -257,7 +230,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$this->random = $random;
$this->logger = $logger;
$this->dispatcher = $dispatcher;
- $this->legacyDispatcher = $legacyDispatcher;
$this->config = $config;
$this->legacyEndpoint = $legacyEndpoint;
}
@@ -1301,15 +1273,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$subscriptionRow = $this->getSubscriptionById($calendarId);
$this->dispatcher->dispatchTyped(new CachedCalendarObjectCreatedEvent((int)$calendarId, $subscriptionRow, [], $objectRow));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCachedCalendarObject', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::createCachedCalendarObject',
- [
- 'subscriptionId' => $calendarId,
- 'calendarData' => $subscriptionRow,
- 'shares' => [],
- 'objectData' => $objectRow,
- ]
- ));
}
return '"' . $extraData['etag'] . '"';
@@ -1366,15 +1329,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$subscriptionRow = $this->getSubscriptionById($calendarId);
$this->dispatcher->dispatchTyped(new CachedCalendarObjectUpdatedEvent((int)$calendarId, $subscriptionRow, [], $objectRow));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCachedCalendarObject', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::updateCachedCalendarObject',
- [
- 'subscriptionId' => $calendarId,
- 'calendarData' => $subscriptionRow,
- 'shares' => [],
- 'objectData' => $objectRow,
- ]
- ));
}
}
@@ -1482,15 +1436,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$subscriptionRow = $this->getSubscriptionById($calendarId);
$this->dispatcher->dispatchTyped(new CachedCalendarObjectDeletedEvent((int)$calendarId, $subscriptionRow, [], $data));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCachedCalendarObject', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::deleteCachedCalendarObject',
- [
- 'subscriptionId' => $calendarId,
- 'calendarData' => $subscriptionRow,
- 'shares' => [],
- 'objectData' => $data,
- ]
- ));
}
} else {
$pathInfo = pathinfo($data['uri']);
@@ -2501,12 +2446,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$subscriptionRow = $this->getSubscriptionById($subscriptionId);
$this->dispatcher->dispatchTyped(new SubscriptionCreatedEvent($subscriptionId, $subscriptionRow));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createSubscription', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::createSubscription',
- [
- 'subscriptionId' => $subscriptionId,
- 'subscriptionData' => $subscriptionRow,
- ]));
return $subscriptionId;
}
@@ -2554,13 +2493,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$subscriptionRow = $this->getSubscriptionById($subscriptionId);
$this->dispatcher->dispatchTyped(new SubscriptionUpdatedEvent((int)$subscriptionId, $subscriptionRow, [], $mutations));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateSubscription', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::updateSubscription',
- [
- 'subscriptionId' => $subscriptionId,
- 'subscriptionData' => $subscriptionRow,
- 'propertyMutations' => $mutations,
- ]));
return true;
});
@@ -2575,13 +2507,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
public function deleteSubscription($subscriptionId) {
$subscriptionRow = $this->getSubscriptionById($subscriptionId);
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription',
- [
- 'subscriptionId' => $subscriptionId,
- 'subscriptionData' => $this->getSubscriptionById($subscriptionId),
- ]));
-
$query = $this->db->getQueryBuilder();
$query->delete('calendarsubscriptions')
->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId)))
@@ -2879,15 +2804,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$calendarRow = $this->getCalendarById($calendarId);
$oldShares = $this->getShares($calendarId);
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::updateShares',
- [
- 'calendarId' => $calendarId,
- 'calendarData' => $calendarRow,
- 'shares' => $oldShares,
- 'add' => $add,
- 'remove' => $remove,
- ]));
$this->calendarSharingBackend->updateShares($shareable, $add, $remove);
$this->dispatcher->dispatchTyped(new CalendarShareUpdatedEvent((int)$calendarId, $calendarRow, $oldShares, $add, $remove));
@@ -2909,13 +2825,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
public function setPublishStatus($value, $calendar) {
$calendarId = $calendar->getResourceId();
$calendarData = $this->getCalendarById($calendarId);
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::updateShares',
- [
- 'calendarId' => $calendarId,
- 'calendarData' => $calendarData,
- 'public' => $value,
- ]));
$query = $this->db->getQueryBuilder();
if ($value) {
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php
index 3db20cb4220..2f7f0a22900 100644
--- a/apps/dav/lib/CardDAV/AddressBookImpl.php
+++ b/apps/dav/lib/CardDAV/AddressBookImpl.php
@@ -12,6 +12,7 @@
* @author Joas Schilling <coding@schilljs.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Julius Härtl <jus@bitgrid.net>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @license AGPL-3.0
@@ -206,7 +207,7 @@ class AddressBookImpl implements IAddressBook {
}
/**
- * @param object $id the unique identifier to a contact
+ * @param int $id the unique identifier to a contact
* @return bool successful or not
* @since 5.0.0
*/
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index 864f3da9367..745ca7801b7 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -58,30 +58,19 @@ use Sabre\CardDAV\Plugin;
use Sabre\DAV\Exception\BadRequest;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Reader;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class CardDavBackend implements BackendInterface, SyncSupport {
public const PERSONAL_ADDRESSBOOK_URI = 'contacts';
public const PERSONAL_ADDRESSBOOK_NAME = 'Contacts';
- /** @var Principal */
- private $principalBackend;
-
- /** @var string */
- private $dbCardsTable = 'cards';
-
- /** @var string */
- private $dbCardsPropertiesTable = 'cards_properties';
-
- /** @var IDBConnection */
- private $db;
-
- /** @var Backend */
- private $sharingBackend;
+ private Principal $principalBackend;
+ private string $dbCardsTable = 'cards';
+ private string $dbCardsPropertiesTable = 'cards_properties';
+ private IDBConnection $db;
+ private Backend $sharingBackend;
/** @var array properties to index */
- public static $indexProperties = [
+ public static array $indexProperties = [
'BDAY', 'UID', 'N', 'FN', 'TITLE', 'ROLE', 'NOTE', 'NICKNAME',
'ORG', 'CATEGORIES', 'EMAIL', 'TEL', 'IMPP', 'ADR', 'URL', 'GEO',
'CLOUD', 'X-SOCIALPROFILE'];
@@ -89,18 +78,10 @@ class CardDavBackend implements BackendInterface, SyncSupport {
/**
* @var string[] Map of uid => display name
*/
- protected $userDisplayNames;
-
- /** @var IUserManager */
- private $userManager;
-
- /** @var IEventDispatcher */
- private $dispatcher;
-
- /** @var EventDispatcherInterface */
- private $legacyDispatcher;
-
- private $etagCache = [];
+ protected array $userDisplayNames;
+ private IUserManager $userManager;
+ private IEventDispatcher $dispatcher;
+ private array $etagCache = [];
/**
* CardDavBackend constructor.
@@ -110,19 +91,16 @@ class CardDavBackend implements BackendInterface, SyncSupport {
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IEventDispatcher $dispatcher
- * @param EventDispatcherInterface $legacyDispatcher
*/
public function __construct(IDBConnection $db,
Principal $principalBackend,
IUserManager $userManager,
IGroupManager $groupManager,
- IEventDispatcher $dispatcher,
- EventDispatcherInterface $legacyDispatcher) {
+ IEventDispatcher $dispatcher) {
$this->db = $db;
$this->principalBackend = $principalBackend;
$this->userManager = $userManager;
$this->dispatcher = $dispatcher;
- $this->legacyDispatcher = $legacyDispatcher;
$this->sharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'addressbook');
}
@@ -692,11 +670,6 @@ class CardDavBackend implements BackendInterface, SyncSupport {
$shares = $this->getShares($addressBookId);
$objectRow = $this->getCard($addressBookId, $cardUri);
$this->dispatcher->dispatchTyped(new CardCreatedEvent($addressBookId, $addressBookData, $shares, $objectRow));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::createCard',
- new GenericEvent(null, [
- 'addressBookId' => $addressBookId,
- 'cardUri' => $cardUri,
- 'cardData' => $cardData]));
return '"' . $etag . '"';
}
@@ -756,12 +729,6 @@ class CardDavBackend implements BackendInterface, SyncSupport {
$shares = $this->getShares($addressBookId);
$objectRow = $this->getCard($addressBookId, $cardUri);
$this->dispatcher->dispatchTyped(new CardUpdatedEvent($addressBookId, $addressBookData, $shares, $objectRow));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::updateCard',
- new GenericEvent(null, [
- 'addressBookId' => $addressBookId,
- 'cardUri' => $cardUri,
- 'cardData' => $cardData]));
-
return '"' . $etag . '"';
}
@@ -793,11 +760,6 @@ class CardDavBackend implements BackendInterface, SyncSupport {
if ($ret === 1) {
if ($cardId !== null) {
$this->dispatcher->dispatchTyped(new CardDeletedEvent($addressBookId, $addressBookData, $shares, $objectRow));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::deleteCard',
- new GenericEvent(null, [
- 'addressBookId' => $addressBookId,
- 'cardUri' => $cardUri]));
-
$this->purgeProperties($addressBookId, $cardId);
}
return true;
diff --git a/apps/dav/lib/Command/CreateCalendar.php b/apps/dav/lib/Command/CreateCalendar.php
index 2bea82a345e..24368e8864c 100644
--- a/apps/dav/lib/Command/CreateCalendar.php
+++ b/apps/dav/lib/Command/CreateCalendar.php
@@ -94,7 +94,6 @@ class CreateCalendar extends Command {
$random = \OC::$server->getSecureRandom();
$logger = \OC::$server->get(LoggerInterface::class);
$dispatcher = \OC::$server->get(IEventDispatcher::class);
- $legacyDispatcher = \OC::$server->getEventDispatcher();
$config = \OC::$server->get(IConfig::class);
$name = $input->getArgument('name');
@@ -106,7 +105,6 @@ class CreateCalendar extends Command {
$random,
$logger,
$dispatcher,
- $legacyDispatcher,
$config
);
$caldav->createCalendar("principals/users/$user", $name, []);
diff --git a/apps/dav/lib/Events/CalendarPublishedEvent.php b/apps/dav/lib/Events/CalendarPublishedEvent.php
index 7b3b95f2f77..a95e9f294c1 100644
--- a/apps/dav/lib/Events/CalendarPublishedEvent.php
+++ b/apps/dav/lib/Events/CalendarPublishedEvent.php
@@ -6,6 +6,7 @@ declare(strict_types=1);
* @copyright Copyright (c) 2020, Georg Ehrke
*
* @author Georg Ehrke <oc.list@georgehrke.com>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
*
* @license GNU AGPL version 3 or any later version
*
@@ -34,15 +35,9 @@ use OCP\EventDispatcher\Event;
* @since 20.0.0
*/
class CalendarPublishedEvent extends Event {
-
- /** @var int */
- private $calendarId;
-
- /** @var array */
- private $calendarData;
-
- /** @var string */
- private $publicUri;
+ private int $calendarId;
+ private array $calendarData;
+ private string $publicUri;
/**
* CalendarPublishedEvent constructor.
diff --git a/apps/dav/lib/Events/CalendarUnpublishedEvent.php b/apps/dav/lib/Events/CalendarUnpublishedEvent.php
index 0cea53c6f0d..b2536fc7aef 100644
--- a/apps/dav/lib/Events/CalendarUnpublishedEvent.php
+++ b/apps/dav/lib/Events/CalendarUnpublishedEvent.php
@@ -6,6 +6,7 @@ declare(strict_types=1);
* @copyright Copyright (c) 2020, Georg Ehrke
*
* @author Georg Ehrke <oc.list@georgehrke.com>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
*
* @license GNU AGPL version 3 or any later version
*
@@ -34,12 +35,8 @@ use OCP\EventDispatcher\Event;
* @since 20.0.0
*/
class CalendarUnpublishedEvent extends Event {
-
- /** @var int */
- private $calendarId;
-
- /** @var array */
- private $calendarData;
+ private int $calendarId;
+ private array $calendarData;
/**
* CalendarUnpublishedEvent constructor.
diff --git a/apps/dav/lib/Listener/BirthdayListener.php b/apps/dav/lib/Listener/BirthdayListener.php
new file mode 100644
index 00000000000..43ad782fa9e
--- /dev/null
+++ b/apps/dav/lib/Listener/BirthdayListener.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @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\Listener;
+
+use OCA\DAV\CalDAV\BirthdayService;
+use OCA\DAV\Events\CardCreatedEvent;
+use OCA\DAV\Events\CardDeletedEvent;
+use OCA\DAV\Events\CardUpdatedEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+class BirthdayListener implements IEventListener {
+ private BirthdayService $birthdayService;
+
+ public function __construct(BirthdayService $birthdayService) {
+ $this->birthdayService = $birthdayService;
+ }
+
+ public function handle(Event $event): void {
+ if ($event instanceof CardCreatedEvent || $event instanceof CardUpdatedEvent) {
+ $cardData = $event->getCardData();
+
+ $this->birthdayService->onCardChanged($event->getAddressBookId(), $cardData['uri'], $cardData['carddata']);
+ }
+
+ if ($event instanceof CardDeletedEvent) {
+ $cardData = $event->getCardData();
+ $this->birthdayService->onCardDeleted($event->getAddressBookId(), $cardData['uri']);
+ }
+ }
+}
diff --git a/apps/dav/lib/Listener/CalendarPublicationListener.php b/apps/dav/lib/Listener/CalendarPublicationListener.php
new file mode 100644
index 00000000000..1453694d6fb
--- /dev/null
+++ b/apps/dav/lib/Listener/CalendarPublicationListener.php
@@ -0,0 +1,65 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @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\Listener;
+
+use OCA\DAV\CalDAV\Activity\Backend;
+use OCA\DAV\Events\CalendarPublishedEvent;
+use OCA\DAV\Events\CalendarUnpublishedEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use Psr\Log\LoggerInterface;
+
+class CalendarPublicationListener implements IEventListener {
+ private Backend $activityBackend;
+ private LoggerInterface $logger;
+
+ public function __construct(Backend $activityBackend,
+ LoggerInterface $logger) {
+ $this->activityBackend = $activityBackend;
+ $this->logger = $logger;
+ }
+
+ /**
+ * In case the user has set their default calendar to the deleted one
+ */
+ public function handle(Event $event): void {
+ if ($event instanceof CalendarPublishedEvent) {
+ $this->logger->debug('Creating activity for Calendar being published');
+
+ $this->activityBackend->onCalendarPublication(
+ $event->getCalendarData(),
+ true
+ );
+ } elseif ($event instanceof CalendarUnpublishedEvent) {
+ $this->logger->debug('Creating activity for Calendar being unpublished');
+
+ $this->activityBackend->onCalendarPublication(
+ $event->getCalendarData(),
+ false
+ );
+ }
+ }
+}
diff --git a/apps/dav/lib/Listener/CalendarShareUpdateListener.php b/apps/dav/lib/Listener/CalendarShareUpdateListener.php
new file mode 100644
index 00000000000..88865759162
--- /dev/null
+++ b/apps/dav/lib/Listener/CalendarShareUpdateListener.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @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\Listener;
+
+use OCA\DAV\CalDAV\Activity\Backend;
+use OCA\DAV\Events\CalendarShareUpdatedEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use Psr\Log\LoggerInterface;
+
+class CalendarShareUpdateListener implements IEventListener {
+ private Backend $activityBackend;
+ private LoggerInterface $logger;
+
+ public function __construct(Backend $activityBackend,
+ LoggerInterface $logger) {
+ $this->activityBackend = $activityBackend;
+ $this->logger = $logger;
+ }
+
+ /**
+ * In case the user has set their default calendar to the deleted one
+ */
+ public function handle(Event $event): void {
+ if (!($event instanceof CalendarShareUpdatedEvent)) {
+ // Not what we subscribed to
+ return;
+ }
+
+ $this->logger->debug("Creating activity for Calendar having it's shares updated");
+
+ $this->activityBackend->onCalendarUpdateShares(
+ $event->getCalendarData(),
+ $event->getOldShares(),
+ $event->getAdded(),
+ $event->getRemoved()
+ );
+ }
+}
diff --git a/apps/dav/lib/Listener/ClearPhotoCacheListener.php b/apps/dav/lib/Listener/ClearPhotoCacheListener.php
new file mode 100644
index 00000000000..ed02770e35d
--- /dev/null
+++ b/apps/dav/lib/Listener/ClearPhotoCacheListener.php
@@ -0,0 +1,48 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @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\Listener;
+
+use OCA\DAV\CardDAV\PhotoCache;
+use OCA\DAV\Events\CardDeletedEvent;
+use OCA\DAV\Events\CardUpdatedEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+class ClearPhotoCacheListener implements IEventListener {
+ private PhotoCache $photoCache;
+
+ public function __construct(PhotoCache $photoCache) {
+ $this->photoCache = $photoCache;
+ }
+
+ public function handle(Event $event): void {
+ if ($event instanceof CardUpdatedEvent || $event instanceof CardDeletedEvent) {
+ $cardData = $event->getCardData();
+
+ $this->photoCache->delete($event->getAddressBookId(), $cardData['uri']);
+ }
+ }
+}
diff --git a/apps/dav/lib/Listener/SubscriptionListener.php b/apps/dav/lib/Listener/SubscriptionListener.php
new file mode 100644
index 00000000000..36db234aa05
--- /dev/null
+++ b/apps/dav/lib/Listener/SubscriptionListener.php
@@ -0,0 +1,85 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @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\Listener;
+
+use OCA\DAV\BackgroundJob\RefreshWebcalJob;
+use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend;
+use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
+use OCA\DAV\Events\SubscriptionCreatedEvent;
+use OCA\DAV\Events\SubscriptionDeletedEvent;
+use OCP\BackgroundJob\IJobList;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use Psr\Log\LoggerInterface;
+
+class SubscriptionListener implements IEventListener {
+ private IJobList $jobList;
+ private RefreshWebcalService $refreshWebcalService;
+ private ReminderBackend $reminderBackend;
+ private LoggerInterface $logger;
+
+ public function __construct(IJobList $jobList, RefreshWebcalService $refreshWebcalService, ReminderBackend $reminderBackend,
+ LoggerInterface $logger) {
+ $this->jobList = $jobList;
+ $this->refreshWebcalService = $refreshWebcalService;
+ $this->reminderBackend = $reminderBackend;
+ $this->logger = $logger;
+ }
+
+ /**
+ * In case the user has set their default calendar to the deleted one
+ */
+ public function handle(Event $event): void {
+ if ($event instanceof SubscriptionCreatedEvent) {
+ $subscriptionId = $event->getSubscriptionId();
+ $subscriptionData = $event->getSubscriptionData();
+
+ $this->logger->debug('Refreshing webcal data for subscription ' . $subscriptionId);
+ $this->refreshWebcalService->refreshSubscription(
+ (string)$subscriptionData['principaluri'],
+ (string)$subscriptionData['uri']
+ );
+
+ $this->logger->debug('Scheduling webcal data refreshment for subscription ' . $subscriptionId);
+ $this->jobList->add(RefreshWebcalJob::class, [
+ 'principaluri' => $subscriptionData['principaluri'],
+ 'uri' => $subscriptionData['uri']
+ ]);
+ } elseif ($event instanceof SubscriptionDeletedEvent) {
+ $subscriptionId = $event->getSubscriptionId();
+ $subscriptionData = $event->getSubscriptionData();
+
+ $this->logger->debug('Removing refresh webcal job for subscription ' . $subscriptionId);
+ $this->jobList->remove(RefreshWebcalJob::class, [
+ 'principaluri' => $subscriptionData['principaluri'],
+ 'uri' => $subscriptionData['uri']
+ ]);
+
+ $this->logger->debug('Cleaning all reminders for subscription ' . $subscriptionId);
+ $this->reminderBackend->cleanRemindersForCalendar($subscriptionId);
+ }
+ }
+}
diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php
index 8a11a676609..8ad4d6aa841 100644
--- a/apps/dav/lib/RootCollection.php
+++ b/apps/dav/lib/RootCollection.php
@@ -7,6 +7,7 @@
* @author Georg Ehrke <oc.list@georgehrke.com>
* @author Joas Schilling <coding@schilljs.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Vincent Petry <vincent@nextcloud.com>
*
@@ -61,7 +62,6 @@ class RootCollection extends SimpleCollection {
$shareManager = \OC::$server->getShareManager();
$db = \OC::$server->getDatabaseConnection();
$dispatcher = \OC::$server->get(IEventDispatcher::class);
- $legacyDispatcher = \OC::$server->getEventDispatcher();
$config = \OC::$server->get(IConfig::class);
$proxyMapper = \OC::$server->query(ProxyMapper::class);
@@ -105,7 +105,6 @@ class RootCollection extends SimpleCollection {
$random,
$logger,
$dispatcher,
- $legacyDispatcher,
$config
);
$userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger);
@@ -140,11 +139,11 @@ class RootCollection extends SimpleCollection {
);
$pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
- $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher);
+ $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
$usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, 'principals/users');
$usersAddressBookRoot->disableListing = $disableListing;
- $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher);
+ $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
$systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, 'principals/system');
$systemAddressBookRoot->disableListing = $disableListing;
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
index ec966248e01..b04f8701c23 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
@@ -7,6 +7,7 @@
* @author Joas Schilling <coding@schilljs.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @license AGPL-3.0
@@ -42,7 +43,6 @@ use OCP\Share\IManager as ShareManager;
use Psr\Log\LoggerInterface;
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
use Sabre\DAV\Xml\Property\Href;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
/**
@@ -65,8 +65,6 @@ abstract class AbstractCalDavBackend extends TestCase {
protected $groupManager;
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
protected $dispatcher;
- /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
- protected $legacyDispatcher;
/** @var ISecureRandom */
private $random;
@@ -84,7 +82,6 @@ abstract class AbstractCalDavBackend extends TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
- $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->principal = $this->getMockBuilder(Principal::class)
->setConstructorArgs([
$this->userManager,
@@ -120,7 +117,6 @@ abstract class AbstractCalDavBackend extends TestCase {
$this->random,
$this->logger,
$this->dispatcher,
- $this->legacyDispatcher,
$this->config
);
@@ -147,8 +143,6 @@ abstract class AbstractCalDavBackend extends TestCase {
$calendars = $this->backend->getCalendarsForUser($principal);
$this->dispatcher->expects(self::any())
->method('dispatchTyped');
- $this->legacyDispatcher->expects(self::any())
- ->method('dispatch');
foreach ($calendars as $calendar) {
$this->backend->deleteCalendar($calendar['id'], true);
}
diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
index a6439ee6d2b..13025415f2a 100644
--- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
@@ -151,9 +151,6 @@ class CalDavBackendTest extends AbstractCalDavBackend {
$calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertCount(1, $calendars);
$calendar = new Calendar($this->backend, $calendars[0], $l10n, $config, $logger);
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::updateShares');
$this->backend->updateShares($calendar, $add, []);
$calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
$this->assertCount(1, $calendars);
diff --git a/apps/dav/tests/unit/CalDAV/Listener/CalendarPublicationListenerTest.php b/apps/dav/tests/unit/CalDAV/Listener/CalendarPublicationListenerTest.php
new file mode 100644
index 00000000000..c42fca1a1cf
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/Listener/CalendarPublicationListenerTest.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @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\Tests\unit\CalDAV\Listeners;
+
+use OCA\DAV\CalDAV\Activity\Backend;
+use OCA\DAV\Events\CalendarPublishedEvent;
+use OCA\DAV\Events\CalendarUnpublishedEvent;
+use OCA\DAV\Listener\CalendarPublicationListener;
+use OCP\EventDispatcher\Event;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class CalendarPublicationListenerTest extends TestCase {
+
+ /** @var Backend|MockObject */
+ private $activityBackend;
+
+ /** @var LoggerInterface|MockObject */
+ private $logger;
+
+ private CalendarPublicationListener $calendarPublicationListener;
+
+ /** @var CalendarPublishedEvent|MockObject */
+ private $publicationEvent;
+
+ /** @var CalendarUnpublishedEvent|MockObject */
+ private $unpublicationEvent;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->activityBackend = $this->createMock(Backend::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->publicationEvent = $this->createMock(CalendarPublishedEvent::class);
+ $this->unpublicationEvent = $this->createMock(CalendarUnpublishedEvent::class);
+ $this->calendarPublicationListener = new CalendarPublicationListener($this->activityBackend, $this->logger);
+ }
+
+ public function testInvalidEvent(): void {
+ $this->activityBackend->expects($this->never())->method('onCalendarPublication');
+ $this->logger->expects($this->never())->method('debug');
+ $this->calendarPublicationListener->handle(new Event());
+ }
+
+ public function testPublicationEvent(): void {
+ $this->publicationEvent->expects($this->once())->method('getCalendarData')->with()->willReturn([]);
+ $this->activityBackend->expects($this->once())->method('onCalendarPublication')->with([], true);
+ $this->logger->expects($this->once())->method('debug');
+ $this->calendarPublicationListener->handle($this->publicationEvent);
+ }
+
+ public function testUnPublicationEvent(): void {
+ $this->unpublicationEvent->expects($this->once())->method('getCalendarData')->with()->willReturn([]);
+ $this->activityBackend->expects($this->once())->method('onCalendarPublication')->with([], false);
+ $this->logger->expects($this->once())->method('debug');
+ $this->calendarPublicationListener->handle($this->unpublicationEvent);
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/Listener/CalendarShareUpdateListenerTest.php b/apps/dav/tests/unit/CalDAV/Listener/CalendarShareUpdateListenerTest.php
new file mode 100644
index 00000000000..0252cffd5a0
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/Listener/CalendarShareUpdateListenerTest.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @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\Tests\unit\CalDAV\Listeners;
+
+use OCA\DAV\CalDAV\Activity\Backend;
+use OCA\DAV\Events\CalendarShareUpdatedEvent;
+use OCA\DAV\Listener\CalendarShareUpdateListener;
+use OCP\EventDispatcher\Event;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class CalendarShareUpdateListenerTest extends TestCase {
+
+ /** @var Backend|MockObject */
+ private $activityBackend;
+
+ /** @var LoggerInterface|MockObject */
+ private $logger;
+
+ private CalendarShareUpdateListener $calendarPublicationListener;
+
+ /** @var CalendarShareUpdatedEvent|MockObject */
+ private $event;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->activityBackend = $this->createMock(Backend::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->event = $this->createMock(CalendarShareUpdatedEvent::class);
+ $this->calendarPublicationListener = new CalendarShareUpdateListener($this->activityBackend, $this->logger);
+ }
+
+ public function testInvalidEvent(): void {
+ $this->activityBackend->expects($this->never())->method('onCalendarUpdateShares');
+ $this->logger->expects($this->never())->method('debug');
+ $this->calendarPublicationListener->handle(new Event());
+ }
+
+ public function testEvent(): void {
+ $this->event->expects($this->once())->method('getCalendarData')->with()->willReturn([]);
+ $this->event->expects($this->once())->method('getOldShares')->with()->willReturn([]);
+ $this->event->expects($this->once())->method('getAdded')->with()->willReturn([]);
+ $this->event->expects($this->once())->method('getRemoved')->with()->willReturn([]);
+ $this->activityBackend->expects($this->once())->method('onCalendarUpdateShares')->with([], [], [], []);
+ $this->logger->expects($this->once())->method('debug');
+ $this->calendarPublicationListener->handle($this->event);
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/Listener/SubscriptionListenerTest.php b/apps/dav/tests/unit/CalDAV/Listener/SubscriptionListenerTest.php
new file mode 100644
index 00000000000..709ebdac7af
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/Listener/SubscriptionListenerTest.php
@@ -0,0 +1,95 @@
+<?php
+/**
+ * @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @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\Tests\unit\CalDAV\Listeners;
+
+use OCA\DAV\BackgroundJob\RefreshWebcalJob;
+use OCA\DAV\CalDAV\Reminder\Backend;
+use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
+use OCA\DAV\Events\SubscriptionCreatedEvent;
+use OCA\DAV\Events\SubscriptionDeletedEvent;
+use OCA\DAV\Listener\SubscriptionListener;
+use OCP\BackgroundJob\IJobList;
+use OCP\EventDispatcher\Event;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class SubscriptionListenerTest extends TestCase {
+
+ /** @var RefreshWebcalService|MockObject */
+ private $refreshWebcalService;
+
+ /** @var Backend|MockObject */
+ private $reminderBackend;
+
+ /** @var IJobList|MockObject */
+ private $jobList;
+
+ /** @var LoggerInterface|MockObject */
+ private $logger;
+
+ private SubscriptionListener $calendarPublicationListener;
+
+ /** @var SubscriptionCreatedEvent|MockObject */
+ private $subscriptionCreatedEvent;
+
+ /** @var SubscriptionDeletedEvent|MockObject */
+ private $subscriptionDeletedEvent;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->refreshWebcalService = $this->createMock(RefreshWebcalService::class);
+ $this->reminderBackend = $this->createMock(Backend::class);
+ $this->jobList = $this->createMock(IJobList::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->subscriptionCreatedEvent = $this->createMock(SubscriptionCreatedEvent::class);
+ $this->subscriptionDeletedEvent = $this->createMock(SubscriptionDeletedEvent::class);
+ $this->calendarPublicationListener = new SubscriptionListener($this->jobList, $this->refreshWebcalService, $this->reminderBackend, $this->logger);
+ }
+
+ public function testInvalidEvent(): void {
+ $this->refreshWebcalService->expects($this->never())->method('refreshSubscription');
+ $this->jobList->expects($this->never())->method('add');
+ $this->logger->expects($this->never())->method('debug');
+ $this->calendarPublicationListener->handle(new Event());
+ }
+
+ public function testCreateSubscriptionEvent(): void {
+ $this->subscriptionCreatedEvent->expects($this->once())->method('getSubscriptionId')->with()->willReturn(5);
+ $this->subscriptionCreatedEvent->expects($this->once())->method('getSubscriptionData')->with()->willReturn(['principaluri' => 'principaluri', 'uri' => 'uri']);
+ $this->refreshWebcalService->expects($this->once())->method('refreshSubscription')->with('principaluri', 'uri');
+ $this->jobList->expects($this->once())->method('add')->with(RefreshWebcalJob::class, ['principaluri' => 'principaluri', 'uri' => 'uri']);
+ $this->logger->expects($this->exactly(2))->method('debug');
+ $this->calendarPublicationListener->handle($this->subscriptionCreatedEvent);
+ }
+
+ public function testDeleteSubscriptionEvent(): void {
+ $this->subscriptionDeletedEvent->expects($this->once())->method('getSubscriptionId')->with()->willReturn(5);
+ $this->subscriptionDeletedEvent->expects($this->once())->method('getSubscriptionData')->with()->willReturn(['principaluri' => 'principaluri', 'uri' => 'uri']);
+ $this->jobList->expects($this->once())->method('remove')->with(RefreshWebcalJob::class, ['principaluri' => 'principaluri', 'uri' => 'uri']);
+ $this->reminderBackend->expects($this->once())->method('cleanRemindersForCalendar')->with(5);
+ $this->logger->expects($this->exactly(2))->method('debug');
+ $this->calendarPublicationListener->handle($this->subscriptionDeletedEvent);
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
index 80e43d279dc..23c1c2ae896 100644
--- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
+++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
@@ -42,7 +42,6 @@ use OCP\IL10N;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
/**
@@ -84,7 +83,6 @@ class PublicCalendarRootTest extends TestCase {
$this->random = \OC::$server->getSecureRandom();
$this->logger = $this->createMock(LoggerInterface::class);
$dispatcher = $this->createMock(IEventDispatcher::class);
- $legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
$config = $this->createMock(IConfig::class);
$this->principal->expects($this->any())->method('getGroupMembership')
@@ -103,7 +101,6 @@ class PublicCalendarRootTest extends TestCase {
$this->random,
$this->logger,
$dispatcher,
- $legacyDispatcher,
$config
);
$this->l10n = $this->getMockBuilder(IL10N::class)
diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
index 7eda691d199..5bfbab07b29 100644
--- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
+++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
@@ -13,6 +13,7 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @license AGPL-3.0
@@ -52,8 +53,6 @@ use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\PropPatch;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Property\Text;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
/**
@@ -77,10 +76,7 @@ class CardDavBackendTest extends TestCase {
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
private $groupManager;
- /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
- private $legacyDispatcher;
-
- /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IEventDispatcher|MockObject */
private $dispatcher;
/** @var IDBConnection */
@@ -155,11 +151,10 @@ class CardDavBackendTest extends TestCase {
->withAnyParameters()
->willReturn([self::UNIT_TEST_GROUP]);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
- $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->db = \OC::$server->getDatabaseConnection();
- $this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher);
+ $this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher);
// start every test with a empty cards_properties and cards table
$query = $this->db->getQueryBuilder();
$query->delete('cards_properties')->execute();
@@ -249,8 +244,8 @@ class CardDavBackendTest extends TestCase {
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backend */
$backend = $this->getMockBuilder(CardDavBackend::class)
- ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
- ->setMethods(['updateProperties', 'purgeProperties'])->getMock();
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
+ ->onlyMethods(['updateProperties', 'purgeProperties'])->getMock();
// create a new address book
$backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
@@ -264,13 +259,9 @@ class CardDavBackendTest extends TestCase {
$backend->expects($this->at(1))->method('updateProperties')->with($bookId, $uri, $this->vcardTest1);
// Expect event
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CardDAV\CardDavBackend::createCard', $this->callback(function (GenericEvent $e) use ($bookId, $uri) {
- return $e->getArgument('addressBookId') === $bookId &&
- $e->getArgument('cardUri') === $uri &&
- $e->getArgument('cardData') === $this->vcardTest0;
- }));
+ $this->dispatcher
+ ->expects($this->exactly(3))
+ ->method('dispatchTyped');
// create a card
$backend->createCard($bookId, $uri, $this->vcardTest0);
@@ -290,28 +281,11 @@ class CardDavBackendTest extends TestCase {
$this->assertArrayHasKey('size', $card);
$this->assertEquals($this->vcardTest0, $card['carddata']);
- // Expect event
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $this->callback(function (GenericEvent $e) use ($bookId, $uri) {
- return $e->getArgument('addressBookId') === $bookId &&
- $e->getArgument('cardUri') === $uri &&
- $e->getArgument('cardData') === $this->vcardTest1;
- }));
-
// update the card
$backend->updateCard($bookId, $uri, $this->vcardTest1);
$card = $backend->getCard($bookId, $uri);
$this->assertEquals($this->vcardTest1, $card['carddata']);
- // Expect event
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $this->callback(function (GenericEvent $e) use ($bookId, $uri) {
- return $e->getArgument('addressBookId') === $bookId &&
- $e->getArgument('cardUri') === $uri;
- }));
-
// delete the card
$backend->expects($this->once())->method('purgeProperties')->with($bookId, $card['id']);
$backend->deleteCard($bookId, $uri);
@@ -321,7 +295,7 @@ class CardDavBackendTest extends TestCase {
public function testMultiCard() {
$this->backend = $this->getMockBuilder(CardDavBackend::class)
- ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
->setMethods(['updateProperties'])->getMock();
// create a new address book
@@ -374,8 +348,8 @@ class CardDavBackendTest extends TestCase {
public function testMultipleUIDOnDifferentAddressbooks() {
$this->backend = $this->getMockBuilder(CardDavBackend::class)
- ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
- ->setMethods(['updateProperties'])->getMock();
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
+ ->onlyMethods(['updateProperties'])->getMock();
// create 2 new address books
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
@@ -396,7 +370,7 @@ class CardDavBackendTest extends TestCase {
public function testMultipleUIDDenied() {
$this->backend = $this->getMockBuilder(CardDavBackend::class)
- ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
->setMethods(['updateProperties'])->getMock();
// create a new address book
@@ -417,7 +391,7 @@ class CardDavBackendTest extends TestCase {
public function testNoValidUID() {
$this->backend = $this->getMockBuilder(CardDavBackend::class)
- ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
->setMethods(['updateProperties'])->getMock();
// create a new address book
@@ -434,8 +408,8 @@ class CardDavBackendTest extends TestCase {
public function testDeleteWithoutCard() {
$this->backend = $this->getMockBuilder(CardDavBackend::class)
- ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
- ->setMethods([
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
+ ->onlyMethods([
'getCardId',
'addChange',
'purgeProperties',
@@ -474,7 +448,7 @@ class CardDavBackendTest extends TestCase {
public function testSyncSupport() {
$this->backend = $this->getMockBuilder(CardDavBackend::class)
- ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
->setMethods(['updateProperties'])->getMock();
// create a new address book
@@ -540,8 +514,8 @@ class CardDavBackendTest extends TestCase {
$cardId = 2;
$backend = $this->getMockBuilder(CardDavBackend::class)
- ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
- ->setMethods(['getCardId'])->getMock();
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
+ ->onlyMethods(['getCardId'])->getMock();
$backend->expects($this->any())->method('getCardId')->willReturn($cardId);
@@ -630,8 +604,8 @@ class CardDavBackendTest extends TestCase {
$qResult->closeCursor();
$this->assertSame(1, count($result));
- $this->assertSame(1 ,(int)$result[0]['addressbookid']);
- $this->assertSame(2 ,(int)$result[0]['cardid']);
+ $this->assertSame(1, (int)$result[0]['addressbookid']);
+ $this->assertSame(2, (int)$result[0]['cardid']);
}
public function testGetCardId() {