Permalink
Browse files

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

…peated event series
  • Loading branch information...
1 parent 6791b08 commit 9f786f74083316e4db372a68c7ec738d5dbf96d9 @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 9f786f7

Please sign in to comment.