2 //This page prints the backup todo list to see everything
7 if (!empty($course->id
)) {
8 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
10 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
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");
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");
25 if (!$site = get_site()) {
26 error("Site not found!");
29 $preferences = new StdClass
;
30 backup_fetch_prefs_from_request($preferences,$count,$course);
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
;
38 notice("No backupable modules are installed!");
43 //Start the main table
44 echo "<table cellpadding=\"5\">";
46 //Now print the Backup Name tr
48 echo "<td align=\"right\"><b>";
49 echo get_string("name").":";
51 echo $preferences->backup_name
;
54 //Start the main tr, where all the backup progress is done
56 echo "<td colspan=\"2\">";
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
);
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();
74 error ("An error occurred deleting old backup data");
77 //Create the moodle.xml file
79 echo "<li>".get_string("creatingxmlfile");
80 //Begin a new list to xml contents
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
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)
97 echo "<li>".get_string("courseinfo").'</li>';
98 //Prints course start (tag and general info)
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>';
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>';
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)
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
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");
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");
176 echo "<li>".get_string("writinggroupsinfo").'</li>';
177 if (!$status = backup_groups_info($backup_file,$preferences)) {
178 notify("An error occurred while backing up groups");
184 echo "<li>".get_string("writingeventsinfo").'</li>';
185 if (!$status = backup_events_info($backup_file,$preferences)) {
186 notify("An error occurred while backing up events");
190 //Print gradebook info
192 echo "<li>".get_string("writinggradebookinfo").'</li>';
193 if (!$status = backup_gradebook_info($backup_file,$preferences)) {
194 notify("An error occurred while backing up gradebook");
198 //Module info, this unique function makes all the work!!
199 //db export and module fileis copy
201 $mods_to_backup = false;
202 //Check if we have any mod to backup
203 foreach ($preferences->mods
as $module) {
204 if ($module->backup
) {
205 $mods_to_backup = true;
208 //If we have to backup some module
209 if ($mods_to_backup) {
210 echo "<li>".get_string("writingmoduleinfo");
212 if (!$status = backup_modules_start ($backup_file,$preferences)) {
213 notify("An error occurred while backing up module info");
215 //Open ul for module list
217 //Iterate over modules and call backup
218 foreach ($preferences->mods
as $module) {
219 if ($module->backup
and $status) {
220 echo "<li>".get_string("modulenameplural",$module->name
).'</li>';
221 if (!$status = backup_module($backup_file,$preferences,$module->name
)) {
222 notify("An error occurred while backing up '$module->name'");
226 //Close ul for module list
229 if (!$status = backup_modules_end ($backup_file,$preferences)) {
230 notify("An error occurred while finishing the module backups");
237 if (!$status = backup_course_end($backup_file,$preferences)) {
238 notify("An error occurred while closing the course backup");
241 //Close the xml file and xml data
243 backup_close_xml($backup_file);
246 //End xml contents (close ul)
250 //Now, if selected, copy user files
252 if ($preferences->backup_user_files
) {
253 echo "<li>".get_string("copyinguserfiles").'</li>';
254 if (!$status = backup_copy_user_files ($preferences)) {
255 notify("An error occurred while copying user files");
260 //Now, if selected, copy course files
262 if ($preferences->backup_course_files
) {
263 echo "<li>".get_string("copyingcoursefiles").'</li>';
264 if (!$status = backup_copy_course_files ($preferences)) {
265 notify("An error occurred while copying course files");
270 //Now, zip all the backup directory contents
272 echo "<li>".get_string("zippingbackup").'</li>';
273 if (!$status = backup_zip ($preferences)) {
274 notify("An error occurred while zipping the backup");
278 //Now, copy the zip file to course directory
280 echo "<li>".get_string("copyingzipfile").'</li>';
281 if (!$status = copy_zip_to_course_dir ($preferences)) {
282 notify("An error occurred while copying the zip file to the course directory");
286 //Now, clean temporary data (db and filesystem)
288 echo "<li>".get_string("cleaningtempdata").'</li>';
289 if (!$status = clean_temp_data ($preferences)) {
290 notify("An error occurred while cleaning up temporary data");
297 //End the main tr, where all the backup is done
304 error ("The backup did not complete successfully",
305 "$CFG->wwwroot/course/view.php?id=$course->id");
309 //Print final message
310 print_simple_box(get_string("backupfinished"),"center");
311 print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course
."&wdir=/backupdata");
313 print_simple_box(get_string('importdataexported'),"CENTER");
314 if (!empty($preferences->backup_destination
)) {
315 $filename = $preferences->backup_destination
."/".$preferences->backup_name
;
317 $filename = $preferences->backup_course
."/backupdata/".$preferences->backup_name
;
319 error_log($filename);
320 $SESSION->import_preferences
= $preferences;
321 print_continue($CFG->wwwroot
.'/course/import/activities/index.php?id='.$to.'&fromcourse='.$id.'&filename='.$filename);
324 $SESSION->backupprefs
[$course->id
] = null; // unset it so we're clear next time.