calendar/export MDL-17964 explicitly define a non-random UID for each event (merged...
[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;
80578821 16 //Add info->backup_version to $restore to be able to detect versions in the restore process
17 //(to decide when to convert wiki texts to markdown...)
18 $restore->backup_version = $info->backup_backup_version;
c9c89845 19
a2c7397c 20 //Check login
21 require_login();
22
93f66983 23 $loginurl = get_login_url();
24
a2c7397c 25 //Check admin
be2a6fc6 26 if (!empty($id)) {
0fd332a8 27 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
873bf875 28 if (empty($to)) {
93f66983 29 print_error("cannotuseadminadminorteacher", '', $loginurl);
873bf875 30 } else {
d4c550f5 31 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
32 && !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
93f66983 33 print_error("cannotuseadminadminorteacher", '', $loginurl);
873bf875 34 }
35 }
be2a6fc6 36 }
37 } else {
957f6fc9 38 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
93f66983 39 print_error("cannotuseadmin", '', $loginurl);
be2a6fc6 40 }
a2c7397c 41 }
42
43 //Check site
44 if (!$site = get_site()) {
d3b7ea93 45 print_error("siteisnotdefined", 'debug');
a2c7397c 46 }
f90666aa 47 $errorstr = '';
3f1c7233 48
f90666aa 49 $status = restore_execute($restore,$info,$course_header,$errorstr);
a2c7397c 50
51 if (!$status) {
d3b7ea93 52 print_error ("cannotrestore");
a2c7397c 53 }
54
410c459d 55 if (empty($restore->importing)) {
873bf875 56 //Print final message
1bbf415f 57 print_simple_box(get_string("restorefinished"),"center");
873bf875 58 } else {
1bbf415f 59 print_simple_box(get_string("importdatafinished"),"center");
b5037f72 60 $file = $CFG->dataroot . '/'
61 . $SESSION->import_preferences->backup_course
62 . '/backupdata/' . $SESSION->import_preferences->backup_name;
63 if (is_readable($file)) {
64 unlink($file);
65 }
66 else {
67 error_log("import course data: couldn't unlink $file");
68 }
873bf875 69 unset($SESSION->restore);
70 }
9c1ae5ae 71 print_continue("$CFG->wwwroot/course/view.php?id=".$restore->course_id);
11c1d525 72
a2c7397c 73?>