Skip to content

Commit

Permalink
Start refactoring handling of exceptions/recurrence during save.
Browse files Browse the repository at this point in the history
This commit extracts commons iCal related code and wraps dav specific logic.
(Hopefully) fixes Bug: 13898 and Bug: 13815.

Still need to refactor other places we deal with exceptions.

Conflicts:
	kronolith/package.xml
  • Loading branch information
mrubinsk authored and yunosh committed Mar 19, 2015
1 parent 3a8da6d commit 284d73a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 71 deletions.
60 changes: 4 additions & 56 deletions kronolith/lib/Application.php
Expand Up @@ -815,62 +815,10 @@ public function davPutObject($collection, $object, $data)
if (!$ical->parsevCalendar($data)) {
throw new Kronolith_Exception(_("There was an error importing the iCalendar data."));
}

$kronolith_driver = Kronolith::getDriver(null, $internal);

foreach ($ical->getComponents() as $content) {
if (!($content instanceof Horde_Icalendar_Vevent)) {
continue;
}

$event = $kronolith_driver->getEvent();
$event->fromiCalendar($content, true);

try {
try {
$existing_id = $dav->getInternalObjectId($object, $internal)
?: preg_replace('/\.ics$/', '', $object);
} catch (Horde_Dav_Exception $e) {
$existing_id = $object;
}
$existing_event = $kronolith_driver->getEvent($existing_id);
/* Check if our event is newer then the existing - get the
* event's history. */
$existing_event->loadHistory();
$modified = $existing_event->modified
?: $existing_event->created;
try {
if (!empty($modified) &&
$content->getAttribute('LAST-MODIFIED') < $modified->timestamp()) {
/* LAST-MODIFIED timestamp of existing entry is newer:
* don't replace it. */
continue;
}
} catch (Horde_Icalendar_Exception $e) {
}

// Don't change creator/owner.
$event->creator = $existing_event->creator;
} catch (Horde_Exception_NotFound $e) {
$existing_event = null;
}

// Save entry.
$id = $event->save();

if (!$existing_event) {
$dav->addObjectMap($id, $object, $internal);
}

// Send iTip messages.
// Notifications will get lost, there is no way to return messages
// to clients.
Kronolith::sendITipNotifications(
$event,
new Horde_Notification_Handler(new Horde_Notification_Storage_Object()),
Kronolith::ITIP_REQUEST
);
}
$importer = new Kronolith_Icalendar_Handler_Dav(
$ical, Kronolith::getDriver(null, $internal), array('object' => $object)
);
$importer->process();
}

/**
Expand Down
14 changes: 0 additions & 14 deletions kronolith/lib/Event.php
Expand Up @@ -1417,20 +1417,6 @@ protected function _handlevEventRecurrence($vEvent)
$this->recurrence->fromRRule10($rrule);
}

/* Delete all existing exceptions to this event if it already
* exists */
if (!empty($this->uid)) {
$kronolith_driver = $this->getDriver();
$search = new StdClass();
$search->baseid = $this->uid;
$results = $kronolith_driver->search($search);
foreach ($results as $days) {
foreach ($days as $exception) {
$kronolith_driver->deleteEvent($exception->id);
}
}
}

// Exceptions. EXDATE represents deleted events, just add the
// exception, no new event is needed.
$exdates = $vEvent->getAttributeValues('EXDATE');
Expand Down
10 changes: 9 additions & 1 deletion kronolith/package.xml
Expand Up @@ -22,7 +22,7 @@
<email>chuck@horde.org</email>
<active>no</active>
</lead>
<date>2015-03-17</date>
<date>2015-03-18</date>
<version>
<release>4.2.6</release>
<api>4.2.0</api>
Expand Down Expand Up @@ -198,6 +198,12 @@
<file name="Mysql.php" role="horde" />
<file name="Sql.php" role="horde" />
</dir> <!-- /lib/Geo -->
<dir name="Icalendar">
<dir name="Handler">
<file name="Base.php" role="horde" />
<file name="Dav.php" role="horde" />
</dir> <!-- /lib/Icalendar/Handler -->
</dir> <!-- /lib/Icalendar -->
<dir name="LoginTasks">
<dir name="SystemTask">
<file name="Upgrade.php" role="horde" />
Expand Down Expand Up @@ -1204,6 +1210,8 @@
<install as="kronolith/lib/Geo/Base.php" name="lib/Geo/Base.php" />
<install as="kronolith/lib/Geo/Mysql.php" name="lib/Geo/Mysql.php" />
<install as="kronolith/lib/Geo/Sql.php" name="lib/Geo/Sql.php" />
<install as="kronolith/lib/Icalendar/Handler/Base.php" name="lib/Icalendar/Handler/Base.php" />
<install as="kronolith/lib/Icalendar/Handler/Dav.php" name="lib/Icalendar/Handler/Dav.php" />
<install as="kronolith/lib/LoginTasks/SystemTask/Upgrade.php" name="lib/LoginTasks/SystemTask/Upgrade.php" />
<install as="kronolith/lib/LoginTasks/Task/PurgeEvents.php" name="lib/LoginTasks/Task/PurgeEvents.php" />
<install as="kronolith/lib/Prefs/Special/DefaultAlarm.php" name="lib/Prefs/Special/DefaultAlarm.php" />
Expand Down

0 comments on commit 284d73a

Please sign in to comment.