We had both in places, but the old one isn't used anywhere outside this app, so it's time to migrate the code. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>pull/26826/head
parent
abb5b5d983
commit
63eb3694e4
@ -0,0 +1,75 @@ |
||||
<?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 OCA\DAV\Listener; |
||||
|
||||
use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend; |
||||
use OCA\DAV\Events\CalendarDeletedEvent; |
||||
use OCP\EventDispatcher\Event; |
||||
use OCP\EventDispatcher\IEventListener; |
||||
use Psr\Log\LoggerInterface; |
||||
use Throwable; |
||||
use function sprintf; |
||||
|
||||
/** |
||||
* @template-implements IEventListener<\OCA\DAV\Events\CalendarDeletedEvent> |
||||
*/ |
||||
class CalendarDeletionActivityUpdaterListener implements IEventListener { |
||||
|
||||
/** @var ActivityBackend */ |
||||
private $activityBackend; |
||||
|
||||
/** @var LoggerInterface */ |
||||
private $logger; |
||||
|
||||
public function __construct(ActivityBackend $activityBackend, |
||||
LoggerInterface $logger) { |
||||
$this->activityBackend = $activityBackend; |
||||
$this->logger = $logger; |
||||
} |
||||
|
||||
public function handle(Event $event): void { |
||||
if (!($event instanceof CalendarDeletedEvent)) { |
||||
// Not what we subscribed to |
||||
return; |
||||
} |
||||
|
||||
try { |
||||
$this->activityBackend->onCalendarDelete( |
||||
$event->getCalendarData(), |
||||
$event->getShares() |
||||
); |
||||
|
||||
$this->logger->debug( |
||||
sprintf('Activity generated for deleted calendar %d', $event->getCalendarId()) |
||||
); |
||||
} catch (Throwable $e) { |
||||
// Any error with activities shouldn't abort the calendar deletion, so we just log it |
||||
$this->logger->error('Error generating activities for a deleted calendar: ' . $e->getMessage(), [ |
||||
'exception' => $e, |
||||
]); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,86 @@ |
||||
<?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 OCA\DAV\Listener; |
||||
|
||||
use OCA\DAV\Events\CalendarDeletedEvent; |
||||
use OCP\EventDispatcher\Event; |
||||
use OCP\EventDispatcher\IEventListener; |
||||
use OCP\IConfig; |
||||
use Psr\Log\LoggerInterface; |
||||
use Throwable; |
||||
use function strpos; |
||||
|
||||
/** |
||||
* @template-implements IEventListener<\OCA\DAV\Events\CalendarDeletedEvent> |
||||
*/ |
||||
class CalendarDeletionDefaultUpdaterListener implements IEventListener { |
||||
|
||||
/** @var IConfig */ |
||||
private $config; |
||||
|
||||
/** @var LoggerInterface */ |
||||
private $logger; |
||||
|
||||
public function __construct(IConfig $config, |
||||
LoggerInterface $logger) { |
||||
$this->config = $config; |
||||
$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 CalendarDeletedEvent)) { |
||||
// Not what we subscribed to |
||||
return; |
||||
} |
||||
|
||||
try { |
||||
$principalUri = $event->getCalendarData()['principaluri']; |
||||
if (strpos($principalUri, 'principals/users') !== 0) { |
||||
$this->logger->debug('Default calendar needs no update because the deleted calendar does not belong to a user principal'); |
||||
return; |
||||
} |
||||
|
||||
[, $uid] = \Sabre\Uri\split($principalUri); |
||||
$uri = $event->getCalendarData()['uri']; |
||||
if ($this->config->getUserValue($uid, 'dav', 'defaultCalendar') !== $uri) { |
||||
$this->logger->debug('Default calendar needs no update because the deleted calendar is no the user\'s default one'); |
||||
return; |
||||
} |
||||
|
||||
$this->config->deleteUserValue($uid, 'dav', 'defaultCalendar'); |
||||
|
||||
$this->logger->debug('Default user calendar reset'); |
||||
} catch (Throwable $e) { |
||||
// Any error with activities shouldn't abort the calendar deletion, so we just log it |
||||
$this->logger->error('Error generating activities for a deleted calendar: ' . $e->getMessage(), [ |
||||
'exception' => $e, |
||||
]); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,74 @@ |
||||
<?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 OCA\DAV\Listener; |
||||
|
||||
use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend; |
||||
use OCA\DAV\Events\CalendarDeletedEvent; |
||||
use OCP\EventDispatcher\Event; |
||||
use OCP\EventDispatcher\IEventListener; |
||||
use Psr\Log\LoggerInterface; |
||||
use Throwable; |
||||
use function sprintf; |
||||
|
||||
/** |
||||
* @template-implements IEventListener<\OCA\DAV\Events\CalendarDeletedEvent> |
||||
*/ |
||||
class CalendarDeletionReminderUpdaterListener implements IEventListener { |
||||
|
||||
/** @var ReminderBackend */ |
||||
private $reminderBackend; |
||||
|
||||
/** @var LoggerInterface */ |
||||
private $logger; |
||||
|
||||
public function __construct(ReminderBackend $reminderBackend, |
||||
LoggerInterface $logger) { |
||||
$this->reminderBackend = $reminderBackend; |
||||
$this->logger = $logger; |
||||
} |
||||
|
||||
public function handle(Event $event): void { |
||||
if (!($event instanceof CalendarDeletedEvent)) { |
||||
// Not what we subscribed to |
||||
return; |
||||
} |
||||
|
||||
try { |
||||
$this->reminderBackend->cleanRemindersForCalendar( |
||||
$event->getCalendarId() |
||||
); |
||||
|
||||
$this->logger->debug( |
||||
sprintf('Reminders of calendar %d cleaned up', $event->getCalendarId()) |
||||
); |
||||
} catch (Throwable $e) { |
||||
// Any error with activities shouldn't abort the calendar deletion, so we just log it |
||||
$this->logger->error('Error cleaning up reminders of a deleted calendar: ' . $e->getMessage(), [ |
||||
'exception' => $e, |
||||
]); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue