Bumping version for 1.8.10 release (note new convention for numbering)
[moodle.git] / backup / backup_execute.html
blob76f9a0f2afb06465d5d37f2e3f495d4bd9c4a674
1 <?php //$Id$
2 //This page prints the backup todo list to see everything
4 //Check login
5 require_login();
7 if (!empty($course->id)) {
8 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
9 if (empty($to)) {
10 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
11 } else {
12 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
13 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
17 } else {
18 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
19 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
24 //Check site
25 if (!$site = get_site()) {
26 error("Site not found!");
29 $preferences = new StdClass;
30 backup_fetch_prefs_from_request($preferences,$count,$course);
31 //Another Info
32 $preferences->moodle_version = $CFG->version;
33 $preferences->moodle_release = $CFG->release;
34 $preferences->backup_version = $CFG->backup_version;
35 $preferences->backup_release = $CFG->backup_release;
37 if ($count == 0) {
38 notice("No backupable modules are installed!");
42 if (empty($to)) {
43 //Start the main table
44 echo "<table cellpadding=\"5\">";
46 //Now print the Backup Name tr
47 echo "<tr>";
48 echo "<td align=\"right\"><b>";
49 echo get_string("name").":";
50 echo "</b></td><td>";
51 echo $preferences->backup_name;
52 echo "</td></tr>";
54 //Start the main tr, where all the backup progress is done
55 echo "<tr>";
56 echo "<td colspan=\"2\">";
58 //Start the main ul
59 echo "<ul>";
61 //Check for temp and backup and backup_unique_code directory
62 //Create them as needed
63 echo "<li>".get_string("creatingtemporarystructures").'</li>';
64 $status = check_and_create_backup_dir($preferences->backup_unique_code);
65 //Empty dir
66 if ($status) {
67 $status = clear_backup_dir($preferences->backup_unique_code);
70 //Delete old_entries from backup tables
71 echo "<li>".get_string("deletingolddata").'</li>';
72 $status = backup_delete_old_data();
73 if (!$status) {
74 error ("An error occurred deleting old backup data");
77 //Create the moodle.xml file
78 if ($status) {
79 echo "<li>".get_string("creatingxmlfile");
80 //Begin a new list to xml contents
81 echo "<ul>";
82 echo "<li>".get_string("writingheader").'</li>';
83 //Obtain the xml file (create and open) and print prolog information
84 $backup_file = backup_open_xml($preferences->backup_unique_code);
85 echo "<li>".get_string("writinggeneralinfo").'</li>';
86 //Prints general info about backup to file
87 if ($backup_file) {
88 if (!$status = backup_general_info($backup_file,$preferences)) {
89 notify("An error occurred while backing up general info");
92 echo "<li>".get_string("writingcoursedata");
94 //Start new ul (for course)
95 echo "<ul>";
97 echo "<li>".get_string("courseinfo").'</li>';
98 //Prints course start (tag and general info)
99 if ($status) {
100 if (!$status = backup_course_start($backup_file,$preferences)) {
101 notify("An error occurred while backing up course start");
104 //Metacourse information
105 if ($status && $preferences->backup_metacourse) {
106 echo "<li>".get_string("metacourse").'</li>';
107 if (!$status = backup_course_metacourse($backup_file,$preferences)) {
108 notify("An error occurred while backing up metacourse info");
111 echo "<li>".get_string("blocks").'</li>';
112 //Blocks information
113 if ($status) {
114 if (!$status = backup_course_blocks($backup_file,$preferences)) {
115 notify("An error occurred while backing up course blocks");
118 echo "<li>".get_string("sections").'</li>';
119 //Section info
120 if ($status) {
121 if (!$status = backup_course_sections($backup_file,$preferences)) {
122 notify("An error occurred while backing up course sections");
126 //End course contents (close ul)
127 echo "</ul></li>";
129 //User info
130 if ($status) {
131 echo "<li>".get_string("writinguserinfo").'</li>';
132 if (!$status = backup_user_info($backup_file,$preferences)) {
133 notify("An error occurred while backing up user info");
137 //If we have selected to backup messages and we are
138 //doing a SITE backup, let's do it
139 if ($status && $preferences->backup_messages && $preferences->backup_course == SITEID) {
140 echo "<li>".get_string("writingmessagesinfo").'</li>';
141 if (!$status = backup_messages($backup_file,$preferences)) {
142 notify("An error occurred while backing up messages");
146 //If we have selected to backup quizzes, backup categories and
147 //questions structure (step 1). See notes on mod/quiz/backuplib.php
148 if ($status and !empty($preferences->mods['quiz']->backup)) {
149 echo "<li>".get_string("writingcategoriesandquestions").'</li>';
150 require_once($CFG->dirroot.'/mod/quiz/backuplib.php');
151 if (!$status = backup_question_categories($backup_file,$preferences)) {
152 notify("An error occurred while backing up quiz categories");
156 //Print logs if selected
157 if ($status) {
158 if ($preferences->backup_logs) {
159 echo "<li>".get_string("writingloginfo").'</li>';
160 if (!$status = backup_log_info($backup_file,$preferences)) {
161 notify("An error occurred while backing up log info");
166 //Print scales info
167 if ($status) {
168 echo "<li>".get_string("writingscalesinfo").'</li>';
169 if (!$status = backup_scales_info($backup_file,$preferences)) {
170 notify("An error occurred while backing up scales");
174 //Print groupings info
175 if ($status) {
176 echo "<li>".get_string("writinggroupingsinfo").'</li>';
177 if (!$status = backup_groupings_info($backup_file,$preferences)) {
178 notify("An error occurred while backing up groupings");
182 //Print groups info
183 if ($status) {
184 echo "<li>".get_string("writinggroupsinfo").'</li>';
185 if (!$status = backup_groups_info($backup_file,$preferences)) {
186 notify("An error occurred while backing up groups");
190 //Print events info
191 if ($status) {
192 echo "<li>".get_string("writingeventsinfo").'</li>';
193 if (!$status = backup_events_info($backup_file,$preferences)) {
194 notify("An error occurred while backing up events");
198 //Print gradebook info
199 if ($status) {
200 echo "<li>".get_string("writinggradebookinfo").'</li>';
201 if (!$status = backup_gradebook_info($backup_file,$preferences)) {
202 notify("An error occurred while backing up gradebook");
206 //Module info, this unique function makes all the work!!
207 //db export and module fileis copy
208 if ($status) {
209 $mods_to_backup = false;
210 //Check if we have any mod to backup
211 foreach ($preferences->mods as $module) {
212 if ($module->backup) {
213 $mods_to_backup = true;
216 //If we have to backup some module
217 if ($mods_to_backup) {
218 echo "<li>".get_string("writingmoduleinfo");
219 //Start modules tag
220 if (!$status = backup_modules_start ($backup_file,$preferences)) {
221 notify("An error occurred while backing up module info");
223 //Open ul for module list
224 echo "<ul>";
225 //Iterate over modules and call backup
226 foreach ($preferences->mods as $module) {
227 if ($module->backup and $status) {
228 echo "<li>".get_string("modulenameplural",$module->name).'</li>';
229 if (!$status = backup_module($backup_file,$preferences,$module->name)) {
230 notify("An error occurred while backing up '$module->name'");
234 //Close ul for module list
235 echo "</ul></li>";
236 //Close modules tag
237 if (!$status = backup_modules_end ($backup_file,$preferences)) {
238 notify("An error occurred while finishing the module backups");
243 //Backup course format data, if any.
244 echo '<li>'.get_string("courseformatdata").'</li>';
245 if($status) {
246 if (!$status = backup_format_data($backup_file,$preferences)) {
247 notify("An error occurred while backing up the course format data");
251 //Prints course end
252 if ($status) {
253 if (!$status = backup_course_end($backup_file,$preferences)) {
254 notify("An error occurred while closing the course backup");
257 //Close the xml file and xml data
258 if ($backup_file) {
259 backup_close_xml($backup_file);
262 //End xml contents (close ul)
263 echo "</ul></li>";
266 //Now, if selected, copy user files
267 if ($status) {
268 if ($preferences->backup_user_files) {
269 echo "<li>".get_string("copyinguserfiles").'</li>';
270 if (!$status = backup_copy_user_files ($preferences)) {
271 notify("An error occurred while copying user files");
276 //Now, if selected, copy course files
277 if ($status) {
278 if ($preferences->backup_course_files) {
279 echo "<li>".get_string("copyingcoursefiles").'</li>';
280 if (!$status = backup_copy_course_files ($preferences)) {
281 notify("An error occurred while copying course files");
286 //Now, zip all the backup directory contents
287 if ($status) {
288 echo "<li>".get_string("zippingbackup").'</li>';
289 if (!$status = backup_zip ($preferences)) {
290 notify("An error occurred while zipping the backup");
294 //Now, copy the zip file to course directory
295 if ($status) {
296 echo "<li>".get_string("copyingzipfile").'</li>';
297 if (!$status = copy_zip_to_course_dir ($preferences)) {
298 notify("An error occurred while copying the zip file to the course directory");
302 //Now, clean temporary data (db and filesystem)
303 if ($status) {
304 echo "<li>".get_string("cleaningtempdata").'</li>';
305 if (!$status = clean_temp_data ($preferences)) {
306 notify("An error occurred while cleaning up temporary data");
310 //Ends th main ul
311 echo "</ul>";
313 //End the main tr, where all the backup is done
314 echo "</td></tr>";
316 //End the main table
317 echo "</table>";
319 if (!$status) {
320 error ("The backup did not complete successfully",
321 "$CFG->wwwroot/course/view.php?id=$course->id");
324 if (empty($to)) {
325 //Print final message
326 print_simple_box(get_string("backupfinished"),"center");
327 print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&amp;wdir=/backupdata");
328 } else {
329 print_simple_box(get_string('importdataexported'),"CENTER");
330 if (!empty($preferences->backup_destination)) {
331 $filename = $preferences->backup_destination."/".$preferences->backup_name;
332 } else {
333 $filename = $preferences->backup_course."/backupdata/".$preferences->backup_name;
335 error_log($filename);
336 $SESSION->import_preferences = $preferences;
337 print_continue($CFG->wwwroot.'/course/import/activities/index.php?id='.$to.'&fromcourse='.$id.'&filename='.$filename);
340 $SESSION->backupprefs[$course->id] = null; // unset it so we're clear next time.