Skip to content

Commit

Permalink
We still need to process the recurrence rules here.
Browse files Browse the repository at this point in the history
We only need to skip the exception handling for EAS 16. We still may
have a recurrence rule to handle.
  • Loading branch information
mrubinsk committed Jan 21, 2016
1 parent 1aab772 commit acda4d2
Showing 1 changed file with 45 additions and 41 deletions.
86 changes: 45 additions & 41 deletions kronolith/lib/Event.php
Expand Up @@ -1668,15 +1668,19 @@ public function fromASAppointment(Horde_ActiveSync_Message_Appointment $message)
}

/* Recurrence */
if ($message->getProtocolVersion() < Horde_ActiveSync::VERSION_SIXTEEN &&
$rrule = $message->getRecurrence()) {
if ($rrule = $message->getRecurrence()) {
/* Exceptions */
/* Since AS keeps exceptions as part of the original event, we need
* to delete all existing exceptions and re-create them. The only
* drawback to this is that the UIDs will change. */
$kronolith_driver = $this->getDriver();
$this->recurrence = $rrule;
if (!empty($this->uid)) {

if (!empty($this->uid) &&
$message->getProtocolVersion() < Horde_ActiveSync::VERSION_SIXTEEN) {
// EAS 16.0 NEVER adds exceptions from withing the base event,
// so we can't delete the existing exceptions - we don't have
// the current list to replace them with.
$search = new StdClass();
$search->baseid = $this->uid;
$results = $kronolith_driver->search($search);
Expand All @@ -1685,46 +1689,46 @@ public function fromASAppointment(Horde_ActiveSync_Message_Appointment $message)
$kronolith_driver->deleteEvent($exception->id);
}
}
}

$erules = $message->getExceptions();
foreach ($erules as $rule){
/* Readd the exception event, but only if not deleted */
if (!$rule->deleted) {
$event = $kronolith_driver->getEvent();
$times = $rule->getDatetime();
if ($message->getProtocolVersion() < Horde_ActiveSync::VERSION_SIXTEEN) {
$original = $rule->getExceptionStartTime();
} else {
$original = $rule->instanceid;
}
$original->setTimezone($tz);
$this->recurrence->addException($original->format('Y'), $original->format('m'), $original->format('d'));
$event->start = $times['start'];
$event->end = $times['end'];
$event->start->setTimezone($tz);
$event->end->setTimezone($tz);
$event->allday = $times['allday'];
$event->title = $rule->getSubject();
$event->title = empty($event->title) ? $this->title : $event->title;
$event->description = $rule->getBody();
$event->description = empty($event->description) ? $this->description : $event->description;
$event->baseid = $this->uid;
$event->exceptionoriginaldate = $original;
$event->initialized = true;
if ($tz != date_default_timezone_get()) {
$event->timezone = $tz;
}
$event->save();
} else {
/* For exceptions that are deletions, just add the exception */
if ($message->getProtocolVersion() < Horde_ActiveSync::VERSION_SIXTEEN) {
$exceptiondt = $rule->getExceptionStartTime();
$erules = $message->getExceptions();
foreach ($erules as $rule){
/* Readd the exception event, but only if not deleted */
if (!$rule->deleted) {
$event = $kronolith_driver->getEvent();
$times = $rule->getDatetime();
if ($message->getProtocolVersion() < Horde_ActiveSync::VERSION_SIXTEEN) {
$original = $rule->getExceptionStartTime();
} else {
$original = $rule->instanceid;
}
$original->setTimezone($tz);
$this->recurrence->addException($original->format('Y'), $original->format('m'), $original->format('d'));
$event->start = $times['start'];
$event->end = $times['end'];
$event->start->setTimezone($tz);
$event->end->setTimezone($tz);
$event->allday = $times['allday'];
$event->title = $rule->getSubject();
$event->title = empty($event->title) ? $this->title : $event->title;
$event->description = $rule->getBody();
$event->description = empty($event->description) ? $this->description : $event->description;
$event->baseid = $this->uid;
$event->exceptionoriginaldate = $original;
$event->initialized = true;
if ($tz != date_default_timezone_get()) {
$event->timezone = $tz;
}
$event->save();
} else {
$exceptiondt = $rule->instanceid;
}
$exceptiondt->setTimezone($tz);
$this->recurrence->addException($exceptiondt->format('Y'), $exceptiondt->format('m'), $exceptiondt->format('d'));
/* For exceptions that are deletions, just add the exception */
if ($message->getProtocolVersion() < Horde_ActiveSync::VERSION_SIXTEEN) {
$exceptiondt = $rule->getExceptionStartTime();
} else {
$exceptiondt = $rule->instanceid;
}
$exceptiondt->setTimezone($tz);
$this->recurrence->addException($exceptiondt->format('Y'), $exceptiondt->format('m'), $exceptiondt->format('d'));
}
}
}
}
Expand Down

0 comments on commit acda4d2

Please sign in to comment.