Clean up reminder actions and call methods directly
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
257613e6ef
commit
f5462650f1
|
@ -125,7 +125,7 @@ class BuildReminderIndexBackgroundJob extends QueuedJob {
|
||||||
$row['component'] = $row['componenttype'];
|
$row['component'] = $row['componenttype'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->reminderService->onTouchCalendarObject('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $row);
|
$this->reminderService->onCalendarObjectCreate($row);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
$this->logger->logException($ex);
|
$this->logger->logException($ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ use Sabre\VObject\InvalidDataException;
|
||||||
use Sabre\VObject\ParseException;
|
use Sabre\VObject\ParseException;
|
||||||
use Sabre\VObject\Recur\EventIterator;
|
use Sabre\VObject\Recur\EventIterator;
|
||||||
use Sabre\VObject\Recur\NoInstancesException;
|
use Sabre\VObject\Recur\NoInstancesException;
|
||||||
|
use function strcasecmp;
|
||||||
|
|
||||||
class ReminderService {
|
class ReminderService {
|
||||||
|
|
||||||
|
@ -154,39 +155,15 @@ class ReminderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $action
|
|
||||||
* @param array $objectData
|
* @param array $objectData
|
||||||
* @throws VObject\InvalidDataException
|
* @throws VObject\InvalidDataException
|
||||||
*/
|
*/
|
||||||
public function onTouchCalendarObject(string $action,
|
public function onCalendarObjectCreate(array $objectData):void {
|
||||||
array $objectData):void {
|
|
||||||
// We only support VEvents for now
|
// We only support VEvents for now
|
||||||
if (strcasecmp($objectData['component'], 'vevent') !== 0) {
|
if (strcasecmp($objectData['component'], 'vevent') !== 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($action) {
|
|
||||||
case '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject':
|
|
||||||
$this->onCalendarObjectCreate($objectData);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject':
|
|
||||||
$this->onCalendarObjectEdit($objectData);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject':
|
|
||||||
$this->onCalendarObjectDelete($objectData);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $objectData
|
|
||||||
*/
|
|
||||||
private function onCalendarObjectCreate(array $objectData):void {
|
|
||||||
$calendarData = is_resource($objectData['calendardata'])
|
$calendarData = is_resource($objectData['calendardata'])
|
||||||
? stream_get_contents($objectData['calendardata'])
|
? stream_get_contents($objectData['calendardata'])
|
||||||
: $objectData['calendardata'];
|
: $objectData['calendardata'];
|
||||||
|
@ -307,8 +284,9 @@ class ReminderService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $objectData
|
* @param array $objectData
|
||||||
|
* @throws VObject\InvalidDataException
|
||||||
*/
|
*/
|
||||||
private function onCalendarObjectEdit(array $objectData):void {
|
public function onCalendarObjectEdit(array $objectData):void {
|
||||||
// TODO - this can be vastly improved
|
// TODO - this can be vastly improved
|
||||||
// - get cached reminders
|
// - get cached reminders
|
||||||
// - ...
|
// - ...
|
||||||
|
@ -319,8 +297,14 @@ class ReminderService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $objectData
|
* @param array $objectData
|
||||||
|
* @throws VObject\InvalidDataException
|
||||||
*/
|
*/
|
||||||
private function onCalendarObjectDelete(array $objectData):void {
|
public function onCalendarObjectDelete(array $objectData):void {
|
||||||
|
// We only support VEvents for now
|
||||||
|
if (strcasecmp($objectData['component'], 'vevent') !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->backend->cleanRemindersForEvent((int) $objectData['id']);
|
$this->backend->cleanRemindersForEvent((int) $objectData['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,8 +74,7 @@ class CalendarObjectReminderUpdaterListener implements IEventListener {
|
||||||
}
|
}
|
||||||
} elseif ($event instanceof CalendarObjectCreatedEvent) {
|
} elseif ($event instanceof CalendarObjectCreatedEvent) {
|
||||||
try {
|
try {
|
||||||
$this->reminderService->onTouchCalendarObject(
|
$this->reminderService->onCalendarObjectCreate(
|
||||||
'\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject',
|
|
||||||
$event->getObjectData()
|
$event->getObjectData()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -90,8 +89,7 @@ class CalendarObjectReminderUpdaterListener implements IEventListener {
|
||||||
}
|
}
|
||||||
} elseif ($event instanceof CalendarObjectUpdatedEvent) {
|
} elseif ($event instanceof CalendarObjectUpdatedEvent) {
|
||||||
try {
|
try {
|
||||||
$this->reminderService->onTouchCalendarObject(
|
$this->reminderService->onCalendarObjectEdit(
|
||||||
'\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject',
|
|
||||||
$event->getObjectData()
|
$event->getObjectData()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -106,8 +104,7 @@ class CalendarObjectReminderUpdaterListener implements IEventListener {
|
||||||
}
|
}
|
||||||
} elseif ($event instanceof CalendarObjectDeletedEvent) {
|
} elseif ($event instanceof CalendarObjectDeletedEvent) {
|
||||||
try {
|
try {
|
||||||
$this->reminderService->onTouchCalendarObject(
|
$this->reminderService->onCalendarObjectDelete(
|
||||||
'\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject',
|
|
||||||
$event->getObjectData()
|
$event->getObjectData()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -211,17 +211,15 @@ EOD;
|
||||||
->method('cleanRemindersForEvent')
|
->method('cleanRemindersForEvent')
|
||||||
->with(44);
|
->with(44);
|
||||||
|
|
||||||
$action = '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject';
|
|
||||||
$objectData = [
|
$objectData = [
|
||||||
'id' => '44',
|
'id' => '44',
|
||||||
'component' => 'vevent',
|
'component' => 'vevent',
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
$this->reminderService->onCalendarObjectDelete($objectData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOnCalendarObjectCreateSingleEntry():void {
|
public function testOnCalendarObjectCreateSingleEntry():void {
|
||||||
$action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
|
|
||||||
$objectData = [
|
$objectData = [
|
||||||
'calendardata' => self::CALENDAR_DATA,
|
'calendardata' => self::CALENDAR_DATA,
|
||||||
'id' => '42',
|
'id' => '42',
|
||||||
|
@ -242,11 +240,10 @@ EOD;
|
||||||
->with()
|
->with()
|
||||||
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
|
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
|
||||||
|
|
||||||
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
$this->reminderService->onCalendarObjectCreate($objectData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOnCalendarObjectCreateSingleEntryWithRepeat(): void {
|
public function testOnCalendarObjectCreateSingleEntryWithRepeat(): void {
|
||||||
$action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
|
|
||||||
$objectData = [
|
$objectData = [
|
||||||
'calendardata' => self::CALENDAR_DATA_REPEAT,
|
'calendardata' => self::CALENDAR_DATA_REPEAT,
|
||||||
'id' => '42',
|
'id' => '42',
|
||||||
|
@ -270,11 +267,10 @@ EOD;
|
||||||
->with()
|
->with()
|
||||||
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
|
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
|
||||||
|
|
||||||
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
$this->reminderService->onCalendarObjectCreate($objectData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOnCalendarObjectCreateRecurringEntry(): void {
|
public function testOnCalendarObjectCreateRecurringEntry(): void {
|
||||||
$action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
|
|
||||||
$objectData = [
|
$objectData = [
|
||||||
'calendardata' => self::CALENDAR_DATA_RECURRING,
|
'calendardata' => self::CALENDAR_DATA_RECURRING,
|
||||||
'id' => '42',
|
'id' => '42',
|
||||||
|
@ -295,11 +291,10 @@ EOD;
|
||||||
->with()
|
->with()
|
||||||
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
|
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
|
||||||
|
|
||||||
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
$this->reminderService->onCalendarObjectCreate($objectData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOnCalendarObjectCreateEmpty():void {
|
public function testOnCalendarObjectCreateEmpty():void {
|
||||||
$action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
|
|
||||||
$objectData = [
|
$objectData = [
|
||||||
'calendardata' => self::CALENDAR_DATA_NO_ALARM,
|
'calendardata' => self::CALENDAR_DATA_NO_ALARM,
|
||||||
'id' => '42',
|
'id' => '42',
|
||||||
|
@ -310,11 +305,10 @@ EOD;
|
||||||
$this->backend->expects($this->never())
|
$this->backend->expects($this->never())
|
||||||
->method('insertReminder');
|
->method('insertReminder');
|
||||||
|
|
||||||
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
$this->reminderService->onCalendarObjectCreate($objectData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOnCalendarObjectCreateRecurringEntryWithRepeat():void {
|
public function testOnCalendarObjectCreateRecurringEntryWithRepeat():void {
|
||||||
$action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
|
|
||||||
$objectData = [
|
$objectData = [
|
||||||
'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
|
'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
|
||||||
'id' => '42',
|
'id' => '42',
|
||||||
|
@ -339,7 +333,7 @@ EOD;
|
||||||
->with()
|
->with()
|
||||||
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
|
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
|
||||||
|
|
||||||
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
$this->reminderService->onCalendarObjectCreate($objectData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testProcessReminders():void {
|
public function testProcessReminders():void {
|
||||||
|
|
Loading…
Reference in New Issue