From ff284fac9e7d3c2ad1611b2d58e8a6f34506d1ed 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 7280f14c7a8..2094f3a14ed 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -2275,6 +2275,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;