MDL-7647 confirmation email - usernames with slashes causing confirmation problems
[moodle.git] / backup / restore_execute.html
blob5ce7258e953c5e3f8a38fa63707cd5d3626e052f
1 <?php //$Id$
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
6 //Get objects from session
7 if ($SESSION) {
8 $info = $SESSION->info;
9 $course_header = $SESSION->course_header;
10 $restore = $SESSION->restore;
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))) {
20 $status = true; // All session checksums were or, we can rely on that to continue restoring
23 if(!$status) { // Something was wrong checking objects from session, abort with error
24 print_error('restorechecksumfailed');
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;
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;
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;
39 //Check login
40 require_login();
42 //Check admin
43 if (!empty($id)) {
44 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
45 if (empty($to)) {
46 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
47 } else {
48 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
49 && !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
50 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
54 } else {
55 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
56 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
60 //Check site
61 if (!$site = get_site()) {
62 error("Site not found!");
64 $errorstr = '';
66 $status = restore_execute($restore,$info,$course_header,$errorstr);
68 if (!$status) {
69 error ("An error has occurred and the restore could not be completed!");
72 if (empty($restore->importing)) {
73 //Print final message
74 print_simple_box(get_string("restorefinished"),"center");
75 } else {
76 print_simple_box(get_string("importdatafinished"),"center");
77 $file = $CFG->dataroot . '/'
78 . $SESSION->import_preferences->backup_course
79 . '/backupdata/' . $SESSION->import_preferences->backup_name;
80 if (is_readable($file)) {
81 unlink($file);
83 else {
84 error_log("import course data: couldn't unlink $file");
86 unset($SESSION->restore);
88 print_continue("$CFG->wwwroot/course/view.php?id=".$restore->course_id);