MDL-19039 improved default frontpage role capability evealuation, needs to be manuall...
[moodle.git] / backup / restore_execute.html
CommitLineData
7ef0797d 1<?php //$Id$
a2c7397c 2 //This page receives the required info and executes the restore
3 //with the parameters suplied. Whe finished, delete temporary
4 //data from backup_tables and temp directory
5
6 //Get objects from session
7 if ($SESSION) {
8 $info = $SESSION->info;
9 $course_header = $SESSION->course_header;
10 $restore = $SESSION->restore;
11 }
12
c9c89845 13 //Add info->original_wwwroot to $restore to be able to use it in all the restore process
14 //(mainly when decoding internal links)
15 $restore->original_wwwroot = $info->original_wwwroot;
d61f7b76 16 // Copy $info->original_siteidentifier, is present, so backup_is_same_site can work.
17 if (isset($info->original_siteidentifier)) {
18 $restore->original_siteidentifier = $info->original_siteidentifier;
19 }
80578821 20 //Add info->backup_version to $restore to be able to detect versions in the restore process
21 //(to decide when to convert wiki texts to markdown...)
22 $restore->backup_version = $info->backup_backup_version;
c9c89845 23
a2c7397c 24 //Check login
25 require_login();
26
93f66983 27 $loginurl = get_login_url();
28
a2c7397c 29 //Check admin
be2a6fc6 30 if (!empty($id)) {
0fd332a8 31 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
873bf875 32 if (empty($to)) {
93f66983 33 print_error("cannotuseadminadminorteacher", '', $loginurl);
873bf875 34 } else {
d4c550f5 35 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
36 && !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
93f66983 37 print_error("cannotuseadminadminorteacher", '', $loginurl);
873bf875 38 }
39 }
be2a6fc6 40 }
41 } else {
957f6fc9 42 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
93f66983 43 print_error("cannotuseadmin", '', $loginurl);
be2a6fc6 44 }
a2c7397c 45 }
46
47 //Check site
48 if (!$site = get_site()) {
d3b7ea93 49 print_error("siteisnotdefined", 'debug');
a2c7397c 50 }
f90666aa 51 $errorstr = '';
3f1c7233 52
f90666aa 53 $status = restore_execute($restore,$info,$course_header,$errorstr);
a2c7397c 54
55 if (!$status) {
d3b7ea93 56 print_error ("cannotrestore");
a2c7397c 57 }
58
410c459d 59 if (empty($restore->importing)) {
873bf875 60 //Print final message
9549b986 61 echo $OUTPUT->box(get_string("restorefinished"));
873bf875 62 } else {
9549b986 63 echo $OUTPUT->box(get_string("importdatafinished"));
b5037f72 64 $file = $CFG->dataroot . '/'
65 . $SESSION->import_preferences->backup_course
66 . '/backupdata/' . $SESSION->import_preferences->backup_name;
67 if (is_readable($file)) {
68 unlink($file);
69 }
70 else {
71 error_log("import course data: couldn't unlink $file");
72 }
873bf875 73 unset($SESSION->restore);
74 }
9549b986 75 echo $OUTPUT->continue_button("$CFG->wwwroot/course/view.php?id=".$restore->course_id);
11c1d525 76
a2c7397c 77?>