Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

297 lines (253 sloc) 9.463 kB
<?PHP //$Id$
//This page prints the backup todo list to see everything
//Check login
require_login();
if (!empty($course->id)) {
if (!isteacheredit($course->id)) {
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
}
} else {
if (!isadmin()) {
error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
}
}
//Check site
if (!$site = get_site()) {
error("Site not found!");
}
//Checks for the required files/functions to backup every mod
//And check if there is data about it
$count = 0;
if ($allmods = get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
$modbackup = $modname."_backup_mods";
$modcheckbackup = $modname."_check_backup_mods";
if (file_exists($modfile)) {
include_once($modfile);
if (function_exists($modbackup) and function_exists($modcheckbackup)) {
$var = "exists_".$modname;
$$var = true;
$count++;
}
}
//Check data
//Check module info
$var = "backup_".$modname;
if (!isset($$var)) {
//Every undefined backup_XXXX isn't exported
$$var = 0;
}
//Now stores all the mods preferences into an array into preferences
$preferences->mods[$modname]->backup = $$var;
//Check include user info
$var = "backup_user_info_".$modname;
if (!isset($$var)) {
$$var = 1;
}
//Now stores all the mods preferences into an array into preferences
$preferences->mods[$modname]->userinfo = $$var;
//And the name of the mod
$preferences->mods[$modname]->name = $modname;
}
}
//Check other parameters
if (!isset($backup_users)) {
$backup_users = 1;
}
$preferences->backup_users = $backup_users;
if (!isset($backup_logs)) {
$backup_logs = 0;
}
$preferences->backup_logs = $backup_logs;
if (!isset($backup_user_files)) {
$backup_user_files = 1;
}
$preferences->backup_user_files = $backup_user_files;
if (!isset($backup_course_files)) {
$backup_course_files = 2;
}
$preferences->backup_course_files = $backup_course_files;
if (!isset($id)) {
error ("Course not specified");
}
$preferences->backup_course = $id;
if (!isset($backup_name)) {
error ("Backup name not specified");
}
$preferences->backup_name = $backup_name;
if (!isset($backup_unique_code)) {
error ("Backup unique code not specified");
}
$preferences->backup_unique_code = $backup_unique_code;
//Another Info
$preferences->moodle_version = $CFG->version;
$preferences->moodle_release = $CFG->release;
$preferences->backup_version = $CFG->backup_version;
$preferences->backup_release = $CFG->backup_release;
if ($count == 0) {
notice("No backupable modules are installed!");
}
//Start the main table
echo "<table cellpadding=5>";
//Now print the Backup Name tr
echo "<tr>";
echo "<td align=\"right\"><P><B>";
echo get_string("name").":";
echo "</B></td><td>";
echo $backup_name;
echo "</td></tr>";
//Start the main tr, where all the backup progress is done
echo "<tr>";
echo "<td colspan=\"2\">";
//Start the main ul
echo "<ul>";
//Check for temp and backup and backup_unique_code directory
//Create them as needed
echo "<li>".get_string("creatingtemporarystructures");
$status = check_and_create_backup_dir($backup_unique_code);
//Empty dir
if ($status) {
$status = clear_backup_dir($backup_unique_code);
}
//Delete old_entries from backup tables
echo "<li>".get_string("deletingolddata");
$status = backup_delete_old_data();
if (!$status) {
error ("An error has ocurred");
}
//Create the moodle.xml file
if ($status) {
echo "<li>".get_string("creatingxmlfile");
//Begin a new list to xml contents
echo "<ul>";
echo "<li>".get_string("writingheader");
//Obtain the xml file (create and open) and print prolog information
$backup_file = backup_open_xml($backup_unique_code);
echo "<li>".get_string("writinggeneralinfo");;
//Prints general info about backup to file
if ($backup_file) {
$status = backup_general_info($backup_file,$preferences);
}
echo "<li>".get_string("writingcoursedata");
//Start new ul (for course)
echo "<ul>";
echo "<li>".get_string("courseinfo");
//Prints course start (tag and general info)
if ($status) {
$status = backup_course_start($backup_file,$preferences);
}
echo "<li>".get_string("sections");
//Section info
if ($status) {
$status = backup_course_sections($backup_file,$preferences);
}
//End course contents (close ul)
echo "</ul>";
echo "<li>".get_string("writinguserinfo");
//User info
if ($status) {
$status = backup_user_info($backup_file,$preferences);
}
//If we have selected to backup quizzes, backup categories and
//questions structure (step 1). See notes on mod/quiz/backuplib.php
if ($status and $preferences->mods['quiz']->backup) {
echo "<li>".get_string("writingcategoriesandquestions");
$status = quiz_backup_question_categories($backup_file,$preferences);
}
//Print logs if selected
if ($status) {
if ($preferences->backup_logs) {
echo "<li>".get_string("writingloginfo");
$status = backup_log_info($backup_file,$preferences);
}
}
//Print scales info
if ($status) {
echo "<li>".get_string("writingscalesinfo");
$status = backup_scales_info($backup_file,$preferences);
}
//Module info, this unique function makes all the work!!
//db export and module fileis copy
if ($status) {
$mods_to_backup = false;
//Check if we have any mod to backup
foreach ($preferences->mods as $module) {
if ($module->backup) {
$mods_to_backup = true;
}
}
//If we have to backup some module
if ($mods_to_backup) {
echo "<li>".get_string("writingmoduleinfo");
//Start modules tag
$status = backup_modules_start ($backup_file,$preferences);
//Open ul for module list
echo "<ul>";
//Iterate over modules and call backup
foreach ($preferences->mods as $module) {
if ($module->backup and $status) {
echo "<li>".get_string("modulenameplural",$module->name);
$status = backup_module($backup_file,$preferences,$module->name);
}
}
//Close ul for module list
echo "</ul>";
//Close modules tag
$status = backup_modules_end ($backup_file,$preferences);
}
}
//Prints course end
if ($status) {
$status = backup_course_end($backup_file,$preferences);
}
//Close the xml file and xml data
if ($backup_file) {
backup_close_xml($backup_file);
}
//End xml contents (close ul)
echo "</ul>";
}
//Now, if selected, copy user files
if ($status) {
if ($preferences->backup_user_files) {
echo "<li>".get_string("copyinguserfiles");
$status = backup_copy_user_files ($preferences);
}
}
//Now, if selected, copy course files
if ($status) {
if ($preferences->backup_course_files) {
echo "<li>".get_string("copyingcoursefiles");
$status = backup_copy_course_files ($preferences);
}
}
//Now, zip all the backup directory contents
if ($status) {
echo "<li>".get_string("zippingbackup");
$status = backup_zip ($preferences);
}
//Now, copy the zip file to course directory
if ($status) {
echo "<li>".get_string("copyingzipfile");
$status = copy_zip_to_course_dir ($preferences);
}
//Now, clean temporary data (db and filesystem)
if ($status) {
echo "<li>".get_string("cleaningtempdata");
$status = clean_temp_data ($preferences);
}
//Ends th main ul
echo "</ul>";
//End the main tr, where all the backup is done
echo "</td></tr>";
//End the main table
echo "</table>";
if (!$status) {
error ("An error has ocurred");
}
//Print final message
print_simple_box(get_string("backupfinished"),"CENTER");
print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&wdir=/backupdata");
?>
Jump to Line
Something went wrong with that request. Please try again.