";
//Start the main ul
echo "";
//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 == 2) {
echo "- ".get_string("creatingnewcourse");
if (!$status = restore_create_new_course($restore,$course_header)) {
notify("Error while creating the new empty course.");
}
//Print course fullname and shortname and category
if ($status) {
echo "
";
echo "- ".$course_header->course_fullname." (".$course_header->course_shortname.")";
echo "
- ".get_string("category").": ".$course_header->category->name;
echo "
";
//Put the destination course_id
$restore->course_id = $course_header->course_id;
}
} else {
$course = get_record("course","id",$restore->course_id);
if ($course) {
echo " - ".get_string("usingexistingcourse");
echo "
";
echo "- ".get_string("from").": ".$course_header->course_fullname." (".$course_header->course_shortname.")";
echo "
- ".get_string("to").": ".$course->fullname." (".$course->shortname.")";
if (($restore->deleting)) {
echo "
- ".get_string("deletingexistingcoursedata");
} else {
echo "
- ".get_string("addingdatatoexisting");
}
echo "
";
//If we have selected to restore deleting, we do it now.
if ($restore->deleting) {
echo " - ".get_string("deletingolddata");
$status = remove_course_contents($restore->course_id,false) and
delete_dir_contents($CFG->dataroot."/".$restore->course_id,"backupdata");
if ($status) {
//Now , this situation is equivalent to the "restore to new course" one (we
//have a course record and nothing more), so define it as "to new course"
$restore->restoreto = 2;
} else {
notify("An error occurred while deleting some of the course contents.");
}
}
} else {
notify("Error opening existing course.");
$status = false;
}
}
//Now create the course_sections and their associated course_modules
if ($status) {
//Into new course
if ($restore->restoreto == 2) {
echo "
- ".get_string("creatingsections");
if (!$status = restore_create_sections($restore,$xml_file)) {
notify("Error creating sections in the existing course.");
}
//Into existing course
} else if ($restore->restoreto == 0 or $restore->restoreto == 1) {
echo "
- ".get_string("checkingsections");
if (!$status = restore_create_sections($restore,$xml_file)) {
notify("Error creating sections in the existing course.");
}
//Error
} else {
notify("Neither a new course or an existing one was specified.");
$status = false;
}
}
//Now create users as needed
if ($status and ($restore->users == 0 or $restore->users == 1)) {
echo "
- ".get_string("creatingusers")."
";
if (!$status = restore_create_users($restore,$xml_file)) {
notify("Could not restore users.");
}
//Now print info about the work done
if ($status) {
$recs = get_records_sql("select old_id, new_id from {$CFG->prefix}backup_ids
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;
$counter = 0;
//Iterate, filling counters
foreach ($recs as $rec) {
//Get full record, using backup_getids
$record = backup_getid($restore->backup_unique_code,"user",$rec->old_id);
if (strpos($record->info,"new") !== false) {
$new_count++;
}
if (strpos($record->info,"exists") !== false) {
$exists_count++;
}
if (strpos($record->info,"student")) {
$student_count++;
} else if (strpos($record->info,"teacher")) {
$teacher_count++;
} else if (strpos($record->info,"admin")) {
$admin_count++;
} else if (strpos($record->info,"coursecreator")) {
$coursecreator_count++;
} else if ($record->info == "new" or $record->info == "exists") {
$other_count++;
}
//Do some output
$counter++;
if ($counter % 10 == 0) {
echo ".";
if ($counter % 200 == 0) {
echo " ";
}
backup_flush(300);
}
}
//Now print information gathered
echo " (".get_string("new").": ".$new_count.", ".get_string("existing").": ".$exists_count.")";
echo "";
echo "- ".get_string("students").": ".$student_count;
echo "
- ".get_string("teachers").": ".$teacher_count;
echo "
- ".get_string("coursecreators").": ".$coursecreator_count;
echo "
- ".get_string("administrators").": ".$admin_count;
echo "
- ".get_string("other").": ".$other_count;
echo "
";
} else {
notify("Something is wrong - no users were found!");
$status = false;
}
}
}
//Now create categories and questions as needed (STEP1)
if ($status and ($restore->mods[quiz]->restore)) {
echo " - ".get_string("creatingcategoriesandquestions")."
";
if (!$status = restore_create_questions($restore,$xml_file)) {
notify("Could not restore categories and questions!");
}
}
//Now create user_files as needed
if ($status and ($restore->user_files)) {
echo " - ".get_string("copyinguserfiles")."
";
if (!$status = restore_user_files($restore)) {
notify("Could not restore user files!");
}
//If all is ok (and we have a counter)
if ($status and ($status !== true)) {
//Inform about user dirs created from backup
echo "";
echo "- ".get_string("userzones").": ".$status;
echo "
";
}
}
//Now create course files as needed
if ($status and ($restore->course_files)) {
echo " - ".get_string("copyingcoursefiles")."
";
if (!$status = restore_course_files($restore)) {
notify("Could not restore course files!");
}
//If all is ok (and we have a counter)
if ($status and ($status !== true)) {
//Inform about user dirs created from backup
echo "";
echo "- ".get_string("filesfolders").": ".$status;
echo "
";
}
}
//Now create scales as needed
if ($status) {
echo " - ".get_string("creatingscales");
if (!$status = restore_create_scales($restore,$xml_file)) {
notify("Could not restore custom scales!");
}
}
//Now create course modules as needed
if ($status) {
echo "
- ".get_string("creatingcoursemodules");
if (!$status = restore_create_modules($restore,$xml_file)) {
notify("Could not restore custom scales!");
}
}
//Now create log entries as needed
if ($status and ($restore->logs)) {
echo "
- ".get_string("creatinglogentries")."(not implemented!!)";
}
//Now, if all is OK, adjust the instance field in course_modules !!
if ($status) {
echo "
- ".get_string("checkinginstances");
if (!$status = restore_check_instances($restore)) {
notify("Could not adjust instances in course_modules!");
}
}
//Now if all is OK, update:
// - course modinfo field
// - categories table
if ($status) {
echo "
- ".get_string("checkingcourse");
//modinfo field
rebuild_course_cache($restore->course_id);
//categories table
$course = get_record("course","id",$restore->course_id);
fix_course_sortorder($course->category);
}
//Cleanup temps (files and db)
if ($status) {
echo "
- ".get_string("cleaningtempdata");
if (!$status = clean_temp_data ($restore)) {
notify("Could not clean up temporary data from files and database");
}
}
//End the main ul
echo "
";
//End the main table
echo " |
";
echo "