From a90659d6baef4a3475604a379a7f49005ff22020 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Fri, 11 Feb 2011 00:07:32 +0100 Subject: [PATCH] DL-22146 backup & restore - course formats remaining hooks --- backup/moodle2/backup_format_plugin.class.php | 19 ++++++++++++++++++- backup/moodle2/backup_stepslib.php | 6 ++++++ backup/moodle2/restore_section_task.class.php | 10 ++++++++++ backup/moodle2/restore_stepslib.php | 17 +++++++++++++++-- backup/util/dbops/backup_plan_dbops.class.php | 9 +++++++++ 5 files changed, 58 insertions(+), 3 deletions(-) diff --git a/backup/moodle2/backup_format_plugin.class.php b/backup/moodle2/backup_format_plugin.class.php index 933b660f5af..d1af1b923f4 100644 --- a/backup/moodle2/backup_format_plugin.class.php +++ b/backup/moodle2/backup_format_plugin.class.php @@ -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); + } } diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 645d22c6977..6b4dbf34355 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -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)); diff --git a/backup/moodle2/restore_section_task.class.php b/backup/moodle2/restore_section_task.class.php index 75bf7c3ef3d..5c03bcb7b85 100644 --- a/backup/moodle2/restore_section_task.class.php +++ b/backup/moodle2/restore_section_task.class.php @@ -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 */ diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 7b5d82c6bbe..cab0de16a55 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -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; } diff --git a/backup/util/dbops/backup_plan_dbops.class.php b/backup/util/dbops/backup_plan_dbops.class.php index 99592362bb6..a6f60fff3c7 100644 --- a/backup/util/dbops/backup_plan_dbops.class.php +++ b/backup/util/dbops/backup_plan_dbops.class.php @@ -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