From d28da62e34fcef1fab0e92a2890eb5ec837859c8 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Fri, 27 Apr 2012 16:33:26 +0800 Subject: [PATCH] MDL-31671 calendar: Fixing error when trying to delete parent of a repeated event series --- calendar/lib.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/calendar/lib.php b/calendar/lib.php index a6bc06977ed..adc83d8ea38 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -2087,6 +2087,14 @@ class calendar_event { // Delete the event $DB->delete_records('event', array('id'=>$this->properties->id)); + // If we are deleting parent of a repeated event series, promote the next event in the series as parent + if (($this->properties->id == $this->properties->repeatid) && !$deleterepeated) { + $newparent = $DB->get_field_sql("SELECT id from {event} where repeatid = ? order by id ASC", array($this->properties->id), IGNORE_MULTIPLE); + if (!empty($newparent)) { + $DB->execute("UPDATE {event} SET repeatid = ? WHERE repeatid = ?", array($newparent, $this->properties->id)); + } + } + // If the editor context hasn't already been set then set it now if ($this->editorcontext === null) { $this->editorcontext = $this->properties->context;