mirror of
https://github.com/moodle/moodle.git
synced 2025-04-28 03:44:24 +02:00
MDL-21432 backup - allow arbitrary contexts when annotating files. Record orignal sysctxid
This commit is contained in:
parent
c1834c3c34
commit
3a1cccc6d4
@ -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');
|
||||
|
||||
|
@ -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'];
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user