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");
174 //Print groupings info
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");
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");
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
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
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");
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
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
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>';
246 if (!$status = backup_format_data($backup_file,$preferences)) {
247 notify("An error occurred while backing up the course format data");
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
259 backup_close_xml($backup_file);
262 //End xml contents (close ul)
266 //Now, if selected, copy user files
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
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
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
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)
304 echo "<li>".get_string("cleaningtempdata").'</li>';
305 if (!$status = clean_temp_data ($preferences)) {
306 notify("An error occurred while cleaning up temporary data");
313 //End the main tr, where all the backup is done
320 error ("The backup did not complete successfully",
321 "$CFG->wwwroot/course/view.php?id=$course->id");
325 //Print final message
326 print_simple_box(get_string("backupfinished"),"center");
327 print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course
."&wdir=/backupdata");
329 print_simple_box(get_string('importdataexported'),"CENTER");
330 if (!empty($preferences->backup_destination
)) {
331 $filename = $preferences->backup_destination
."/".$preferences->backup_name
;
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.