Skip to content

Commit

Permalink
Merge pull request #39190 from nextcloud/bugfix/noid/move-dav-app-to-…
Browse files Browse the repository at this point in the history
…non-deprecated-dispatcher
  • Loading branch information
skjnldsv authored Jul 11, 2023
2 parents 428153c + e1d4b82 commit 2dfd9ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
45 changes: 15 additions & 30 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
*/
namespace OCA\DAV\AppInfo;

use Exception;
use OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob;
use OCA\DAV\CalDAV\Activity\Backend;
use OCA\DAV\CalDAV\AppCalendar\AppCalendarPlugin;
use OCA\DAV\CalDAV\CalendarManager;
Expand Down Expand Up @@ -71,6 +69,7 @@
use OCA\DAV\Events\CardUpdatedEvent;
use OCA\DAV\Events\SubscriptionCreatedEvent;
use OCA\DAV\Events\SubscriptionDeletedEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\Events\TrustedServerRemovedEvent;
use OCA\DAV\HookManager;
use OCA\DAV\Listener\ActivityUpdaterListener;
Expand Down Expand Up @@ -105,7 +104,6 @@
use OCP\IUser;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Throwable;
use function is_null;
Expand Down Expand Up @@ -215,9 +213,8 @@ public function boot(IBootContext $context): void {
}

public function registerHooks(HookManager $hm,
EventDispatcherInterface $dispatcher,
IAppContainer $container,
IServerContainer $serverContainer) {
IEventDispatcher $dispatcher,
IAppContainer $container) {
$hm->setup();

// first time login event setup
Expand All @@ -227,40 +224,28 @@ public function registerHooks(HookManager $hm,
}
});

$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($container) {
$user = $event->getSubject();
/** @var SyncService $syncService */
$syncService = $container->query(SyncService::class);
$syncService->updateUser($user);
$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('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) use ($container) {
$dispatcher->addListener(CalendarShareUpdatedEvent::class, function (CalendarShareUpdatedEvent $event) use ($container) {
/** @var Backend $backend */
$backend = $container->query(Backend::class);
$backend->onCalendarUpdateShares(
$event->getArgument('calendarData'),
$event->getArgument('shares'),
$event->getArgument('add'),
$event->getArgument('remove')
$event->getCalendarData(),
$event->getOldShares(),
$event->getAdded(),
$event->getRemoved()
);

// Here we should recalculate if reminders should be sent to new or old sharees
});

$eventHandler = function () use ($container, $serverContainer): void {
try {
/** @var UpdateCalendarResourcesRoomsBackgroundJob $job */
$job = $container->query(UpdateCalendarResourcesRoomsBackgroundJob::class);
$job->run([]);
$serverContainer->getJobList()->setLastRun($job);
} catch (Exception $ex) {
$serverContainer->get(LoggerInterface::class)->error($ex->getMessage(), ['exception' => $ex]);
}
};

$dispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler);
$dispatcher->addListener('\OCP\Calendar\Room\ForceRefreshEvent', $eventHandler);
}

public function registerContactsManager(IContactsManager $cm, IAppContainer $container): void {
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,7 @@ public function updateShares(IShareable $shareable, array $add, array $remove):
$calendarId = $shareable->getResourceId();
$calendarRow = $this->getCalendarById($calendarId);
if ($calendarRow === null) {
throw new \RuntimeException('Trying to update shares for innexistant calendar: ' . $calendarId);
throw new \RuntimeException('Trying to update shares for non-existing calendar: ' . $calendarId);
}
$oldShares = $this->getShares($calendarId);

Expand Down

0 comments on commit 2dfd9ee

Please sign in to comment.