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.
  • Loading branch information
mrubinsk committed Mar 18, 2015
1 parent e6e7c20 commit dbc46bc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 72 deletions.
60 changes: 4 additions & 56 deletions kronolith/lib/Application.php
Expand Up @@ -821,62 +821,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 @@ -1424,20 +1424,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
14 changes: 12 additions & 2 deletions kronolith/package.xml
Expand Up @@ -22,7 +22,7 @@
<email>chuck@horde.org</email>
<active>no</active>
</lead>
<date>2014-06-04</date>
<date>2015-03-18</date>
<version>
<release>4.3.0</release>
<api>4.2.0</api>
Expand Down Expand Up @@ -200,6 +200,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 @@ -504,6 +510,7 @@
<file name="20_kronolith_upgrade_timezone.php" role="horde" />
<file name="21_kronolith_upgrade_exceptionutc.php" role="horde" />
<file name="22_kronolith_upgrade_parents.php" role="horde" />
<file name="23_kronolith_upgrade_baseidindex.php" role="horde" />
</dir> <!-- /migration -->
<dir name="resources">
<dir name="groups">
Expand Down Expand Up @@ -1205,6 +1212,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 Expand Up @@ -1331,6 +1340,7 @@
<install as="kronolith/migration/20_kronolith_upgrade_timezone.php" name="migration/20_kronolith_upgrade_timezone.php" />
<install as="kronolith/migration/21_kronolith_upgrade_exceptionutc.php" name="migration/21_kronolith_upgrade_exceptionutc.php" />
<install as="kronolith/migration/22_kronolith_upgrade_parents.php" name="migration/22_kronolith_upgrade_parents.php" />
<install as="kronolith/migration/23_kronolith_upgrade_baseidindex.php" name="migration/23_kronolith_upgrade_baseidindex.php" />
<install as="kronolith/resources/create.php" name="resources/create.php" />
<install as="kronolith/resources/delete.php" name="resources/delete.php" />
<install as="kronolith/resources/edit.php" name="resources/edit.php" />
Expand Down Expand Up @@ -2525,7 +2535,7 @@
<stability>
<release>beta</release>
<api>beta</api></stability>
<date>2014-06-04</date>
<date>2015-03-18</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [mjr] Enforce case on attendee user part, but add attendee to event if only only the case differs (Bug #13905).
Expand Down

0 comments on commit dbc46bc

Please sign in to comment.