MDL-41384 course: do not show debugging message if $COURSE contains format options

before showing debugging message make sure that field exists in database and not only in the object
This commit is contained in:
Marina Glancy 2014-01-10 15:37:46 +08:00
parent e262d58d6c
commit 1c4b2c0b8d
2 changed files with 17 additions and 7 deletions

View file

@ -45,8 +45,11 @@ if ($id) {
print_error('cannoteditsiteform'); 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); require_login($course);
$course = course_get_format($course)->get_course();
$category = $DB->get_record('course_categories', array('id'=>$course->category), '*', MUST_EXIST); $category = $DB->get_record('course_categories', array('id'=>$course->category), '*', MUST_EXIST);
$coursecontext = context_course::instance($course->id); $coursecontext = context_course::instance($course->id);
require_capability('moodle/course:update', $coursecontext); require_capability('moodle/course:update', $coursecontext);

View file

@ -237,14 +237,21 @@ abstract class format_base {
if ($this->course === false) { if ($this->course === false) {
$this->course = get_course($this->courseid); $this->course = get_course($this->courseid);
$options = $this->get_format_options(); $options = $this->get_format_options();
$dbcoursecolumns = null;
foreach ($options as $optionname => $optionvalue) { foreach ($options as $optionname => $optionvalue) {
if (!isset($this->course->$optionname)) { if (isset($this->course->$optionname)) {
$this->course->$optionname = $optionvalue; // Course format options must not have the same names as existing columns in db table "course".
} else { if (!isset($dbcoursecolumns)) {
debugging('The option name '.$optionname.' in course format '.$this->format. $dbcoursecolumns = $DB->get_columns('course');
' is invalid because the field with the same name exists in {course} table', }
DEBUG_DEVELOPER); 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; return $this->course;