2003-05-04 21:29:27 +00:00
|
|
|
<?PHP //$Id$
|
|
|
|
//This page prints the backup todo list to see everything
|
|
|
|
|
2003-05-18 17:15:05 +00:00
|
|
|
//Check login
|
|
|
|
require_login();
|
|
|
|
|
|
|
|
//Check admin
|
|
|
|
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!");
|
|
|
|
}
|
|
|
|
|
2003-05-04 21:29:27 +00:00
|
|
|
//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 = "$mods_home/$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)) {
|
2003-05-09 23:21:55 +00:00
|
|
|
//Every undefined backup_XXXX isn't exported
|
|
|
|
$$var = 0;
|
2003-05-04 21:29:27 +00:00
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
//Now stores all the mods preferences into an array into preferences
|
|
|
|
$preferences->mods[$modname]->backup = $$var;
|
|
|
|
|
2003-05-04 21:29:27 +00:00
|
|
|
//Check include user info
|
|
|
|
$var = "backup_user_info_".$modname;
|
|
|
|
if (!isset($$var)) {
|
|
|
|
$$var = 1;
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
//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;
|
2003-05-04 21:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check other parameters
|
|
|
|
if (!isset($backup_users)) {
|
|
|
|
$backup_users = 1;
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_users = $backup_users;
|
2003-05-04 21:29:27 +00:00
|
|
|
|
|
|
|
if (!isset($backup_logs)) {
|
|
|
|
$backup_logs = 1;
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_logs = $backup_logs;
|
2003-05-04 21:29:27 +00:00
|
|
|
|
|
|
|
if (!isset($backup_user_files)) {
|
|
|
|
$backup_user_files = 1;
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_user_files = $backup_user_files;
|
2003-05-04 21:29:27 +00:00
|
|
|
|
|
|
|
if (!isset($backup_course_files)) {
|
|
|
|
$backup_course_files = 2;
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_course_files = $backup_course_files;
|
2003-05-04 21:29:27 +00:00
|
|
|
|
2003-05-04 23:24:48 +00:00
|
|
|
if (!isset($id)) {
|
|
|
|
error ("Course not specified");
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_course = $id;
|
2003-05-04 23:24:48 +00:00
|
|
|
|
|
|
|
if (!isset($backup_name)) {
|
|
|
|
error ("Backup name not specified");
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_name = $backup_name;
|
2003-05-04 23:24:48 +00:00
|
|
|
|
|
|
|
if (!isset($backup_unique_code)) {
|
|
|
|
error ("Backup unique code not specified");
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_unique_code = $backup_unique_code;
|
|
|
|
|
|
|
|
//Another Info
|
|
|
|
$preferences->moodle_version = $version;
|
|
|
|
$preferences->moodle_release = $release;
|
|
|
|
$preferences->backup_version = $backup_version;
|
|
|
|
$preferences->backup_release = $backup_release;
|
2003-05-04 23:24:48 +00:00
|
|
|
|
2003-05-04 21:29:27 +00:00
|
|
|
if ($count == 0) {
|
|
|
|
notice("No backupable modules are installed!");
|
|
|
|
}
|
|
|
|
|
2003-05-04 23:24:48 +00:00
|
|
|
//Start the main table
|
|
|
|
echo "<table cellpadding=5>";
|
2003-05-04 21:29:27 +00:00
|
|
|
|
|
|
|
//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>";
|
|
|
|
|
2003-05-04 23:24:48 +00:00
|
|
|
//Start the main tr, where all the backup progress is done
|
|
|
|
echo "<tr>";
|
|
|
|
echo "<td colspan=\"2\">";
|
2003-05-06 22:48:25 +00:00
|
|
|
|
|
|
|
//Start the main ul
|
|
|
|
echo "<ul>";
|
2003-05-04 21:29:27 +00:00
|
|
|
|
2003-05-04 23:24:48 +00:00
|
|
|
//Check for temp and backup and backup_unique_code directory
|
|
|
|
//Create them as needed
|
|
|
|
echo "<li>Creating temporary structures";
|
|
|
|
$status = check_and_create_backup_dir($backup_unique_code);
|
|
|
|
//Empty dir
|
|
|
|
if ($status) {
|
|
|
|
$status = clear_backup_dir($backup_unique_code);
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
|
2003-05-16 17:36:47 +00:00
|
|
|
//Delete old_entries from backup tables
|
|
|
|
echo "<li>Deteting old data";
|
|
|
|
$status = backup_delete_old_data();
|
|
|
|
if (!$status) {
|
|
|
|
error ("An error has ocurred");
|
|
|
|
}
|
|
|
|
|
2003-05-06 22:48:25 +00:00
|
|
|
//Create the moodle.xml file
|
|
|
|
if ($status) {
|
|
|
|
echo "<li>Creating xml file";
|
|
|
|
//Begin a new list to xml contents
|
|
|
|
echo "<ul>";
|
|
|
|
echo "<li>Writing header";
|
|
|
|
//Obtain the xml file (create and open) and print prolog information
|
|
|
|
$backup_file = backup_open_xml($backup_unique_code);
|
2003-05-07 22:15:14 +00:00
|
|
|
echo "<li>Writing general info";
|
2003-05-06 22:48:25 +00:00
|
|
|
//Prints general info about backup to file
|
|
|
|
if ($backup_file) {
|
|
|
|
$status = backup_general_info($backup_file,$preferences);
|
|
|
|
}
|
2003-05-07 22:15:14 +00:00
|
|
|
echo "<li>Writing course data";
|
2003-05-06 22:48:25 +00:00
|
|
|
|
2003-05-07 22:15:14 +00:00
|
|
|
//Start new ul (for course)
|
|
|
|
echo "<ul>";
|
|
|
|
|
|
|
|
echo "<li>Course info";
|
|
|
|
//Prints course start (tag and general info)
|
|
|
|
if ($status) {
|
|
|
|
$status = backup_course_start($backup_file,$preferences);
|
|
|
|
}
|
|
|
|
echo "<li>Sections";
|
|
|
|
//Section info
|
|
|
|
if ($status) {
|
2003-05-09 14:57:41 +00:00
|
|
|
$status = backup_course_sections($backup_file,$preferences);
|
2003-05-07 22:15:14 +00:00
|
|
|
}
|
|
|
|
|
2003-05-09 14:57:41 +00:00
|
|
|
//End course contents (close ul)
|
|
|
|
echo "</ul>";
|
2003-05-07 22:15:14 +00:00
|
|
|
|
2003-05-09 14:57:41 +00:00
|
|
|
echo "<li>Writing users info";
|
2003-05-07 22:15:14 +00:00
|
|
|
//User info
|
2003-05-09 14:57:41 +00:00
|
|
|
if ($status) {
|
|
|
|
$status = backup_user_info($backup_file,$preferences);
|
|
|
|
}
|
2003-05-09 20:05:15 +00:00
|
|
|
|
|
|
|
//Print logs if selected
|
2003-05-10 17:25:20 +00:00
|
|
|
if ($status) {
|
|
|
|
if ($preferences->backup_logs) {
|
|
|
|
echo "<li>Writing logs info";
|
2003-05-09 20:05:15 +00:00
|
|
|
$status = backup_log_info($backup_file,$preferences);
|
|
|
|
}
|
|
|
|
}
|
2003-05-07 22:15:14 +00:00
|
|
|
|
2003-05-10 17:25:20 +00:00
|
|
|
//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>Writing modules info";
|
|
|
|
//Start modules tag
|
|
|
|
$status = backup_modules_start ($backup_file,$preferences);
|
|
|
|
//Open ul for module list
|
|
|
|
echo "<ul>";
|
|
|
|
//Iterate over modules and call backupa
|
|
|
|
foreach ($preferences->mods as $module) {
|
|
|
|
if ($module->backup and $status) {
|
|
|
|
echo "<li>".$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);
|
|
|
|
}
|
|
|
|
}
|
2003-05-07 22:15:14 +00:00
|
|
|
|
|
|
|
//Prints course end
|
|
|
|
if ($status) {
|
|
|
|
$status = backup_course_end($backup_file,$preferences);
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
//Close the xml file and xml data
|
|
|
|
if ($backup_file) {
|
2003-05-07 22:15:14 +00:00
|
|
|
backup_close_xml($backup_file);
|
2003-05-06 22:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//End xml contents (close ul)
|
|
|
|
echo "</ul>";
|
|
|
|
}
|
2003-05-10 17:44:08 +00:00
|
|
|
|
|
|
|
//Now, if selected, copy user files
|
|
|
|
if ($status) {
|
|
|
|
if ($preferences->backup_user_files) {
|
2003-05-11 00:14:11 +00:00
|
|
|
echo "<li>Copying user files";
|
|
|
|
$status = backup_copy_user_files ($preferences);
|
2003-05-10 17:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Now, if selected, copy course files
|
|
|
|
if ($status) {
|
|
|
|
if ($preferences->backup_course_files) {
|
2003-05-11 00:14:11 +00:00
|
|
|
echo "<li>Copying course files";
|
|
|
|
$status = backup_copy_course_files ($preferences);
|
2003-05-10 17:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
|
2003-05-11 11:06:23 +00:00
|
|
|
//Now, zip all the backup directory contents
|
|
|
|
if ($status) {
|
|
|
|
echo "<li>Zipping backup";
|
|
|
|
$status = backup_zip ($preferences,$moodle_home);
|
2003-05-11 17:45:56 +00:00
|
|
|
}
|
2003-05-11 11:06:23 +00:00
|
|
|
|
2003-05-11 17:45:56 +00:00
|
|
|
//Now, copy the zip file to course directory
|
|
|
|
if ($status) {
|
|
|
|
echo "<li>Copying zip file";
|
|
|
|
$status = copy_zip_to_course_dir ($preferences);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Now, clean temporary data (db and filesystem)
|
|
|
|
if ($status) {
|
|
|
|
echo "<li>Cleaning up temp data";
|
|
|
|
$status = clean_temp_data ($preferences);
|
2003-05-11 11:06:23 +00:00
|
|
|
}
|
|
|
|
|
2003-05-04 23:24:48 +00:00
|
|
|
if (!$status) {
|
|
|
|
error ("An error has ocurred");
|
|
|
|
}
|
2003-05-04 21:29:27 +00:00
|
|
|
|
2003-05-06 22:48:25 +00:00
|
|
|
//Ends th main ul
|
|
|
|
echo "</ul>";
|
2003-05-04 21:29:27 +00:00
|
|
|
|
2003-05-04 23:24:48 +00:00
|
|
|
//End the main tr, where all the backup is done
|
2003-05-06 22:48:25 +00:00
|
|
|
echo "</td></tr>";
|
2003-05-04 21:29:27 +00:00
|
|
|
|
2003-05-04 23:24:48 +00:00
|
|
|
//End the main table
|
|
|
|
echo "</table>";
|
2003-05-11 17:45:56 +00:00
|
|
|
|
|
|
|
//Print final message
|
|
|
|
print_simple_box(get_string("backupfinished"),"CENTER");
|
|
|
|
print_continue($moodle_home."/files/index.php?id=".$preferences->backup_course."&wdir=/".get_string("backupdir"));
|
|
|
|
|
2003-05-04 21:29:27 +00:00
|
|
|
?>
|