diff --git a/course/edit.php b/course/edit.php index c549cc13929..ebe4ab9948c 100644 --- a/course/edit.php +++ b/course/edit.php @@ -45,8 +45,11 @@ if ($id) { // editing course print_error('cannoteditsiteform'); } - $course = course_get_format($id)->get_course(); + // Login to the course and retrieve also all fields defined by course format. + $course = get_course($id); require_login($course); + $course = course_get_format($course)->get_course(); + $category = $DB->get_record('course_categories', array('id'=>$course->category), '*', MUST_EXIST); $coursecontext = context_course::instance($course->id); require_capability('moodle/course:update', $coursecontext); diff --git a/course/format/lib.php b/course/format/lib.php index 76e764931d4..acccb97603b 100644 --- a/course/format/lib.php +++ b/course/format/lib.php @@ -237,14 +237,21 @@ abstract class format_base { if ($this->course === false) { $this->course = get_course($this->courseid); $options = $this->get_format_options(); + $dbcoursecolumns = null; foreach ($options as $optionname => $optionvalue) { - if (!isset($this->course->$optionname)) { - $this->course->$optionname = $optionvalue; - } else { - debugging('The option name '.$optionname.' in course format '.$this->format. - ' is invalid because the field with the same name exists in {course} table', - DEBUG_DEVELOPER); + if (isset($this->course->$optionname)) { + // Course format options must not have the same names as existing columns in db table "course". + if (!isset($dbcoursecolumns)) { + $dbcoursecolumns = $DB->get_columns('course'); + } + if (isset($dbcoursecolumns[$optionname])) { + debugging('The option name '.$optionname.' in course format '.$this->format. + ' is invalid because the field with the same name exists in {course} table', + DEBUG_DEVELOPER); + continue; + } } + $this->course->$optionname = $optionvalue; } } return $this->course;