"MDL-14129, fix print_error"
[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
23 //Check admin
be2a6fc6 24 if (!empty($id)) {
0fd332a8 25 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
873bf875 26 if (empty($to)) {
5a2a5331 27 print_error("You need to be a teacher or admin user to use this page.", '', "$CFG->wwwroot/login/index.php");
873bf875 28 } else {
d4c550f5 29 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
30 && !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
5a2a5331 31 print_error("You need to be a teacher or admin user to use this page.", '', "$CFG->wwwroot/login/index.php");
873bf875 32 }
33 }
be2a6fc6 34 }
35 } else {
957f6fc9 36 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
5a2a5331 37 print_error("You need to be an admin user to use this page.", '', "$CFG->wwwroot/login/index.php");
be2a6fc6 38 }
a2c7397c 39 }
40
41 //Check site
42 if (!$site = get_site()) {
5a2a5331 43 print_error("Site not found!");
a2c7397c 44 }
f90666aa 45 $errorstr = '';
3f1c7233 46
f90666aa 47 $status = restore_execute($restore,$info,$course_header,$errorstr);
a2c7397c 48
49 if (!$status) {
5a2a5331 50 print_error ("An error has occurred and the restore could not be completed!");
a2c7397c 51 }
52
410c459d 53 if (empty($restore->importing)) {
873bf875 54 //Print final message
1bbf415f 55 print_simple_box(get_string("restorefinished"),"center");
873bf875 56 } else {
1bbf415f 57 print_simple_box(get_string("importdatafinished"),"center");
b5037f72 58 $file = $CFG->dataroot . '/'
59 . $SESSION->import_preferences->backup_course
60 . '/backupdata/' . $SESSION->import_preferences->backup_name;
61 if (is_readable($file)) {
62 unlink($file);
63 }
64 else {
65 error_log("import course data: couldn't unlink $file");
66 }
873bf875 67 unset($SESSION->restore);
68 }
9c1ae5ae 69 print_continue("$CFG->wwwroot/course/view.php?id=".$restore->course_id);
11c1d525 70
a2c7397c 71?>