Browse Source

Fix phpStorm complaints

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/6402/head
Joas Schilling 9 years ago
committed by Georg Ehrke
parent
commit
cf04093fa6
No known key found for this signature in database GPG Key ID: 9D98FD9380A1CB43
  1. 10
      apps/dav/appinfo/v1/caldav.php
  2. 87
      apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
  3. 10
      apps/dav/lib/Server.php

10
apps/dav/appinfo/v1/caldav.php

@ -87,15 +87,7 @@ $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
if ($sendInvitations) { if ($sendInvitations) {
$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\IMipPlugin(
'dav', // TODO(leon): Retrieve dynamically, but where to find it? :(
\OC::$server->getUserSession()->getUser()->getUID(),
\OC::$server->getConfig(),
\OC::$server->getMailer(),
\OC::$server->getLogger(),
new \OC\AppFramework\Utility\TimeFactory(),
\OC::$server->getL10NFactory()
));
$server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
} }
$server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger())); $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger()));

87
apps/dav/lib/CalDAV/Schedule/IMipPlugin.php

@ -23,17 +23,19 @@
*/ */
namespace OCA\DAV\CalDAV\Schedule; namespace OCA\DAV\CalDAV\Schedule;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
use OCP\L10N\IFactory as L10NFactory; use OCP\L10N\IFactory as L10NFactory;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin; use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin;
use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VEvent;
use Sabre\VObject\DateTimeParser; use Sabre\VObject\DateTimeParser;
use Sabre\VObject\ITip;
use Sabre\VObject\ITip\Message;
use Sabre\VObject\Parameter; use Sabre\VObject\Parameter;
use Sabre\VObject\Property;
use Sabre\VObject\Recur\EventIterator; use Sabre\VObject\Recur\EventIterator;
use Swift_Attachment; use Swift_Attachment;
/** /**
@ -52,9 +54,6 @@ use Swift_Attachment;
*/ */
class IMipPlugin extends SabreIMipPlugin { class IMipPlugin extends SabreIMipPlugin {
/** @var string */
private $appName;
/** @var string */ /** @var string */
private $userId; private $userId;
@ -80,19 +79,15 @@ class IMipPlugin extends SabreIMipPlugin {
const METHOD_CANCEL = 'cancel'; const METHOD_CANCEL = 'cancel';
/** /**
* Creates the email handler.
*
* @param string $appName
* @param string $userId
* @param IConfig $config * @param IConfig $config
* @param IMailer $mailer * @param IMailer $mailer
* @param ILogger $logger * @param ILogger $logger
* @param ITimeFactory $timeFactory * @param ITimeFactory $timeFactory
* @param L10NFactory $l10nFactory * @param L10NFactory $l10nFactory
* @param string $userId
*/ */
function __construct($appName, $userId, IConfig $config, IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory, L10NFactory $l10nFactory) {
public function __construct(IConfig $config, IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory, L10NFactory $l10nFactory, $userId) {
parent::__construct(''); parent::__construct('');
$this->appName = $appName;
$this->userId = $userId; $this->userId = $userId;
$this->config = $config; $this->config = $config;
$this->mailer = $mailer; $this->mailer = $mailer;
@ -104,10 +99,10 @@ class IMipPlugin extends SabreIMipPlugin {
/** /**
* Event handler for the 'schedule' event. * Event handler for the 'schedule' event.
* *
* @param ITip\Message $iTipMessage
* @param Message $iTipMessage
* @return void * @return void
*/ */
function schedule(ITip\Message $iTipMessage) {
public function schedule(Message $iTipMessage) {
// Not sending any emails if the system considers the update // Not sending any emails if the system considers the update
// insignificant. // insignificant.
@ -133,19 +128,14 @@ class IMipPlugin extends SabreIMipPlugin {
return; return;
} }
// Strip off mailto:
$sender = substr($iTipMessage->sender, 7); $sender = substr($iTipMessage->sender, 7);
$recipient = substr($iTipMessage->recipient, 7); $recipient = substr($iTipMessage->recipient, 7);
$senderName = ($iTipMessage->senderName) ? $iTipMessage->senderName : null;
$recipientName = ($iTipMessage->recipientName) ? $iTipMessage->recipientName : null;
$senderName = $iTipMessage->senderName ?: null;
$recipientName = $iTipMessage->recipientName ?: null;
$subject = 'SabreDAV iTIP message';
switch (strtolower($iTipMessage->method)) { switch (strtolower($iTipMessage->method)) {
default: // Treat 'REQUEST' as the default
case self::METHOD_REQUEST:
$subject = $summary;
$templateName = self::METHOD_REQUEST;
break;
case self::METHOD_REPLY: case self::METHOD_REPLY:
$subject = 'Re: ' . $summary; $subject = 'Re: ' . $summary;
$templateName = self::METHOD_REPLY; $templateName = self::METHOD_REPLY;
@ -154,17 +144,23 @@ class IMipPlugin extends SabreIMipPlugin {
$subject = 'Cancelled: ' . $summary; $subject = 'Cancelled: ' . $summary;
$templateName = self::METHOD_CANCEL; $templateName = self::METHOD_CANCEL;
break; break;
case self::METHOD_REQUEST:
default: // Treat 'REQUEST' as the default
$subject = $summary;
$templateName = self::METHOD_REQUEST;
break;
} }
/** @var VEvent $vevent */
$vevent = $iTipMessage->message->VEVENT; $vevent = $iTipMessage->message->VEVENT;
$attendee = $this->getCurrentAttendee($iTipMessage); $attendee = $this->getCurrentAttendee($iTipMessage);
$defaultLang = $this->config->getUserValue($this->userId, 'core', 'lang', $this->l10nFactory->findLanguage()); $defaultLang = $this->config->getUserValue($this->userId, 'core', 'lang', $this->l10nFactory->findLanguage());
$lang = $this->getAttendeeLangOrDefault($attendee, $defaultLang);
$l10n = $this->l10nFactory->get($this->appName, $lang);
$lang = $this->getAttendeeLangOrDefault($defaultLang, $attendee);
$l10n = $this->l10nFactory->get('dav', $lang);
$meetingAttendeeName = !empty($recipientName) ? $recipientName : $recipient;
$meetingInviteeName = !empty($senderName) ? $senderName : $sender;
$meetingAttendeeName = $recipientName ?: $recipient;
$meetingInviteeName = $senderName ?: $sender;
$meetingTitle = $vevent->SUMMARY; $meetingTitle = $vevent->SUMMARY;
$meetingDescription = $vevent->DESCRIPTION; $meetingDescription = $vevent->DESCRIPTION;
@ -209,11 +205,11 @@ class IMipPlugin extends SabreIMipPlugin {
try { try {
$failed = $this->mailer->send($message); $failed = $this->mailer->send($message);
$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
if ($failed) { if ($failed) {
$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]); $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
} }
$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
} catch(\Exception $ex) { } catch(\Exception $ex) {
$this->logger->logException($ex, ['app' => 'dav']); $this->logger->logException($ex, ['app' => 'dav']);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
@ -226,6 +222,7 @@ class IMipPlugin extends SabreIMipPlugin {
* @return bool * @return bool
*/ */
private function isEventInThePast(VCalendar $vObject) { private function isEventInThePast(VCalendar $vObject) {
/** @var VEvent $component */
$component = $vObject->VEVENT; $component = $vObject->VEVENT;
$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
@ -234,15 +231,17 @@ class IMipPlugin extends SabreIMipPlugin {
if (isset($component->DTEND)) { if (isset($component->DTEND)) {
$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
} elseif (isset($component->DURATION)) { } elseif (isset($component->DURATION)) {
/** @var \DateTime $endDate */
$endDate = clone $component->DTSTART->getDateTime(); $endDate = clone $component->DTSTART->getDateTime();
// $component->DTEND->getDateTime() returns DateTimeImmutable // $component->DTEND->getDateTime() returns DateTimeImmutable
$endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); $endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
$lastOccurrence = $endDate->getTimeStamp();
$lastOccurrence = $endDate->getTimestamp();
} elseif (!$component->DTSTART->hasTime()) { } elseif (!$component->DTSTART->hasTime()) {
/** @var \DateTime $endDate */
$endDate = clone $component->DTSTART->getDateTime(); $endDate = clone $component->DTSTART->getDateTime();
// $component->DTSTART->getDateTime() returns DateTimeImmutable // $component->DTSTART->getDateTime() returns DateTimeImmutable
$endDate = $endDate->modify('+1 day'); $endDate = $endDate->modify('+1 day');
$lastOccurrence = $endDate->getTimeStamp();
$lastOccurrence = $endDate->getTimestamp();
} else { } else {
$lastOccurrence = $firstOccurrence; $lastOccurrence = $firstOccurrence;
} }
@ -266,12 +265,21 @@ class IMipPlugin extends SabreIMipPlugin {
return $lastOccurrence < $currentTime; return $lastOccurrence < $currentTime;
} }
/**
* @param string $scope
* @return \OCP\Mail\IEMailTemplate
*/
private function getEmptyInviteTemplate($scope) { private function getEmptyInviteTemplate($scope) {
return $this->mailer->createEMailTemplate('dav.invite.' . $scope, array());
return $this->mailer->createEMailTemplate('dav.invite.' . $scope, []);
} }
private function getInviteTemplates($l10n, $_) {
$ret = array();
/**
* @param IL10N $l10n
* @param array $_
* @return array
*/
private function getInviteTemplates(IL10N $l10n, array $_) {
$ret = [];
$requestTmpl = $ret[self::METHOD_REQUEST] = $this->getEmptyInviteTemplate(self::METHOD_REQUEST); $requestTmpl = $ret[self::METHOD_REQUEST] = $this->getEmptyInviteTemplate(self::METHOD_REQUEST);
$replyTmpl = $ret[self::METHOD_REPLY] = $this->getEmptyInviteTemplate(self::METHOD_REPLY); $replyTmpl = $ret[self::METHOD_REPLY] = $this->getEmptyInviteTemplate(self::METHOD_REPLY);
$cancelTmpl = $ret[self::METHOD_CANCEL] = $this->getEmptyInviteTemplate(self::METHOD_CANCEL); $cancelTmpl = $ret[self::METHOD_CANCEL] = $this->getEmptyInviteTemplate(self::METHOD_CANCEL);
@ -305,10 +313,16 @@ Description: %s
return $ret; return $ret;
} }
private function getCurrentAttendee($iTipMessage) {
/**
* @param Message $iTipMessage
* @return null|Property
*/
private function getCurrentAttendee(Message $iTipMessage) {
/** @var VEvent $vevent */
$vevent = $iTipMessage->message->VEVENT; $vevent = $iTipMessage->message->VEVENT;
$attendees = $vevent->select('ATTENDEE'); $attendees = $vevent->select('ATTENDEE');
foreach ($attendees as $attendee) { foreach ($attendees as $attendee) {
/** @var Property $attendee */
if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) { if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) {
return $attendee; return $attendee;
} }
@ -316,8 +330,13 @@ Description: %s
return null; return null;
} }
private function getAttendeeLangOrDefault($attendee, $default) {
if ($attendee) {
/**
* @param string $default
* @param Property|null $attendee
* @return string
*/
private function getAttendeeLangOrDefault($default, Property $attendee = null) {
if ($attendee !== null) {
$lang = $attendee->offsetGet('LANGUAGE'); $lang = $attendee->offsetGet('LANGUAGE');
if ($lang instanceof Parameter) { if ($lang instanceof Parameter) {
return $lang->getValue(); return $lang->getValue();

10
apps/dav/lib/Server.php

@ -140,15 +140,7 @@ class Server {
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
if ($sendInvitations) { if ($sendInvitations) {
$this->server->addPlugin(new IMipPlugin(
'dav', // TODO(leon): Retrieve dynamically, but where to find it? :(
\OC::$server->getUserSession()->getUser()->getUID(),
\OC::$server->getConfig(),
$mailer,
$logger,
$timezone,
$l10nFactory
));
$this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
} }
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());

Loading…
Cancel
Save