smaller syntax changes to CalDAV reminder classes

Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
Georg Ehrke 2019-08-02 16:34:39 +02:00 committed by Roeland Jago Douma
parent 36b9b51297
commit 11fa45196e
No known key found for this signature in database
GPG Key ID: F941078878347C0C
7 changed files with 38 additions and 56 deletions

View File

@ -37,9 +37,9 @@ use Sabre\VObject\DateTimeParser;
use Sabre\VObject\Parameter; use Sabre\VObject\Parameter;
use Sabre\VObject\Property; use Sabre\VObject\Property;
abstract class AbstractNotificationProvider abstract class AbstractNotificationProvider {
{
/** @var string */
public const NOTIFICATION_TYPE = ''; public const NOTIFICATION_TYPE = '';
/** @var ILogger */ /** @var ILogger */
@ -78,7 +78,7 @@ abstract class AbstractNotificationProvider
* @param IUser $user * @param IUser $user
* @return void * @return void
*/ */
public function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user): void {} abstract function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user): void;
/** /**
* @var VCalendar $vcalendar * @var VCalendar $vcalendar
@ -86,8 +86,7 @@ abstract class AbstractNotificationProvider
* @return array * @return array
* @throws \Exception * @throws \Exception
*/ */
protected function extractEventDetails(VCalendar $vcalendar, $defaultValue = ''): array protected function extractEventDetails(VCalendar $vcalendar, $defaultValue = ''):array {
{
/** @var VEvent $vevent */ /** @var VEvent $vevent */
$vevent = $vcalendar->VEVENT; $vevent = $vcalendar->VEVENT;
@ -129,8 +128,7 @@ abstract class AbstractNotificationProvider
* @return string * @return string
* @throws \Exception * @throws \Exception
*/ */
private function generateWhenString(Property $dtstart, Property $dtend): string private function generateWhenString(Property $dtstart, Property $dtend):string {
{
$isAllDay = $dtstart instanceof Property\ICalendar\Date; $isAllDay = $dtstart instanceof Property\ICalendar\Date;
/** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */ /** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */
@ -201,8 +199,7 @@ abstract class AbstractNotificationProvider
* @param DateTime $dtEnd * @param DateTime $dtEnd
* @return bool * @return bool
*/ */
private function isDayEqual(DateTime $dtStart, DateTime $dtEnd): bool private function isDayEqual(DateTime $dtStart, DateTime $dtEnd):bool {
{
return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d'); return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d');
} }
} }

View File

@ -56,8 +56,7 @@ class Backend {
* @param int $notificationDate * @param int $notificationDate
* @param int $eventStartDate * @param int $eventStartDate
*/ */
public function insertReminder(string $uid, string $calendarId, string $uri, string $type, int $notificationDate, int $eventStartDate): void public function insertReminder(string $uid, string $calendarId, string $uri, string $type, int $notificationDate, int $eventStartDate):void {
{
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->insert('calendar_reminders') $query->insert('calendar_reminders')
->values([ ->values([
@ -76,8 +75,7 @@ class Backend {
* @param int $calendarId * @param int $calendarId
* @param string $objectUri * @param string $objectUri
*/ */
public function cleanRemindersForEvent(int $calendarId, string $objectUri): void public function cleanRemindersForEvent(int $calendarId, string $objectUri):void {
{
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->delete('calendar_reminders') $query->delete('calendar_reminders')
@ -92,8 +90,7 @@ class Backend {
* @param integer $calendarId * @param integer $calendarId
* @return void * @return void
*/ */
public function cleanRemindersForCalendar(int $calendarId): void public function cleanRemindersForCalendar(int $calendarId):void {
{
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->delete('calendar_reminders') $query->delete('calendar_reminders')
@ -107,8 +104,7 @@ class Backend {
* @param integer $reminderId * @param integer $reminderId
* @return void * @return void
*/ */
public function removeReminder(int $reminderId): void public function removeReminder(int $reminderId):void {
{
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->delete('calendar_reminders') $query->delete('calendar_reminders')
@ -122,8 +118,7 @@ class Backend {
* @return array * @return array
* @throws \Exception * @throws \Exception
*/ */
public function getRemindersToProcess(): array public function getRemindersToProcess():array {
{
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$fields = ['cr.id', 'cr.calendarid', 'cr.objecturi', 'cr.type', 'cr.notificationdate', 'cr.uid', 'co.calendardata', 'c.displayname']; $fields = ['cr.id', 'cr.calendarid', 'cr.objecturi', 'cr.type', 'cr.notificationdate', 'cr.uid', 'co.calendardata', 'c.displayname'];
$stmt = $query->select($fields) $stmt = $query->select($fields)

View File

@ -33,11 +33,12 @@ use OCP\Mail\IMailer;
use OCP\IUser; use OCP\IUser;
use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCalendar;
class EmailProvider extends AbstractNotificationProvider class EmailProvider extends AbstractNotificationProvider {
{
/** @var IMailer */ /** @var IMailer */
private $mailer; private $mailer;
/** @var string */
public const NOTIFICATION_TYPE = 'EMAIL'; public const NOTIFICATION_TYPE = 'EMAIL';
/** /**
@ -63,8 +64,7 @@ class EmailProvider extends AbstractNotificationProvider
* @return void * @return void
* @throws \Exception * @throws \Exception
*/ */
public function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user): void public function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user):void {
{
if ($user->getEMailAddress() === null) { if ($user->getEMailAddress() === null) {
return; return;
} }
@ -111,8 +111,7 @@ class EmailProvider extends AbstractNotificationProvider
* @param IEMailTemplate $template * @param IEMailTemplate $template
* @param string $summary * @param string $summary
*/ */
private function addSubjectAndHeading(IEMailTemplate $template, string $summary): void private function addSubjectAndHeading(IEMailTemplate $template, string $summary):void {
{
$template->setSubject('Notification: ' . $summary); $template->setSubject('Notification: ' . $summary);
$template->addHeading($summary); $template->addHeading($summary);
} }
@ -122,8 +121,7 @@ class EmailProvider extends AbstractNotificationProvider
* @param array $eventData * @param array $eventData
* @param string $calendarDisplayName * @param string $calendarDisplayName
*/ */
private function addBulletList(IEMailTemplate $template, array $eventData, string $calendarDisplayName): void private function addBulletList(IEMailTemplate $template, array $eventData, string $calendarDisplayName):void {
{
$template->addBodyListItem($calendarDisplayName, $this->l10n->t('Calendar:'), $template->addBodyListItem($calendarDisplayName, $this->l10n->t('Calendar:'),
$this->getAbsoluteImagePath('actions/info.svg')); $this->getAbsoluteImagePath('actions/info.svg'));
@ -148,8 +146,7 @@ class EmailProvider extends AbstractNotificationProvider
* @param string $path * @param string $path
* @return string * @return string
*/ */
private function getAbsoluteImagePath($path): string private function getAbsoluteImagePath(string $path):string {
{
return $this->urlGenerator->getAbsoluteURL( return $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->imagePath('core', $path) $this->urlGenerator->imagePath('core', $path)
); );

View File

@ -35,9 +35,9 @@ use OCP\Notification\INotification;
use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCalendar;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
class PushProvider extends AbstractNotificationProvider class PushProvider extends AbstractNotificationProvider {
{
/** @var string */
public const NOTIFICATION_TYPE = 'DISPLAY'; public const NOTIFICATION_TYPE = 'DISPLAY';
/** /**
@ -75,9 +75,7 @@ class PushProvider extends AbstractNotificationProvider
* @return void * @return void
* @throws \Exception * @throws \Exception
*/ */
public function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user): void public function send(VCalendar $vcalendar, string $calendarDisplayName, IUser $user):void {
{
$lang = $this->config->getUserValue($user->getUID(), 'core', 'lang', $this->l10nFactory->findLanguage()); $lang = $this->config->getUserValue($user->getUID(), 'core', 'lang', $this->l10nFactory->findLanguage());
$this->l10n = $this->l10nFactory->get('dav', $lang); $this->l10n = $this->l10nFactory->get('dav', $lang);

View File

@ -31,8 +31,7 @@ class NotificationProviderManager {
* @throws ProviderNotAvailableException * @throws ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException * @throws NotificationTypeDoesNotExistException
*/ */
public function getProvider(string $type): AbstractNotificationProvider public function getProvider(string $type):AbstractNotificationProvider {
{
if (in_array($type, ReminderService::REMINDER_TYPES, true)) { if (in_array($type, ReminderService::REMINDER_TYPES, true)) {
if (isset($this->providers[$type])) { if (isset($this->providers[$type])) {
return $this->providers[$type]; return $this->providers[$type];
@ -46,8 +45,7 @@ class NotificationProviderManager {
* @param string $providerClassName * @param string $providerClassName
* @throws \OCP\AppFramework\QueryException * @throws \OCP\AppFramework\QueryException
*/ */
public function registerProvider(string $providerClassName): void public function registerProvider(string $providerClassName):void {
{
$provider = \OC::$server->query($providerClassName); $provider = \OC::$server->query($providerClassName);
if (!$provider instanceof AbstractNotificationProvider) { if (!$provider instanceof AbstractNotificationProvider) {

View File

@ -31,14 +31,15 @@ use OCP\IURLGenerator;
class Notifier implements INotifier { class Notifier implements INotifier {
public static $units = array( /** @var array */
public static $units = [
'y' => 'year', 'y' => 'year',
'm' => 'month', 'm' => 'month',
'd' => 'day', 'd' => 'day',
'h' => 'hour', 'h' => 'hour',
'i' => 'minute', 'i' => 'minute',
's' => 'second', 's' => 'second',
); ];
/** @var IFactory */ /** @var IFactory */
protected $factory; protected $factory;
@ -60,8 +61,7 @@ class Notifier implements INotifier {
* @return INotification * @return INotification
* @throws \Exception * @throws \Exception
*/ */
public function prepare(INotification $notification, $languageCode): INotification public function prepare(INotification $notification, string $languageCode):INotification {
{
if ($notification->getApp() !== Application::APP_ID) { if ($notification->getApp() !== Application::APP_ID) {
throw new \InvalidArgumentException('Notification not from this app'); throw new \InvalidArgumentException('Notification not from this app');
} }
@ -87,8 +87,7 @@ class Notifier implements INotifier {
* @return string * @return string
* @throws \Exception * @throws \Exception
*/ */
private function processEventTitle(array $event): string private function processEventTitle(array $event):string {
{
$event_datetime = new \DateTime(); $event_datetime = new \DateTime();
$event_datetime->setTimestamp($event['start']); $event_datetime->setTimestamp($event['start']);
$now = new \DateTime(); $now = new \DateTime();
@ -112,8 +111,7 @@ class Notifier implements INotifier {
* @param string $title * @param string $title
* @return string * @return string
*/ */
private function getPluralizedTitle(int $count, int $invert, string $unit, string $title): string private function getPluralizedTitle(int $count, int $invert, string $unit, string $title):string {
{
if ($invert) { if ($invert) {
return $this->l->n('%s (in one %s)', '%s (in %n %ss)', $count, [$title, $unit]); return $this->l->n('%s (in one %s)', '%s (in %n %ss)', $count, [$title, $unit]);
} }
@ -125,8 +123,7 @@ class Notifier implements INotifier {
* @param array $event * @param array $event
* @return string * @return string
*/ */
private function processEventDescription(array $event): string private function processEventDescription(array $event):string {
{
$description = [ $description = [
$this->l->t('Calendar: %s', $event['calendar']), $this->l->t('Calendar: %s', $event['calendar']),
$this->l->t('Date: %s', $event['when']), $this->l->t('Date: %s', $event['when']),

View File

@ -49,7 +49,11 @@ class ReminderService {
public const REMINDER_TYPE_DISPLAY = 'DISPLAY'; public const REMINDER_TYPE_DISPLAY = 'DISPLAY';
public const REMINDER_TYPE_AUDIO = 'AUDIO'; public const REMINDER_TYPE_AUDIO = 'AUDIO';
public const REMINDER_TYPES = [self::REMINDER_TYPE_EMAIL, self::REMINDER_TYPE_DISPLAY, self::REMINDER_TYPE_AUDIO]; public const REMINDER_TYPES = [
self::REMINDER_TYPE_EMAIL,
self::REMINDER_TYPE_DISPLAY,
self::REMINDER_TYPE_AUDIO
];
public function __construct(Backend $backend, public function __construct(Backend $backend,
NotificationProviderManager $notificationProviderManager, NotificationProviderManager $notificationProviderManager,
@ -70,9 +74,7 @@ class ReminderService {
* @throws NotificationProvider\ProviderNotAvailableException * @throws NotificationProvider\ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException * @throws NotificationTypeDoesNotExistException
*/ */
public function processReminders(): void public function processReminders():void {
{
$reminders = $this->backend->getRemindersToProcess(); $reminders = $this->backend->getRemindersToProcess();
foreach ($reminders as $reminder) { foreach ($reminders as $reminder) {
@ -101,8 +103,7 @@ class ReminderService {
* @throws VObject\InvalidDataException * @throws VObject\InvalidDataException
* @throws NoUserException * @throws NoUserException
*/ */
public function onTouchCalendarObject(string $action, array $calendarData, array $shares, array $objectData): void public function onTouchCalendarObject(string $action, array $calendarData, array $shares, array $objectData):void {
{
if (!isset($calendarData['principaluri'])) { if (!isset($calendarData['principaluri'])) {
return; return;
} }
@ -157,8 +158,7 @@ class ReminderService {
* @param array $shares * @param array $shares
* @return string[] * @return string[]
*/ */
private function getUsersForShares(array $shares): array private function getUsersForShares(array $shares):array {
{
$users = $groups = []; $users = $groups = [];
foreach ($shares as $share) { foreach ($shares as $share) {
$principal = explode('/', $share['{http://owncloud.org/ns}principal']); $principal = explode('/', $share['{http://owncloud.org/ns}principal']);