diff --git a/backup/backupfilesedit.php b/backup/backupfilesedit.php index dc27fde35ac..41d0320f14f 100755 --- a/backup/backupfilesedit.php +++ b/backup/backupfilesedit.php @@ -40,7 +40,7 @@ $filecontext = get_context_instance_by_id($contextid); $url = new moodle_url('/backup/backupfilesedit.php', array('currentcontext'=>$currentcontext, 'contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea)); -require_login($course); +require_login($course, false, $cm); require_capability('moodle/restore:uploadfile', $context); $PAGE->set_url($url); diff --git a/backup/restorefile.php b/backup/restorefile.php index 00268ed1238..1ccd6cd4a10 100755 --- a/backup/restorefile.php +++ b/backup/restorefile.php @@ -58,7 +58,7 @@ switch ($context->contextlevel) { } -require_login($course); +require_login($course, false, $cm); require_capability('moodle/restore:restorecourse', $context); $browser = get_file_browser(); @@ -112,6 +112,21 @@ if (has_capability('moodle/restore:uploadfile', $context)) { echo $OUTPUT->container_end(); } +if ($context->contextlevel == CONTEXT_MODULE) { + echo $OUTPUT->heading_with_help(get_string('choosefilefromactivitybackup', 'backup'), 'choosefilefromuserbackup', 'backup'); + echo $OUTPUT->container_start(); + $treeview_options = array(); + $user_context = get_context_instance(CONTEXT_USER, $USER->id); + $treeview_options['filecontext'] = $context; + $treeview_options['currentcontext'] = $context; + $treeview_options['component'] = 'backup'; + $treeview_options['context'] = $context; + $treeview_options['filearea'] = 'activity'; + $renderer = $PAGE->get_renderer('core', 'backup'); + echo $renderer->backup_files_viewer($treeview_options); + echo $OUTPUT->container_end(); +} + echo $OUTPUT->heading_with_help(get_string('choosefilefromcoursebackup', 'backup'), 'choosefilefromcoursebackup', 'backup'); echo $OUTPUT->container_start(); $treeview_options = array(); @@ -124,7 +139,6 @@ $renderer = $PAGE->get_renderer('core', 'backup'); echo $renderer->backup_files_viewer($treeview_options); echo $OUTPUT->container_end(); - echo $OUTPUT->heading_with_help(get_string('choosefilefromuserbackup', 'backup'), 'choosefilefromuserbackup', 'backup'); echo $OUTPUT->container_start(); $treeview_options = array(); diff --git a/backup/util/ui/backup_ui_stage.class.php b/backup/util/ui/backup_ui_stage.class.php index bffeb7184c4..a5bb1a7769b 100644 --- a/backup/util/ui/backup_ui_stage.class.php +++ b/backup/util/ui/backup_ui_stage.class.php @@ -453,8 +453,20 @@ class backup_ui_stage_complete extends backup_ui_stage_final { global $OUTPUT; // Get the resulting stored_file record - $coursecontext = get_context_instance(CONTEXT_COURSE, $this->get_ui()->get_controller()->get_courseid()); - $restorerul = new moodle_url('/backup/restorefile.php', array('contextid'=>$coursecontext->id)); + $type = $this->get_ui()->get_controller()->get_type(); + $courseid = $this->get_ui()->get_controller()->get_courseid(); + switch ($type) { + case 'activity': + $cmid = $this->get_ui()->get_controller()->get_id(); + $cm = get_coursemodule_from_id(null, $cmid, $courseid); + $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); + $restorerul = new moodle_url('/backup/restorefile.php', array('contextid'=>$modcontext->id)); + break; + case 'course': + default: + $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid); + $restorerul = new moodle_url('/backup/restorefile.php', array('contextid'=>$coursecontext->id)); + } echo $OUTPUT->box_start(); echo $OUTPUT->notification(get_string('executionsuccess', 'backup'), 'notifysuccess'); diff --git a/lang/en/backup.php b/lang/en/backup.php index b22cccd60f4..14115e1bf9d 100644 --- a/lang/en/backup.php +++ b/lang/en/backup.php @@ -48,10 +48,12 @@ $string['backuptypeactivity'] = 'Activity'; $string['backuptypecourse'] = 'Course'; $string['backupversion'] = 'Backup version'; $string['cannotfindassignablerole'] = 'The {$a} role in the backup file cannot be mapped to any of the roles that you are allowed to assign.'; -$string['choosefilefromcoursebackup'] = 'Choose an existing backup file from course backup area'; +$string['choosefilefromcoursebackup'] = 'Course backup area'; $string['choosefilefromcoursebackup_help'] = 'When backup courses using default settings, backup files will be stored here'; -$string['choosefilefromuserbackup'] = 'Choose an existing backup file from private backup area'; +$string['choosefilefromuserbackup'] = 'User private backup area'; $string['choosefilefromuserbackup_help'] = 'When backup courses with "Anonymize user information" option ticked, backup files will be stored here'; +$string['choosefilefromactivitybackup'] = 'Activity backup area'; +$string['choosefilefromactivitybackup_help'] = 'When backup activities using default settings, backup files will be stored here'; $string['configgeneralactivities'] = 'Sets the default for including activities in a backup.'; $string['configgeneralanonymize'] = 'If enabled all information pertaining to users will be anonymised by default.'; $string['configgeneralblocks'] = 'Sets the default for including blocks in a backup.'; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 116481be4e3..7f1737af9fa 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -3146,6 +3146,13 @@ class settings_navigation extends navigation_node { $modulenode->add(get_string('backup'), $url, self::TYPE_SETTING); } + // Restore this activity + $featuresfunc = $this->page->activityname.'_supports'; + if (function_exists($featuresfunc) && $featuresfunc(FEATURE_BACKUP_MOODLE2) && has_capability('moodle/restore:restoreactivity', $this->page->cm->context)) { + $url = new moodle_url('/backup/restorefile.php', array('contextid'=>$this->page->cm->context->id)); + $modulenode->add(get_string('restore'), $url, self::TYPE_SETTING); + } + $function = $this->page->activityname.'_extend_settings_navigation'; if (!function_exists($function)) { return $modulenode;