Skip to content

Commit

Permalink
MDL-41384 course: do not show debugging message if $COURSE contains f…
Browse files Browse the repository at this point in the history
…ormat options

before showing debugging message make sure that field exists in database and not only in the object
  • Loading branch information
marinaglancy committed Jan 31, 2014
1 parent e204978 commit 7456c96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion course/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@
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);
Expand Down
19 changes: 13 additions & 6 deletions course/format/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,21 @@ public function get_course() {
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;
Expand Down

0 comments on commit 7456c96

Please sign in to comment.