mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
Changed to support the backup_ids table in all modules (to store and
convert ids in backup/restore. Added a check_version (copied from main moodle auto-update) to mantain changes in backup/restore system.
This commit is contained in:
parent
8980a4e8db
commit
8cc242516e
@ -13,6 +13,9 @@
|
||||
|
||||
//Units used
|
||||
require_once ("$moodle_home/config.php");
|
||||
require_once ("backup_version.php");
|
||||
require_once ("db/backup_$CFG->dbtype.php");
|
||||
require_once ("lib.php");
|
||||
|
||||
//Optional variables
|
||||
optional_variable($id); // course id
|
||||
@ -29,6 +32,46 @@
|
||||
if (!$site = get_site()) {
|
||||
error("Site not found!");
|
||||
}
|
||||
|
||||
//Check backup_version
|
||||
if ($CFG->backup_version) {
|
||||
if ($backup_version > $CFG->backup_version) { // upgrade
|
||||
$a->oldversion = $CFG->backup_version;
|
||||
$a->newversion = $backup_version;
|
||||
$strdatabasechecking = get_string("databasechecking", "", $a);
|
||||
$strdatabasesuccess = get_string("databasesuccess");
|
||||
print_header($strdatabasechecking, $strdatabasechecking, $strdatabasechecking);
|
||||
print_heading($strdatabasechecking);
|
||||
$db->debug=true;
|
||||
if (backup_upgrade($a->oldversion)) {
|
||||
$db->debug=false;
|
||||
if (set_config("backup_version", $a->newversion)) {
|
||||
notify($strdatabasesuccess, "green");
|
||||
print_continue("backup.php");
|
||||
die;
|
||||
} else {
|
||||
notify("Upgrade failed! (Could not update version in config table)");
|
||||
die;
|
||||
}
|
||||
} else {
|
||||
$db->debug=false;
|
||||
notify("Upgrade failed! See backup_version.php");
|
||||
die;
|
||||
}
|
||||
} else if ($backup_version < $CFG->backup_version) {
|
||||
notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
|
||||
}
|
||||
//Not exists. Starting installation
|
||||
} else {
|
||||
$strdatabaseupgrades = get_string("databaseupgrades");
|
||||
print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades);
|
||||
|
||||
if (set_config("backup_version", "2003010100")) {
|
||||
print_heading("You are currently going to install the needed structures to Backup/Recover");
|
||||
print_continue("backup.php");
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
//Get strings
|
||||
$strcoursebackup = get_string("coursebackup");
|
||||
|
@ -63,7 +63,7 @@
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\"><P><B>";
|
||||
echo get_string("name").":";
|
||||
echo "</td><td>";
|
||||
echo "</B></td><td>";
|
||||
//Calculate the backup string
|
||||
$backup_name = strtolower(get_string("backup"));
|
||||
//If non-translated, use "backup"
|
||||
@ -76,16 +76,17 @@
|
||||
if (substr($backup_name_format,0,1) == "[") {
|
||||
$backup_name_format = "%%Y%%m%%d-%%H%%M";
|
||||
}
|
||||
$backup_name .= "-".userdate(time(),$backup_name_format,99,false).".zip";
|
||||
$backup_name .= "-".strtolower($course->shortname)."-".userdate(time(),$backup_name_format,99,false).".zip";
|
||||
echo $backup_name;
|
||||
//Add as hidden name
|
||||
echo "<input type=\"hidden\" name=\"backup_name\" value=\"".$backup_name."\">";
|
||||
echo "</td></tr>";
|
||||
|
||||
//Calculate the temp dir name to do all the work
|
||||
$tempdir_name = userdate(time(),"%Y%m%d%H%M",99,false);
|
||||
//Calculate the backup unique code to allow simultaneus backups (to define
|
||||
//the temp-directory name and records in backup temp tables
|
||||
$backup_unique_code = time();
|
||||
//Add as hidden name
|
||||
echo "<input type=\"hidden\" name=\"tempdir_name\" value=\"".$tempdir_name."\">";
|
||||
echo "<input type=\"hidden\" name=\"backup_unique_code\" value=\"".$backup_unique_code."\">";
|
||||
|
||||
//Line
|
||||
echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
|
||||
@ -124,7 +125,7 @@
|
||||
echo $backup_user_options[$$var]."<P>";
|
||||
//Call the check function to show more info
|
||||
$modcheckbackup = $modname."_check_backup_mods";
|
||||
$table->data = $modcheckbackup($id,$$var);
|
||||
$table->data = $modcheckbackup($id,$$var,$backup_unique_code);
|
||||
print_table($table);
|
||||
echo "</td></tr>";
|
||||
}
|
||||
|
@ -21,12 +21,12 @@
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
function assignment_backup_mods($course,$user_data=false) {
|
||||
function assignment_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
print "hola";
|
||||
}
|
||||
|
||||
//Return an array of info (name,value)
|
||||
function assignment_check_backup_mods($course,$user_data=false) {
|
||||
function assignment_check_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
//First the course data
|
||||
$info[0][0] = get_string("modulenameplural","assignment");
|
||||
if ($ids = assignment_ids ($course)) {
|
||||
|
@ -21,12 +21,12 @@
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
function choice_backup_mods($course,$user_data=false) {
|
||||
function choice_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
print "hola";
|
||||
}
|
||||
|
||||
////Return an array of info (name,value)
|
||||
function choice_check_backup_mods($course,$user_data=false) {
|
||||
function choice_check_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
//First the course data
|
||||
$info[0][0] = get_string("modulenameplural","choice");
|
||||
if ($ids = choice_ids ($course)) {
|
||||
|
@ -36,7 +36,7 @@
|
||||
}
|
||||
|
||||
////Return an array of info (name,value)
|
||||
function forum_check_backup_mods($course,$user_data=false) {
|
||||
function forum_check_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
//First the course data
|
||||
$info[0][0] = get_string("modulenameplural","forum");
|
||||
if ($ids = forum_ids ($course)) {
|
||||
|
@ -21,12 +21,12 @@
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
function journal_backup_mods($course,$user_data=false) {
|
||||
function journal_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
print "hola";
|
||||
}
|
||||
|
||||
////Return an array of info (name,value)
|
||||
function journal_check_backup_mods($course,$user_data=false) {
|
||||
function journal_check_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
//First the course data
|
||||
$info[0][0] = get_string("modulenameplural","journal");
|
||||
if ($ids = journal_ids ($course)) {
|
||||
|
@ -26,12 +26,12 @@
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
function pgassignment_backup_mods($course,$user_data=false) {
|
||||
function pgassignment_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
print "hola";
|
||||
}
|
||||
|
||||
////Return an array of info (name,value)
|
||||
function pgassignment_check_backup_mods($course,$user_data=false) {
|
||||
function pgassignment_check_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
//First the course data
|
||||
$info[0][0] = get_string("modulenameplural","pgassignment");
|
||||
if ($ids = pgassignment_ids ($course)) {
|
||||
|
@ -48,12 +48,18 @@
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
function quiz_backup_mods() {
|
||||
//THIS MOD BACKUP NEEDS TO USE THE mdl_backup_ids TABLE
|
||||
|
||||
function quiz_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
print "hola";
|
||||
}
|
||||
|
||||
////Return an array of info (name,value)
|
||||
function quiz_check_backup_mods($course,$user_data=false) {
|
||||
function quiz_check_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
//Deletes data from mdl_backup_ids (categories section)
|
||||
delete_category_ids ($backup_unique_code);
|
||||
//Create date into mdl_backup_ids (categories section)
|
||||
insert_category_ids ($course,$backup_unique_code);
|
||||
//First the course data
|
||||
$info[0][0] = get_string("modulenameplural","quiz");
|
||||
if ($ids = quiz_ids ($course)) {
|
||||
@ -63,14 +69,14 @@
|
||||
}
|
||||
//Categories
|
||||
$info[1][0] = get_string("categories","quiz");
|
||||
if ($ids = quiz_category_ids_by_course ($course)) {
|
||||
if ($ids = quiz_category_ids_by_backup ($backup_unique_code)) {
|
||||
$info[1][1] = count($ids);
|
||||
} else {
|
||||
$info[1][1] = 0;
|
||||
}
|
||||
//Questions
|
||||
$info[2][0] = get_string("questions","quiz");
|
||||
if ($ids = quiz_question_ids_by_course ($course)) {
|
||||
if ($ids = quiz_question_ids_by_backup ($backup_unique_code)) {
|
||||
$info[2][1] = count($ids);
|
||||
} else {
|
||||
$info[2][1] = 0;
|
||||
@ -108,24 +114,24 @@
|
||||
}
|
||||
|
||||
//Returns an array of categories id
|
||||
function quiz_category_ids_by_course ($course) {
|
||||
function quiz_category_ids_by_backup ($backup_unique_code) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
return get_records_sql ("SELECT a.id, a.course
|
||||
FROM {$CFG->prefix}quiz_categories a
|
||||
WHERE a.course = '$course'");
|
||||
return get_records_sql ("SELECT a.old_id, a.backup_code
|
||||
FROM {$CFG->prefix}backup_ids a
|
||||
WHERE a.backup_code = '$backup_unique_code'");
|
||||
}
|
||||
|
||||
function quiz_question_ids_by_course ($course) {
|
||||
function quiz_question_ids_by_backup ($backup_unique_code) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
return get_records_sql ("SELECT q.id, q.category
|
||||
FROM {$CFG->prefix}quiz_categories a,
|
||||
FROM {$CFG->prefix}backup_ids a,
|
||||
{$CFG->prefix}quiz_questions q
|
||||
WHERE a.course = '$course' and
|
||||
q.category = a.id");
|
||||
WHERE a.backup_code = '$backup_unique_code' and
|
||||
q.category = a.old_id");
|
||||
}
|
||||
|
||||
function quiz_grade_ids_by_course ($course) {
|
||||
|
@ -16,12 +16,12 @@
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
function resource_backup_mods($course,$user_data=false) {
|
||||
function resource_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
print "hola";
|
||||
}
|
||||
|
||||
////Return an array of info (name,value)
|
||||
function resource_check_backup_mods($course,$user_data=false) {
|
||||
function resource_check_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
//First the course data
|
||||
$info[0][0] = get_string("modulenameplural","resource");
|
||||
if ($ids = resource_ids ($course)) {
|
||||
|
@ -27,7 +27,7 @@
|
||||
}
|
||||
|
||||
////Return an array of info (name,value)
|
||||
function survey_check_backup_mods($course,$user_data=false) {
|
||||
function survey_check_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
//First the course data
|
||||
$info[0][0] = get_string("modulenameplural","survey");
|
||||
if ($ids = survey_ids ($course)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user