Permalink
Browse files

MDL-31671 calendar: Fixing error when trying to delete parent of a re…

…peated event series
  • Loading branch information...
1 parent 8075bd8 commit d28da62e34fcef1fab0e92a2890eb5ec837859c8 @ankitagarwal ankitagarwal committed Apr 27, 2012
Showing with 8 additions and 0 deletions.
  1. +8 −0 calendar/lib.php
View
@@ -2087,6 +2087,14 @@ public function delete($deleterepeated=false) {
// 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;

0 comments on commit d28da62

Please sign in to comment.