New translation added.
[moodle.git] / backup / restore_execute.html
blob0af87a5e6ebbad9af030b3a6568254cf38c165d4
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;
13 //Check login
14 require_login();
16 //Check admin
17 if (!isadmin()) {
18 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
21 //Check site
22 if (!$site = get_site()) {
23 error("Site not found!");
26 //Checks for the required files/functions to restore every module
27 //and include them
28 if ($allmods = get_records("modules") ) {
29 foreach ($allmods as $mod) {
30 $modname = $mod->name;
31 $modfile = "$mods_home/$modname/restorelib.php";
32 //If file exists and we have selected to restore that type of module
33 if ((file_exists($modfile)) and ($restore->mods[$modname]->restore)) {
34 include_once($modfile);
39 //Start the main table
40 echo "<table cellpadding=5>";
41 echo "<tr><td>";
43 //Start the main ul
44 echo "<ul>";
46 //Init status
47 $status = true;
49 //Localtion of the xml file
50 $xml_file = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code."/moodle.xml";
52 //If we've selected to restore into new course
53 //create it (course)
54 //Saving conversion id variables into backup_tables
55 if ($restore->restoreto ==1) {
56 echo "<li>Creating new course";
57 $status = restore_create_new_course($restore,&$course_header);
58 //Print course fullname and shortname and category
59 if ($status) {
60 echo "<ul>";
61 echo "<li>".$course_header->course_fullname." (".$course_header->course_shortname.")";
62 echo "<li>".get_string("category").": ".$course_header->category->name;
63 echo "</ul>";
64 //Put the destination course_id
65 $restore->course_id = $course_header->course_id;
67 } else {
68 $course = get_record("course","id",$restore->course_id);
69 if ($course) {
70 echo "<li>Using existing course";
71 echo "<ul>";
72 echo "<li>From: ".$course_header->course_fullname." (".$course_header->course_shortname.")";
73 echo "<li>To: ".$course->fullname." (".$course->shortname.")";
74 echo "</ul>";
78 //Now create the course_sections and their associated course_modules
79 if ($status) {
80 if ($restore->restoreto == 1) {
81 echo "<li>Creating sections";
82 $status = restore_create_sections($restore,$xml_file);
83 } else if ($restore->restoreto == 0) {
84 echo "<li>Checking sections";
85 $status = restore_create_sections($restore,$xml_file);
86 } else {
87 $status = false;
92 //Now create users as needed
93 if ($status and ($restore->users == 0 or $restore->users == 1)) {
94 echo "<li>Creating users<br>";
95 $status = restore_create_users($restore,$xml_file);
96 //Now print info about the work done
97 if ($status) {
98 $recs = get_records_sql("select old_id, new_id from {$CFG->prefix}backup_ids
99 where backup_code = '$restore->backup_unique_code' and
100 table_name = 'user'");
101 //We've records
102 if ($recs) {
103 $new_count = 0;
104 $exists_count = 0;
105 $student_count = 0;
106 $teacher_count = 0;
107 $coursecreator_count = 0;
108 $admin_count = 0;
109 $other_count = 0;
110 $counter = 0;
111 //Iterate, filling counters
112 foreach ($recs as $rec) {
113 //Get full record, using backup_getids
114 $record = backup_getid($restore->backup_unique_code,"user",$rec->old_id);
115 if (strpos($record->info,"new") !== false) {
116 $new_count++;
118 if (strpos($record->info,"exists") !== false) {
119 $exists_count++;
121 if (strpos($record->info,"student")) {
122 $student_count++;
123 } else if (strpos($record->info,"teacher")) {
124 $teacher_count++;
125 } else if (strpos($record->info,"admin")) {
126 $admin_count++;
127 } else if (strpos($record->info,"coursecreator")) {
128 $coursecreator_count++;
129 } else if ($record->info == "new" or $record->info == "exists") {
130 $other_count++;
132 //Do some output
133 $counter++;
134 if ($counter % 10 == 0) {
135 echo ".";
136 if ($counter % 200 == 0) {
137 echo "<br>";
139 backup_flush(300);
142 //Now print information gathered
143 echo " (new: ".$new_count.", existing: ".$exists_count.")";
144 echo "<ul>";
145 echo "<li>Students: ".$student_count;
146 echo "<li>Teachers: ".$teacher_count;
147 echo "<li>Course Creators: ".$coursecreator_count;
148 echo "<li>Admins: ".$admin_count;
149 echo "<li>Other: ".$other_count;
150 echo "</ul>";
151 } else {
152 //Something is wrong. There is no users !!
153 $status = false;
158 //Now create categories and questions as needed (STEP1)
159 if ($status and ($restore->mods[quiz]->restore)) {
160 echo "<li>Creating Categories and Questions<br>";
161 $status = restore_create_questions($restore,$xml_file);
164 //Now create user_files as needed
165 if ($status and ($restore->user_files)) {
166 echo "<li>Copying User Files<br>";
167 $status = restore_user_files($restore);
168 //If all is ok (and we have a counter)
169 if ($status and ($status !== true)) {
170 //Inform about user dirs created from backup
171 echo "<ul>";
172 echo "<li>User Zones: ".$status;
173 echo "</ul>";
177 //Now create course files as needed
178 if ($status and ($restore->course_files)) {
179 echo "<li>Copying Course Files<br>";
180 $status = restore_course_files($restore);
181 //If all is ok (and we have a counter)
182 if ($status and ($status !== true)) {
183 //Inform about user dirs created from backup
184 echo "<ul>";
185 echo "<li>Main Files/Folders: ".$status;
186 echo "</ul>";
190 //Now create course modules as needed
191 if ($status) {
192 echo "<li>Creating Course Modules";
193 $status = restore_create_modules($restore,$xml_file);
211 //Now create log entries as needed
212 if ($status and ($restore->logs)) {
213 echo "<li>Creating Log Entries <b>(not implemented!!)</b>";
216 //Now, if all is OK, adjust the instance field in course_modules !!
217 if ($status) {
218 echo "<li>Checking Instances";
219 $status = restore_check_instances($restore);
222 //Now if all is OK, update course modinfo field !!
223 if ($status) {
224 echo "<li>Checking Course";
225 rebuild_course_cache($restore->course_id);
228 //Cleanup temps (files and db)
229 if ($status) {
230 echo "<li>Cleaning up temp data";
231 $status = clean_temp_data ($restore);
234 //End the main ul
235 echo "</ul>";
238 //End the main table
239 echo "</tr></td>";
240 echo "</table>";
242 if (!$status) {
243 error ("An error has ocurred");
246 //Print final message
247 print_simple_box(get_string("restorefinished"),"CENTER");
248 print_continue($moodle_home."/course/view.php?id=".$restore->course_id);