From 3a1cccc6d4f81a26258eaba7db2ea7f79c424197 Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Sun, 18 Jul 2010 17:52:33 +0000 Subject: [PATCH] MDL-21432 backup - allow arbitrary contexts when annotating files. Record orignal sysctxid --- backup/moodle2/backup_stepslib.php | 6 +++++- backup/util/helper/backup_general_helper.class.php | 1 + backup/util/structure/backup_nested_element.class.php | 8 +++++--- .../util/structure/backup_structure_processor.class.php | 8 ++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 9179390612c..708104e5704 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -502,6 +502,9 @@ class backup_final_scales_structure_step extends backup_structure_step { WHERE bi.backupid = ? AND bi.itemname = 'scalefinal'", array(backup::VAR_BACKUPID)); + // Annotate scale files (they store files in system context, so pass it instead of default one) + $scale->annotate_files('grade', 'scale', 'id', get_context_instance(CONTEXT_SYSTEM)->id); + // Return main element (scalesdef) return $scalesdef; } @@ -1195,6 +1198,7 @@ class backup_main_structure_step extends backup_structure_step { $info['original_site_identifier_hash'] = md5(get_site_identifier()); $info['original_course_id'] = $this->get_courseid(); $info['original_course_contextid'] = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id; + $info['original_system_contextid'] = get_context_instance(CONTEXT_SYSTEM)->id; // Get more information from controller list($dinfo, $cinfo, $sinfo) = backup_controller_dbops::get_moodle_backup_information($this->get_backupid()); @@ -1206,7 +1210,7 @@ class backup_main_structure_step extends backup_structure_step { $information = new backup_nested_element('information', null, array( 'name', 'moodle_version', 'moodle_release', 'backup_version', 'backup_release', 'backup_date', 'original_wwwroot', - 'original_site_identifier_hash', 'original_course_id', 'original_course_contextid')); + 'original_site_identifier_hash', 'original_course_id', 'original_course_contextid', 'original_system_contextid')); $details = new backup_nested_element('details'); diff --git a/backup/util/helper/backup_general_helper.class.php b/backup/util/helper/backup_general_helper.class.php index 969fde04b19..d5eff64efeb 100644 --- a/backup/util/helper/backup_general_helper.class.php +++ b/backup/util/helper/backup_general_helper.class.php @@ -140,6 +140,7 @@ abstract class backup_general_helper extends backup_helper { $info->original_site_identifier_hash = $infoarr['original_site_identifier_hash']; $info->original_course_id = $infoarr['original_course_id']; $info->original_course_contextid= $infoarr['original_course_contextid']; + $info->original_system_contextid= $infoarr['original_system_contextid']; $info->type = $infoarr['details']['detail'][0]['type']; $info->format = $infoarr['details']['detail'][0]['format']; $info->mode = $infoarr['details']['detail'][0]['mode']; diff --git a/backup/util/structure/backup_nested_element.class.php b/backup/util/structure/backup_nested_element.class.php index b69b21d4728..09f55294bd2 100644 --- a/backup/util/structure/backup_nested_element.class.php +++ b/backup/util/structure/backup_nested_element.class.php @@ -146,8 +146,7 @@ class backup_nested_element extends base_nested_element implements processable { } } - public function annotate_files($component, $filearea, $elementname) { - // note: it is possible to annotate areas ONLY in current context, ie modules may backup only from module context + public function annotate_files($component, $filearea, $elementname, $filesctxid = null) { if (!array_key_exists($component, $this->fileannotations)) { $this->fileannotations[$component] = array(); } @@ -160,7 +159,10 @@ class backup_nested_element extends base_nested_element implements processable { throw new base_element_struct_exception('annotate_files_duplicate_annotation', "$component/$filearea/$elementname"); } - $this->fileannotations[$component][$filearea] = $elementname; + $info = new stdclass(); + $info->element = $elementname; + $info->contextid = $filesctxid; + $this->fileannotations[$component][$filearea] = $info; } public function annotate_ids($itemname, $elementname) { diff --git a/backup/util/structure/backup_structure_processor.class.php b/backup/util/structure/backup_structure_processor.class.php index 6d3e2f6be47..3c648545dd9 100644 --- a/backup/util/structure/backup_structure_processor.class.php +++ b/backup/util/structure/backup_structure_processor.class.php @@ -70,10 +70,10 @@ class backup_structure_processor extends base_processor { $fileannotations = $nested->get_file_annotations(); if ($fileannotations) { // If there are areas to search $backupid = $this->get_var(backup::VAR_BACKUPID); - $contextid = $this->get_var(backup::VAR_CONTEXTID); - foreach ($fileannotations as $component=>$area) { - foreach ($area as $filearea=>$element) { - $itemid = !is_null($element) ? $element->get_value() : null; + foreach ($fileannotations as $component => $area) { + foreach ($area as $filearea => $info) { + $contextid = !is_null($info->contextid) ? $info->contextid : $this->get_var(backup::VAR_CONTEXTID); + $itemid = !is_null($info->element) ? $info->element->get_value() : null; backup_structure_dbops::annotate_files($backupid, $contextid, $component, $filearea, $itemid); } }