summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CalDAV
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/CalDAV')
-rw-r--r--apps/dav/lib/CalDAV/Reminder/Backend.php2
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php39
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php77
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php14
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProviderManager.php36
-rw-r--r--apps/dav/lib/CalDAV/Reminder/Notifier.php12
-rw-r--r--apps/dav/lib/CalDAV/Reminder/ReminderService.php38
7 files changed, 94 insertions, 124 deletions
diff --git a/apps/dav/lib/CalDAV/Reminder/Backend.php b/apps/dav/lib/CalDAV/Reminder/Backend.php
index be65c35da0f..b3cc013fb3e 100644
--- a/apps/dav/lib/CalDAV/Reminder/Backend.php
+++ b/apps/dav/lib/CalDAV/Reminder/Backend.php
@@ -63,7 +63,7 @@ class Backend {
$query = $this->db->getQueryBuilder();
$query->select(['cr.*', 'co.calendardata', 'c.displayname', 'c.principaluri'])
->from('calendar_reminders', 'cr')
-// ->where($query->expr()->lte('cr.notification_date', $query->createNamedParameter($this->timeFactory->getTime())))
+ ->where($query->expr()->lte('cr.notification_date', $query->createNamedParameter($this->timeFactory->getTime())))
->leftJoin('cr', 'calendarobjects', 'co', $query->expr()->eq('cr.object_id', 'co.id'))
->leftJoin('cr', 'calendars', 'c', $query->expr()->eq('cr.calendar_id', 'c.id'));
$stmt = $query->execute();
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
index 6b2364c8022..6e3a8eaddef 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
@@ -25,8 +25,6 @@ declare(strict_types=1);
*/
namespace OCA\DAV\CalDAV\Reminder\NotificationProvider;
-use \DateTime;
-use \DateTimeImmutable;
use OCA\DAV\CalDAV\Reminder\INotificationProvider;
use OCP\IConfig;
use OCP\IL10N;
@@ -36,7 +34,6 @@ use OCP\L10N\IFactory as L10NFactory;
use OCP\IUser;
use Sabre\VObject\Component\VEvent;
use Sabre\VObject\DateTimeParser;
-use Sabre\VObject\Parameter;
use Sabre\VObject\Property;
/**
@@ -49,22 +46,22 @@ abstract class AbstractProvider implements INotificationProvider {
/** @var string */
public const NOTIFICATION_TYPE = '';
- /** @var ILogger */
- protected $logger;
+ /** @var ILogger */
+ protected $logger;
- /** @var L10NFactory */
- private $l10nFactory;
+ /** @var L10NFactory */
+ private $l10nFactory;
- /** @var IL10N[] */
+ /** @var IL10N[] */
private $l10ns;
/** @var string */
private $fallbackLanguage;
- /** @var IURLGenerator */
- protected $urlGenerator;
+ /** @var IURLGenerator */
+ protected $urlGenerator;
- /** @var IConfig */
+ /** @var IConfig */
protected $config;
/**
@@ -79,9 +76,9 @@ abstract class AbstractProvider implements INotificationProvider {
IConfig $config) {
$this->logger = $logger;
$this->l10nFactory = $l10nFactory;
- $this->urlGenerator = $urlGenerator;
+ $this->urlGenerator = $urlGenerator;
$this->config = $config;
- }
+ }
/**
* Send notification
@@ -91,22 +88,22 @@ abstract class AbstractProvider implements INotificationProvider {
* @param IUser[] $users
* @return void
*/
- abstract public function send(VEvent $vevent,
+ abstract public function send(VEvent $vevent,
string $calendarDisplayName,
array $users=[]): void;
/**
* @return string
*/
- protected function getFallbackLanguage():string {
- if ($this->fallbackLanguage) {
- return $this->fallbackLanguage;
+ protected function getFallbackLanguage():string {
+ if ($this->fallbackLanguage) {
+ return $this->fallbackLanguage;
}
- $fallbackLanguage = $this->l10nFactory->findLanguage();
- $this->fallbackLanguage = $fallbackLanguage;
+ $fallbackLanguage = $this->l10nFactory->findLanguage();
+ $this->fallbackLanguage = $fallbackLanguage;
- return $fallbackLanguage;
+ return $fallbackLanguage;
}
/**
@@ -114,7 +111,7 @@ abstract class AbstractProvider implements INotificationProvider {
* @return bool
*/
protected function hasL10NForLang(string $lang):bool {
- return $this->l10nFactory->languageExists('dav', $lang);
+ return $this->l10nFactory->languageExists('dav', $lang);
}
/**
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
index cf79fad7ab8..f5932a87b3e 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
@@ -25,8 +25,7 @@ declare(strict_types=1);
*/
namespace OCA\DAV\CalDAV\Reminder\NotificationProvider;
-use DateTime;
-use DateTimeImmutable;
+use \DateTime;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
@@ -97,36 +96,35 @@ class EmailProvider extends AbstractProvider {
$organizer = $this->getOrganizerEMailAndNameFromEvent($vevent);
foreach($sortedByLanguage as $lang => $emailAddresses) {
- if ($this->hasL10NForLang($lang)) {
+ if (!$this->hasL10NForLang($lang)) {
$lang = $fallbackLanguage;
}
$l10n = $this->getL10NForLang($lang);
$fromEMail = \OCP\Util::getDefaultEmailAddress('reminders-noreply');
- $message = $this->mailer->createMessage();
- $message->setFrom([$fromEMail]);
- if ($organizer) {
- $message->setReplyTo($organizer);
- }
- $message->setTo([])
- ->setBcc($emailAddresses);
-
$template = $this->mailer->createEMailTemplate('dav.calendarReminder');
$template->addHeader();
-
$this->addSubjectAndHeading($template, $l10n, $vevent);
$this->addBulletList($template, $l10n, $calendarDisplayName, $vevent);
-
$template->addFooter();
- $message->useTemplate($template);
- try {
- $failed = $this->mailer->send($message);
- if ($failed) {
- $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]);
+ foreach ($emailAddresses as $emailAddress) {
+ $message = $this->mailer->createMessage();
+ $message->setFrom([$fromEMail]);
+ if ($organizer) {
+ $message->setReplyTo($organizer);
+ }
+ $message->setTo([$emailAddress]);
+ $message->useTemplate($template);
+
+ try {
+ $failed = $this->mailer->send($message);
+ if ($failed) {
+ $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]);
+ }
+ } catch (\Exception $ex) {
+ $this->logger->logException($ex, ['app' => 'dav']);
}
- } catch (\Exception $ex) {
- $this->logger->logException($ex, ['app' => 'dav']);
}
}
}
@@ -165,9 +163,9 @@ class EmailProvider extends AbstractProvider {
$template->addBodyListItem((string) $vevent->DESCRIPTION, $l10n->t('Description:'),
$this->getAbsoluteImagePath('actions/more.svg'));
}
- }
+ }
- /**
+ /**
* @param string $path
* @return string
*/
@@ -202,35 +200,6 @@ class EmailProvider extends AbstractProvider {
}
/**
- * @param array $sortedByLanguage
- * @param IUser[] $users
- * @param string $defaultLanguage
- */
- private function sortUsersByLanguage(array &$sortedByLanguage,
- array $users,
- string $defaultLanguage):void {
- /**
- * @var array $sortedByLanguage
- * [
- * 'de' => ['a@b.com', 'c@d.com'],
- * ...
- * ]
- */
- foreach($users as $user) {
- /** @var IUser $user */
- $emailAddress = $user->getEMailAddress();
- $lang = $this->config->getUserValue($user->getUID(),
- 'core', 'lang', $defaultLanguage);
-
- if (!isset($sortedByLanguage[$lang])) {
- $sortedByLanguage[$lang] = [];
- }
-
- $sortedByLanguage[$lang][] = $emailAddress;
- }
- }
-
- /**
* @param array $emails
* @param string $defaultLanguage
* @return array
@@ -386,7 +355,7 @@ class EmailProvider extends AbstractProvider {
}
}
- return array_unique($emailAddresses);
+ return $emailAddresses;
}
/**
@@ -415,7 +384,9 @@ class EmailProvider extends AbstractProvider {
$diff = $dtstartDt->diff($dtendDt);
+ /** @phan-suppress-next-line PhanUndeclaredClassMethod */
$dtstartDt = new \DateTime($dtstartDt->format(\DateTime::ATOM));
+ /** @phan-suppress-next-line PhanUndeclaredClassMethod */
$dtendDt = new \DateTime($dtendDt->format(\DateTime::ATOM));
if ($isAllDay) {
@@ -432,7 +403,9 @@ class EmailProvider extends AbstractProvider {
$startTimezone = $endTimezone = null;
if (!$vevent->DTSTART->isFloating()) {
+ /** @phan-suppress-next-line PhanUndeclaredClassMethod */
$startTimezone = $vevent->DTSTART->getDateTime()->getTimezone()->getName();
+ /** @phan-suppress-next-line PhanUndeclaredClassMethod */
$endTimezone = $this->getDTEndFromEvent($vevent)->getDateTime()->getTimezone()->getName();
}
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php
index 2e580fd78a3..3872b67e596 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php
@@ -47,7 +47,7 @@ class PushProvider extends AbstractProvider {
/** @var string */
public const NOTIFICATION_TYPE = 'DISPLAY';
- /** @var IManager */
+ /** @var IManager */
private $manager;
/** @var ITimeFactory */
@@ -70,7 +70,7 @@ class PushProvider extends AbstractProvider {
parent::__construct($logger, $l10nFactory, $urlGenerator, $config);
$this->manager = $manager;
$this->timeFactory = $timeFactory;
- }
+ }
/**
* Send push notification to all users.
@@ -80,13 +80,13 @@ class PushProvider extends AbstractProvider {
* @param IUser[] $users
* @throws \Exception
*/
- public function send(VEvent $vevent,
+ public function send(VEvent $vevent,
string $calendarDisplayName=null,
array $users=[]):void {
$eventDetails = $this->extractEventDetails($vevent);
$eventDetails['calendar_displayname'] = $calendarDisplayName;
- foreach($users as $user) {
+ foreach($users as $user) {
/** @var INotification $notification */
$notification = $this->manager->createNotification();
$notification->setApp(Application::APP_ID)
@@ -101,7 +101,7 @@ class PushProvider extends AbstractProvider {
$this->manager->notify($notification);
}
- }
+ }
/**
* @var VEvent $vevent
@@ -124,11 +124,15 @@ class PushProvider extends AbstractProvider {
? ((string) $vevent->LOCATION)
: null,
'all_day' => $start instanceof Property\ICalendar\Date,
+ /** @phan-suppress-next-line PhanUndeclaredClassMethod */
'start_atom' => $start->getDateTime()->format(\DateTime::ATOM),
'start_is_floating' => $start->isFloating(),
+ /** @phan-suppress-next-line PhanUndeclaredClassMethod */
'start_timezone' => $start->getDateTime()->getTimezone()->getName(),
+ /** @phan-suppress-next-line PhanUndeclaredClassMethod */
'end_atom' => $end->getDateTime()->format(\DateTime::ATOM),
'end_is_floating' => $end->isFloating(),
+ /** @phan-suppress-next-line PhanUndeclaredClassMethod */
'end_timezone' => $end->getDateTime()->getTimezone()->getName(),
];
}
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProviderManager.php b/apps/dav/lib/CalDAV/Reminder/NotificationProviderManager.php
index 3d54970562d..c9bcf2dd064 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProviderManager.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProviderManager.php
@@ -31,8 +31,8 @@ namespace OCA\DAV\CalDAV\Reminder;
*/
class NotificationProviderManager {
- /** @var INotificationProvider[] */
- private $providers = [];
+ /** @var INotificationProvider[] */
+ private $providers = [];
/**
* Checks whether a provider for a given ACTION exists
@@ -45,23 +45,23 @@ class NotificationProviderManager {
&& isset($this->providers[$type]));
}
- /**
+ /**
* Get provider for a given ACTION
*
- * @param string $type
- * @return INotificationProvider
- * @throws NotificationProvider\ProviderNotAvailableException
- * @throws NotificationTypeDoesNotExistException
- */
- public function getProvider(string $type):INotificationProvider {
- if (in_array($type, ReminderService::REMINDER_TYPES, true)) {
- if (isset($this->providers[$type])) {
- return $this->providers[$type];
- }
- throw new NotificationProvider\ProviderNotAvailableException($type);
- }
- throw new NotificationTypeDoesNotExistException($type);
- }
+ * @param string $type
+ * @return INotificationProvider
+ * @throws NotificationProvider\ProviderNotAvailableException
+ * @throws NotificationTypeDoesNotExistException
+ */
+ public function getProvider(string $type):INotificationProvider {
+ if (in_array($type, ReminderService::REMINDER_TYPES, true)) {
+ if (isset($this->providers[$type])) {
+ return $this->providers[$type];
+ }
+ throw new NotificationProvider\ProviderNotAvailableException($type);
+ }
+ throw new NotificationTypeDoesNotExistException($type);
+ }
/**
* Registers a new provider
@@ -69,7 +69,7 @@ class NotificationProviderManager {
* @param string $providerClassName
* @throws \OCP\AppFramework\QueryException
*/
- public function registerProvider(string $providerClassName):void {
+ public function registerProvider(string $providerClassName):void {
$provider = \OC::$server->query($providerClassName);
if (!$provider instanceof INotificationProvider) {
diff --git a/apps/dav/lib/CalDAV/Reminder/Notifier.php b/apps/dav/lib/CalDAV/Reminder/Notifier.php
index 4bad9841787..2c5f05f62ab 100644
--- a/apps/dav/lib/CalDAV/Reminder/Notifier.php
+++ b/apps/dav/lib/CalDAV/Reminder/Notifier.php
@@ -25,7 +25,7 @@ declare(strict_types=1);
namespace OCA\DAV\CalDAV\Reminder;
-use DateTime;
+use \DateTime;
use OCA\DAV\AppInfo\Application;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IL10N;
@@ -85,10 +85,6 @@ class Notifier implements INotifier {
* @since 17.0.0
*/
public function getName():string {
- if ($this->l10n) {
- return $this->l10n->t('Calendar');
- }
-
return $this->l10nFactory->get('dav')->t('Calendar');
}
@@ -143,7 +139,7 @@ class Notifier implements INotifier {
private function prepareNotificationSubject(INotification $notification): void {
$parameters = $notification->getSubjectParameters();
- $startTime = \DateTime::createFromFormat(\DateTimeInterface::ATOM, $parameters['start_atom']);
+ $startTime = \DateTime::createFromFormat(\DateTime::ATOM, $parameters['start_atom']);
$now = $this->timeFactory->getDateTime();
$title = $this->getTitleFromParameters($parameters);
@@ -220,8 +216,8 @@ class Notifier implements INotifier {
* @throws \Exception
*/
private function generateDateString(array $parameters):string {
- $startDateTime = DateTime::createFromFormat(DATE_ATOM, $parameters['start_atom']);
- $endDateTime = DateTime::createFromFormat(DATE_ATOM, $parameters['end_atom']);
+ $startDateTime = DateTime::createFromFormat(\DateTime::ATOM, $parameters['start_atom']);
+ $endDateTime = DateTime::createFromFormat(\DateTime::ATOM, $parameters['end_atom']);
$isAllDay = $parameters['all_day'];
$diff = $startDateTime->diff($endDateTime);
diff --git a/apps/dav/lib/CalDAV/Reminder/ReminderService.php b/apps/dav/lib/CalDAV/Reminder/ReminderService.php
index ad428eef745..f36ddd157cc 100644
--- a/apps/dav/lib/CalDAV/Reminder/ReminderService.php
+++ b/apps/dav/lib/CalDAV/Reminder/ReminderService.php
@@ -24,7 +24,7 @@ declare(strict_types=1);
*/
namespace OCA\DAV\CalDAV\Reminder;
-use DateTimeImmutable;
+use \DateTimeImmutable;
use OCA\DAV\CalDAV\CalDavBackend;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IGroup;
@@ -40,11 +40,11 @@ use Sabre\VObject\Recur\NoInstancesException;
class ReminderService {
- /** @var Backend */
- private $backend;
+ /** @var Backend */
+ private $backend;
- /** @var NotificationProviderManager */
- private $notificationProviderManager;
+ /** @var NotificationProviderManager */
+ private $notificationProviderManager;
/** @var IUserManager */
private $userManager;
@@ -83,19 +83,19 @@ class ReminderService {
* @param CalDavBackend $caldavBackend
* @param ITimeFactory $timeFactory
*/
- public function __construct(Backend $backend,
- NotificationProviderManager $notificationProviderManager,
+ public function __construct(Backend $backend,
+ NotificationProviderManager $notificationProviderManager,
IUserManager $userManager,
IGroupManager $groupManager,
CalDavBackend $caldavBackend,
ITimeFactory $timeFactory) {
- $this->backend = $backend;
- $this->notificationProviderManager = $notificationProviderManager;
+ $this->backend = $backend;
+ $this->notificationProviderManager = $notificationProviderManager;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->caldavBackend = $caldavBackend;
$this->timeFactory = $timeFactory;
- }
+ }
/**
* Process reminders to activate
@@ -103,12 +103,12 @@ class ReminderService {
* @throws NotificationProvider\ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException
*/
- public function processReminders():void {
- $reminders = $this->backend->getRemindersToProcess();
+ public function processReminders():void {
+ $reminders = $this->backend->getRemindersToProcess();
- foreach($reminders as $reminder) {
- $vcalendar = $this->parseCalendarData($reminder['calendardata']);
- if (!$vcalendar) {
+ foreach($reminders as $reminder) {
+ $vcalendar = $this->parseCalendarData($reminder['calendardata']);
+ if (!$vcalendar) {
$this->backend->removeReminder($reminder['id']);
continue;
}
@@ -140,7 +140,7 @@ class ReminderService {
$this->deleteOrProcessNext($reminder, $vevent);
}
- }
+ }
/**
* @param string $action
@@ -175,7 +175,7 @@ class ReminderService {
/**
* @param array $objectData
*/
- private function onCalendarObjectCreate(array $objectData):void {
+ private function onCalendarObjectCreate(array $objectData):void {
/** @var VObject\Component\VCalendar $vcalendar */
$vcalendar = $this->parseCalendarData($objectData['calendardata']);
if (!$vcalendar) {
@@ -343,7 +343,7 @@ class ReminderService {
'is_repeat_based' => false,
];
- $repeat = $valarm->REPEAT ? (int) $valarm->REPEAT : 0;
+ $repeat = isset($valarm->REPEAT) ? (int) $valarm->REPEAT->getValue() : 0;
for($i = 0; $i < $repeat; $i++) {
if ($valarm->DURATION === null) {
continue;
@@ -671,7 +671,7 @@ class ReminderService {
return null;
}
- if (strcasecmp($principalUri, 'principals/users/') !== 0) {
+ if (stripos($principalUri, 'principals/users/') !== 0) {
return null;
}