From 19fa690c3fe123444e7b95e4d309d3f656e02dcd Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Tue, 24 Oct 2017 16:21:18 +0800 Subject: [PATCH] MDL-60429 calendar: fix for updating event course and group The property courseid and groupid might not be set, so if updating, use the existing value if a new value wasn't specified. --- calendar/lib.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index 8d7c1af66e8..d858b9f28e9 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -599,9 +599,17 @@ class calendar_event { groupid = ?, courseid = ? WHERE repeatid = ?"; - $params = array($this->properties->name, $this->properties->description, $timestartoffset, - $this->properties->timeduration, time(), $this->properties->groupid, - $this->properties->courseid, $event->repeatid); + // Note: Group and course id may not be set. If not, keep their current values. + $params = [ + $this->properties->name, + $this->properties->description, + $timestartoffset, + $this->properties->timeduration, + time(), + isset($this->properties->groupid) ? $this->properties->groupid : $event->groupid, + isset($this->properties->courseid) ? $this->properties->courseid : $event->courseid, + $event->repeatid + ]; } else { $sql = "UPDATE {event} SET name = ?, @@ -611,9 +619,16 @@ class calendar_event { groupid = ?, courseid = ? WHERE repeatid = ?"; - $params = array($this->properties->name, $this->properties->description, - $this->properties->timeduration, time(), $this->properties->groupid, - $this->properties->courseid, $event->repeatid); + // Note: Group and course id may not be set. If not, keep their current values. + $params = [ + $this->properties->name, + $this->properties->description, + $this->properties->timeduration, + time(), + isset($this->properties->groupid) ? $this->properties->groupid : $event->groupid, + isset($this->properties->courseid) ? $this->properties->courseid : $event->courseid, + $event->repeatid + ]; } $DB->execute($sql, $params);