MDL-24203 unused string removed
[moodle.git] / backup / restore_execute.html
CommitLineData
795b6945 1<?php
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;
cf59fbc0 11
12 // Validate objects from session by checking their checksums
13 $status = false;
14 if (isset($SESSION->restore_checksums)) {
15 $checksums = $SESSION->restore_checksums;
16 if (isset($checksums['info']) && $checksums['info'] == md5(serialize($info)) &&
17 isset($checksums['course_header']) && $checksums['course_header'] == md5(serialize($course_header)) &&
18 isset($checksums['restore']) && $checksums['restore'] == md5(serialize($restore))) {
19
20 $status = true; // All session checksums were or, we can rely on that to continue restoring
21 }
22 }
23 if(!$status) { // Something was wrong checking objects from session, abort with error
24 print_error('restorechecksumfailed');
25 }
a2c7397c 26 }
27
c9c89845 28 //Add info->original_wwwroot to $restore to be able to use it in all the restore process
29 //(mainly when decoding internal links)
30 $restore->original_wwwroot = $info->original_wwwroot;
d61f7b76 31 // Copy $info->original_siteidentifier, is present, so backup_is_same_site can work.
32 if (isset($info->original_siteidentifier)) {
33 $restore->original_siteidentifier = $info->original_siteidentifier;
34 }
80578821 35 //Add info->backup_version to $restore to be able to detect versions in the restore process
36 //(to decide when to convert wiki texts to markdown...)
37 $restore->backup_version = $info->backup_backup_version;
c9c89845 38
a2c7397c 39 //Check login
40 require_login();
41
93f66983 42 $loginurl = get_login_url();
43
a2c7397c 44 //Check admin
be2a6fc6 45 if (!empty($id)) {
d2940003 46 if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $id))) {
873bf875 47 if (empty($to)) {
93f66983 48 print_error("cannotuseadminadminorteacher", '', $loginurl);
873bf875 49 } else {
d2940003 50 if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $to))
157aa3a2 51 && !has_capability('moodle/restore:restoretargetimport', get_context_instance(CONTEXT_COURSE, $to))) {
93f66983 52 print_error("cannotuseadminadminorteacher", '', $loginurl);
873bf875 53 }
54 }
be2a6fc6 55 }
56 } else {
d2940003 57 if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_SYSTEM))) {
93f66983 58 print_error("cannotuseadmin", '', $loginurl);
be2a6fc6 59 }
a2c7397c 60 }
61
62 //Check site
3f77c158 63 $site = get_site();
f90666aa 64 $errorstr = '';
3f1c7233 65
f90666aa 66 $status = restore_execute($restore,$info,$course_header,$errorstr);
a2c7397c 67
68 if (!$status) {
d3b7ea93 69 print_error ("cannotrestore");
a2c7397c 70 }
71
410c459d 72 if (empty($restore->importing)) {
873bf875 73 //Print final message
9549b986 74 echo $OUTPUT->box(get_string("restorefinished"));
873bf875 75 } else {
9549b986 76 echo $OUTPUT->box(get_string("importdatafinished"));
795b6945
PS
77 $file = $CFG->dataroot . '/'
78 . $SESSION->import_preferences->backup_course
b5037f72 79 . '/backupdata/' . $SESSION->import_preferences->backup_name;
80 if (is_readable($file)) {
81 unlink($file);
82 }
83 else {
84 error_log("import course data: couldn't unlink $file");
85 }
873bf875 86 unset($SESSION->restore);
87 }
9549b986 88 echo $OUTPUT->continue_button("$CFG->wwwroot/course/view.php?id=".$restore->course_id);