MDL-35339 Deprecate add_mod_to_section(), create new function course_add_cm_to_section()
Function add_mod_to_section() has very confusing arguments when object looks like record from table course_modules but field ->section refers to relative section number (course_sections.section). In table course_modules the field section refers to course_sections.id. Also add_mod_to_section() does not update table course_modules and does not call rebuild_course_cache() which developer can forget to do afterwards. - Added function course_add_cm_to_section() - In the core code add_mod_to_section() is replaced with course_add_cm_to_section() - Function add_mod_to_section() is deprecated
This commit is contained in:
@@ -82,12 +82,13 @@ abstract class phpunit_module_generator {
|
||||
require_once("$CFG->dirroot/course/lib.php");
|
||||
|
||||
$modulename = $this->get_modulename();
|
||||
$sectionnum = isset($options['section']) ? $options['section'] : 0;
|
||||
|
||||
$cm = new stdClass();
|
||||
$cm->course = $courseid;
|
||||
$cm->module = $DB->get_field('modules', 'id', array('name'=>$modulename));
|
||||
$cm->instance = 0;
|
||||
$cm->section = isset($options['section']) ? $options['section'] : 0;
|
||||
$cm->section = 0;
|
||||
$cm->idnumber = isset($options['idnumber']) ? $options['idnumber'] : 0;
|
||||
$cm->added = time();
|
||||
|
||||
@@ -103,9 +104,8 @@ abstract class phpunit_module_generator {
|
||||
}
|
||||
|
||||
$cm->id = $DB->insert_record('course_modules', $cm);
|
||||
$cm->coursemodule = $cm->id;
|
||||
|
||||
add_mod_to_section($cm);
|
||||
course_add_cm_to_section($courseid, $cm->id, $sectionnum);
|
||||
|
||||
return $cm->id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user