DL-22146 backup & restore - course formats remaining hooks
This commit is contained in:
@@ -29,5 +29,22 @@
|
||||
* TODO: Finish phpdocs
|
||||
*/
|
||||
abstract class backup_format_plugin extends backup_plugin {
|
||||
// Love these classes. :-) Nothing special to customize here for now
|
||||
|
||||
protected $courseformat; // To store the format (course->format) of the instance
|
||||
|
||||
public function __construct($plugintype, $pluginname, $optigroup, $step) {
|
||||
|
||||
parent::__construct($plugintype, $pluginname, $optigroup, $step);
|
||||
|
||||
$this->courseformat = backup_plan_dbops::get_courseformat_from_courseid($this->task->get_courseid());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the condition encapsulated into sqlparam format
|
||||
* to get evaluated by value, not by path nor processor setting
|
||||
*/
|
||||
protected function get_format_condition() {
|
||||
return array('sqlparam' => $this->courseformat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,6 +318,9 @@ class backup_module_structure_step extends backup_structure_step {
|
||||
$availability = new backup_nested_element('availability', array('id'), array(
|
||||
'sourcecmid', 'requiredcompletion', 'gradeitemid', 'grademin', 'grademax'));
|
||||
|
||||
// attach format plugin structure to $module element, only one allowed
|
||||
$this->add_plugin_structure('format', $module, false);
|
||||
|
||||
// Define the tree
|
||||
$module->add_child($availinfo);
|
||||
$availinfo->add_child($availability);
|
||||
@@ -354,6 +357,9 @@ class backup_section_structure_step extends backup_structure_step {
|
||||
$section = new backup_nested_element('section', array('id'), array(
|
||||
'number', 'name', 'summary', 'summaryformat', 'sequence', 'visible'));
|
||||
|
||||
// attach format plugin structure to $section element, only one allowed
|
||||
$this->add_plugin_structure('format', $section, false);
|
||||
|
||||
// Define sources
|
||||
|
||||
$section->set_source_table('course_sections', array('id' => backup::VAR_SECTIONID));
|
||||
|
||||
@@ -32,12 +32,14 @@ class restore_section_task extends restore_task {
|
||||
|
||||
protected $info; // info related to section gathered from backup file
|
||||
protected $contextid; // course context id
|
||||
protected $sectionid; // new (target) id of the course section
|
||||
|
||||
/**
|
||||
* Constructor - instantiates one object of this class
|
||||
*/
|
||||
public function __construct($name, $info, $plan = null) {
|
||||
$this->info = $info;
|
||||
$this->sectionid = 0;
|
||||
parent::__construct($name, $plan);
|
||||
}
|
||||
|
||||
@@ -49,10 +51,18 @@ class restore_section_task extends restore_task {
|
||||
return $this->get_basepath() . '/sections/section_' . $this->info->sectionid;
|
||||
}
|
||||
|
||||
public function set_sectionid($sectionid) {
|
||||
$this->sectionid = $sectionid;
|
||||
}
|
||||
|
||||
public function get_contextid() {
|
||||
return $this->contextid;
|
||||
}
|
||||
|
||||
public function get_sectionid() {
|
||||
return $this->sectionid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create all the steps that will be part of this task
|
||||
*/
|
||||
|
||||
@@ -920,7 +920,12 @@ class restore_process_categories_and_questions extends restore_execution_step {
|
||||
class restore_section_structure_step extends restore_structure_step {
|
||||
|
||||
protected function define_structure() {
|
||||
return array(new restore_path_element('section', '/section'));
|
||||
$section = new restore_path_element('section', '/section');
|
||||
|
||||
// Apply for 'format' plugins optional paths at section level
|
||||
$this->add_plugin_structure('format', $section);
|
||||
|
||||
return array($section);
|
||||
}
|
||||
|
||||
public function process_section($data) {
|
||||
@@ -962,6 +967,10 @@ class restore_section_structure_step extends restore_structure_step {
|
||||
// Annotate the section mapping, with restorefiles option if needed
|
||||
$this->set_mapping('course_section', $oldid, $newitemid, $restorefiles);
|
||||
|
||||
// set the new course_section id in the task
|
||||
$this->task->set_sectionid($newitemid);
|
||||
|
||||
|
||||
// Commented out. We never modify course->numsections as far as that is used
|
||||
// by a lot of people to "hide" sections on purpose (so this remains as used to be in Moodle 1.x)
|
||||
// Note: We keep the code here, to know about and because of the possibility of making this
|
||||
@@ -1985,11 +1994,15 @@ class restore_module_structure_step extends restore_structure_step {
|
||||
|
||||
$paths = array();
|
||||
|
||||
$paths[] = new restore_path_element('module', '/module');
|
||||
$module = new restore_path_element('module', '/module');
|
||||
$paths[] = $module;
|
||||
if ($CFG->enableavailability) {
|
||||
$paths[] = new restore_path_element('availability', '/module/availability_info/availability');
|
||||
}
|
||||
|
||||
// Apply for 'format' plugins optional paths at module level
|
||||
$this->add_plugin_structure('format', $module);
|
||||
|
||||
return $paths;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,6 +119,15 @@ abstract class backup_plan_dbops extends backup_dbops {
|
||||
return $sectionsarr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one course id, return its format in DB
|
||||
*/
|
||||
public static function get_courseformat_from_courseid($courseid) {
|
||||
global $DB;
|
||||
|
||||
return $DB->get_field('course', 'format', array('id' => $courseid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the wwwroot of the $CFG->mnet_localhost_id host
|
||||
* caching it along the request
|
||||
|
||||
Reference in New Issue
Block a user