Skip to content

Commit

Permalink
Honor RECURRECNCE-ID RANGE when deleting events.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Nov 21, 2013
1 parent 94fd90f commit 00561eb
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions kronolith/lib/Api.php
Expand Up @@ -917,10 +917,14 @@ public function exportCalendar($calendar, $contentType)
* @param string $recurrenceId The reccurenceId for the event instance, if
* this is a deletion of a recurring event
* instance ($uid must not be an array).
* @param string $range The range value if deleting a recurring
* event instance. Only supported values are
* null or Kronolith::RANGE_THISANDFUTURE.
* @since 4.1.5
*
* @throws Kronolith_Exception
*/
public function delete($uid, $recurrenceId = null)
public function delete($uid, $recurrenceId = null, $range = null)
{
// Handle an array of UIDs for convenience of deleting multiple events
// at once.
Expand All @@ -933,8 +937,8 @@ public function delete($uid, $recurrenceId = null)

$kronolith_driver = Kronolith::getDriver();
$events = $kronolith_driver->getByUID($uid, null, true);

$event = null;

if ($GLOBALS['registry']->isAdmin()) {
$event = $events[0];
}
Expand Down Expand Up @@ -967,10 +971,21 @@ public function delete($uid, $recurrenceId = null)
throw new Horde_Exception_PermissionDenied();
}

if ($recurrenceId && $event->recurs()) {
if ($recurrenceId && $event->recurs() && empty($range)) {
$deleteDate = new Horde_Date($recurrenceId);
$event->recurrence->addException($deleteDate->format('Y'), $deleteDate->format('m'), $deleteDate->format('d'));
$event->save();
} elseif ($range == Kronolith::RANGE_THISANDFUTURE) {
// Deleting the instance and remaining series.
$instance = new Horde_Date($recurrenceId);
$recurEnd = clone($instance);
$recurEnd->mday--;
if ($event->end->compareDate($recurEnd) > 0) {
$kronolith_driver->deleteEvent($event->id);
} else {
$event->recurrence->setRecurEnd($recurEnd);
$result = $event->save();
}
} elseif ($recurrenceId) {
throw new Kronolith_Exception(_("Unable to delete event. An exception date was provided but the event does not seem to be recurring."));
} else {
Expand Down

0 comments on commit 00561eb

Please sign in to comment.