2003-05-25 22:58:13 +00:00
|
|
|
<?PHP //$Id$
|
|
|
|
//This page receives the required info and executes the restore
|
|
|
|
//with the parameters suplied. Whe finished, delete temporary
|
|
|
|
//data from backup_tables and temp directory
|
|
|
|
|
|
|
|
//Get objects from session
|
|
|
|
if ($SESSION) {
|
|
|
|
$info = $SESSION->info;
|
|
|
|
$course_header = $SESSION->course_header;
|
|
|
|
$restore = $SESSION->restore;
|
|
|
|
}
|
|
|
|
|
|
|
|
//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-31 15:21:39 +00:00
|
|
|
//Checks for the required files/functions to restore every module
|
|
|
|
//and include them
|
|
|
|
if ($allmods = get_records("modules") ) {
|
|
|
|
foreach ($allmods as $mod) {
|
|
|
|
$modname = $mod->name;
|
2003-08-01 14:34:11 +00:00
|
|
|
$modfile = "$CFG->dirroot/mod/$modname/restorelib.php";
|
2003-05-31 15:21:39 +00:00
|
|
|
//If file exists and we have selected to restore that type of module
|
|
|
|
if ((file_exists($modfile)) and ($restore->mods[$modname]->restore)) {
|
|
|
|
include_once($modfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-25 22:58:13 +00:00
|
|
|
//Start the main table
|
|
|
|
echo "<table cellpadding=5>";
|
|
|
|
echo "<tr><td>";
|
|
|
|
|
|
|
|
//Start the main ul
|
|
|
|
echo "<ul>";
|
|
|
|
|
|
|
|
//Init status
|
|
|
|
$status = true;
|
|
|
|
|
|
|
|
//Localtion of the xml file
|
|
|
|
$xml_file = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code."/moodle.xml";
|
|
|
|
|
|
|
|
//If we've selected to restore into new course
|
|
|
|
//create it (course)
|
|
|
|
//Saving conversion id variables into backup_tables
|
|
|
|
if ($restore->restoreto ==1) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("creatingnewcourse");
|
2003-07-31 16:44:52 +00:00
|
|
|
$status = restore_create_new_course($restore,$course_header);
|
2003-05-25 22:58:13 +00:00
|
|
|
//Print course fullname and shortname and category
|
|
|
|
if ($status) {
|
|
|
|
echo "<ul>";
|
|
|
|
echo "<li>".$course_header->course_fullname." (".$course_header->course_shortname.")";
|
|
|
|
echo "<li>".get_string("category").": ".$course_header->category->name;
|
|
|
|
echo "</ul>";
|
|
|
|
//Put the destination course_id
|
|
|
|
$restore->course_id = $course_header->course_id;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$course = get_record("course","id",$restore->course_id);
|
|
|
|
if ($course) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("usingexistingcourse");
|
2003-05-25 22:58:13 +00:00
|
|
|
echo "<ul>";
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("from").": ".$course_header->course_fullname." (".$course_header->course_shortname.")";
|
|
|
|
echo "<li>".get_string("to").": ".$course->fullname." (".$course->shortname.")";
|
2003-05-25 22:58:13 +00:00
|
|
|
echo "</ul>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Now create the course_sections and their associated course_modules
|
2003-05-28 23:41:56 +00:00
|
|
|
if ($status) {
|
|
|
|
if ($restore->restoreto == 1) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("creatingsections");
|
2003-05-28 23:41:56 +00:00
|
|
|
$status = restore_create_sections($restore,$xml_file);
|
|
|
|
} else if ($restore->restoreto == 0) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("checkingsections");
|
2003-05-28 23:41:56 +00:00
|
|
|
$status = restore_create_sections($restore,$xml_file);
|
|
|
|
} else {
|
|
|
|
$status = false;
|
|
|
|
}
|
2003-05-25 22:58:13 +00:00
|
|
|
}
|
|
|
|
|
2003-05-28 23:41:56 +00:00
|
|
|
|
2003-05-25 22:58:13 +00:00
|
|
|
//Now create users as needed
|
|
|
|
if ($status and ($restore->users == 0 or $restore->users == 1)) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("creatingusers")."<br>";
|
2003-05-25 22:58:13 +00:00
|
|
|
$status = restore_create_users($restore,$xml_file);
|
2003-05-27 22:34:29 +00:00
|
|
|
//Now print info about the work done
|
|
|
|
if ($status) {
|
2003-06-20 19:44:06 +00:00
|
|
|
$recs = get_records_sql("select old_id, new_id from {$CFG->prefix}backup_ids
|
2003-05-27 22:34:29 +00:00
|
|
|
where backup_code = '$restore->backup_unique_code' and
|
|
|
|
table_name = 'user'");
|
|
|
|
//We've records
|
|
|
|
if ($recs) {
|
|
|
|
$new_count = 0;
|
|
|
|
$exists_count = 0;
|
|
|
|
$student_count = 0;
|
|
|
|
$teacher_count = 0;
|
|
|
|
$coursecreator_count = 0;
|
|
|
|
$admin_count = 0;
|
|
|
|
$other_count = 0;
|
2003-07-07 18:46:36 +00:00
|
|
|
$counter = 0;
|
2003-05-27 22:34:29 +00:00
|
|
|
//Iterate, filling counters
|
|
|
|
foreach ($recs as $rec) {
|
2003-06-20 19:44:06 +00:00
|
|
|
//Get full record, using backup_getids
|
|
|
|
$record = backup_getid($restore->backup_unique_code,"user",$rec->old_id);
|
|
|
|
if (strpos($record->info,"new") !== false) {
|
2003-05-27 22:34:29 +00:00
|
|
|
$new_count++;
|
|
|
|
}
|
2003-06-20 19:44:06 +00:00
|
|
|
if (strpos($record->info,"exists") !== false) {
|
2003-05-27 22:34:29 +00:00
|
|
|
$exists_count++;
|
|
|
|
}
|
2003-06-20 19:44:06 +00:00
|
|
|
if (strpos($record->info,"student")) {
|
2003-06-12 17:32:22 +00:00
|
|
|
$student_count++;
|
2003-06-20 19:44:06 +00:00
|
|
|
} else if (strpos($record->info,"teacher")) {
|
2003-06-12 17:32:22 +00:00
|
|
|
$teacher_count++;
|
2003-06-20 19:44:06 +00:00
|
|
|
} else if (strpos($record->info,"admin")) {
|
2003-05-27 22:34:29 +00:00
|
|
|
$admin_count++;
|
2003-06-20 19:44:06 +00:00
|
|
|
} else if (strpos($record->info,"coursecreator")) {
|
2003-05-27 22:34:29 +00:00
|
|
|
$coursecreator_count++;
|
2003-06-20 19:44:06 +00:00
|
|
|
} else if ($record->info == "new" or $record->info == "exists") {
|
2003-05-27 22:34:29 +00:00
|
|
|
$other_count++;
|
|
|
|
}
|
2003-07-07 18:46:36 +00:00
|
|
|
//Do some output
|
|
|
|
$counter++;
|
|
|
|
if ($counter % 10 == 0) {
|
|
|
|
echo ".";
|
|
|
|
if ($counter % 200 == 0) {
|
|
|
|
echo "<br>";
|
|
|
|
}
|
|
|
|
backup_flush(300);
|
|
|
|
}
|
2003-05-27 22:34:29 +00:00
|
|
|
}
|
|
|
|
//Now print information gathered
|
2003-07-28 19:37:37 +00:00
|
|
|
echo " (".get_string("new").": ".$new_count.", ".get_string("existing").": ".$exists_count.")";
|
2003-05-27 22:34:29 +00:00
|
|
|
echo "<ul>";
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("students").": ".$student_count;
|
|
|
|
echo "<li>".get_string("teachers").": ".$teacher_count;
|
|
|
|
echo "<li>".get_string("coursecreators").": ".$coursecreator_count;
|
|
|
|
echo "<li>".get_string("administrators").": ".$admin_count;
|
|
|
|
echo "<li>".get_string("other").": ".$other_count;
|
2003-05-27 22:34:29 +00:00
|
|
|
echo "</ul>";
|
|
|
|
} else {
|
|
|
|
//Something is wrong. There is no users !!
|
|
|
|
$status = false;
|
|
|
|
}
|
|
|
|
}
|
2003-05-25 22:58:13 +00:00
|
|
|
}
|
|
|
|
|
2003-06-28 23:18:37 +00:00
|
|
|
//Now create categories and questions as needed (STEP1)
|
|
|
|
if ($status and ($restore->mods[quiz]->restore)) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("creatingcategoriesandquestions")."<br>";
|
2003-06-28 23:18:37 +00:00
|
|
|
$status = restore_create_questions($restore,$xml_file);
|
|
|
|
}
|
|
|
|
|
2003-05-28 19:43:11 +00:00
|
|
|
//Now create user_files as needed
|
2003-05-27 22:34:29 +00:00
|
|
|
if ($status and ($restore->user_files)) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("copyinguserfiles")."<br>";
|
2003-05-28 19:43:11 +00:00
|
|
|
$status = restore_user_files($restore);
|
|
|
|
//If all is ok (and we have a counter)
|
|
|
|
if ($status and ($status !== true)) {
|
|
|
|
//Inform about user dirs created from backup
|
|
|
|
echo "<ul>";
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("userzones").": ".$status;
|
2003-05-28 19:43:11 +00:00
|
|
|
echo "</ul>";
|
|
|
|
}
|
|
|
|
}
|
2003-05-25 22:58:13 +00:00
|
|
|
|
2003-05-28 19:43:11 +00:00
|
|
|
//Now create course files as needed
|
|
|
|
if ($status and ($restore->course_files)) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("copyingcoursefiles")."<br>";
|
2003-05-28 19:43:11 +00:00
|
|
|
$status = restore_course_files($restore);
|
|
|
|
//If all is ok (and we have a counter)
|
|
|
|
if ($status and ($status !== true)) {
|
|
|
|
//Inform about user dirs created from backup
|
|
|
|
echo "<ul>";
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("filesfolders").": ".$status;
|
2003-05-28 19:43:11 +00:00
|
|
|
echo "</ul>";
|
|
|
|
}
|
2003-05-27 22:34:29 +00:00
|
|
|
}
|
2003-05-25 22:58:13 +00:00
|
|
|
|
2003-05-30 21:32:04 +00:00
|
|
|
//Now create course modules as needed
|
|
|
|
if ($status) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("creatingcoursemodules");
|
2003-05-30 21:32:04 +00:00
|
|
|
$status = restore_create_modules($restore,$xml_file);
|
|
|
|
}
|
|
|
|
|
2003-05-28 19:43:11 +00:00
|
|
|
//Now create log entries as needed
|
|
|
|
if ($status and ($restore->logs)) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("creatinglogentries")."<b>(not implemented!!)</b>";
|
2003-05-28 19:43:11 +00:00
|
|
|
}
|
2003-05-25 22:58:13 +00:00
|
|
|
|
|
|
|
//Now, if all is OK, adjust the instance field in course_modules !!
|
2003-05-31 15:21:39 +00:00
|
|
|
if ($status) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("checkinginstances");
|
2003-05-31 15:21:39 +00:00
|
|
|
$status = restore_check_instances($restore);
|
|
|
|
}
|
2003-05-25 22:58:13 +00:00
|
|
|
|
2003-07-31 18:01:45 +00:00
|
|
|
//Now if all is OK, update:
|
|
|
|
// - course modinfo field
|
|
|
|
// - categories table
|
2003-05-31 15:21:39 +00:00
|
|
|
if ($status) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("checkingcourse");
|
2003-07-31 18:01:45 +00:00
|
|
|
//modinfo field
|
2003-05-31 15:21:39 +00:00
|
|
|
rebuild_course_cache($restore->course_id);
|
2003-07-31 18:01:45 +00:00
|
|
|
//categories table
|
|
|
|
$course = get_record("course","id",$restore->course_id);
|
|
|
|
fix_category_courses($course->category);
|
2003-05-31 15:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Cleanup temps (files and db)
|
2003-06-01 10:40:11 +00:00
|
|
|
if ($status) {
|
2003-07-28 19:37:37 +00:00
|
|
|
echo "<li>".get_string("cleaningtempdata");
|
2003-07-30 16:29:53 +00:00
|
|
|
$status = clean_temp_data ($restore);
|
2003-06-01 10:40:11 +00:00
|
|
|
}
|
2003-05-25 22:58:13 +00:00
|
|
|
|
|
|
|
//End the main ul
|
|
|
|
echo "</ul>";
|
|
|
|
|
|
|
|
|
|
|
|
//End the main table
|
|
|
|
echo "</tr></td>";
|
|
|
|
echo "</table>";
|
|
|
|
|
|
|
|
if (!$status) {
|
|
|
|
error ("An error has ocurred");
|
|
|
|
}
|
|
|
|
|
2003-07-07 18:46:36 +00:00
|
|
|
//Print final message
|
|
|
|
print_simple_box(get_string("restorefinished"),"CENTER");
|
2003-08-01 14:34:11 +00:00
|
|
|
print_continue("$CFG->wwwroot/course/view.php?id=".$restore->course_id);
|
2003-07-07 18:46:36 +00:00
|
|
|
|
2003-05-25 22:58:13 +00:00
|
|
|
?>
|