<commit_before><?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!");
    }

    //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;
            $modfile = "$mods_home/$modname/restorelib.php";
            //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);
            }
        }
    }

    //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) {
        echo "<li>Creating new course";
        $status = restore_create_new_course($restore,&$course_header);
        //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) {
            echo "<li>Using existing course"; 
            echo "<ul>";
            echo "<li>From: ".$course_header->course_fullname." (".$course_header->course_shortname.")";
            echo "<li>To: ".$course->fullname." (".$course->shortname.")";
            echo "</ul>";
        }
    }

    //Now create the course_sections and their associated course_modules
    if ($status) {
        if ($restore->restoreto == 1) {
            echo "<li>Creating sections";
            $status = restore_create_sections($restore,$xml_file);
        } else if ($restore->restoreto == 0) {
            echo "<li>Checking sections";
            $status = restore_create_sections($restore,$xml_file);
        } else {
            $status = false;
        }
    }


    //Now create users as needed 
    if ($status and ($restore->users == 0 or $restore->users == 1)) {
        echo "<li>Creating users<br>";
        $status = restore_create_users($restore,$xml_file);
        //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;
                //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++;
                    }
                }
                //Now print information gathered
                echo " (new: ".$new_count.", existing: ".$exists_count.")";
                echo "<ul>";
                echo "<li>Students: ".$student_count;
                echo "<li>Teachers: ".$teacher_count;
                echo "<li>Course Creators: ".$coursecreator_count;
                echo "<li>Admins: ".$admin_count;
                echo "<li>Other: ".$other_count;
                echo "</ul>";
            } else {
                //Something is wrong. There is no users !!
                $status = false;
            }
        }
    }

    //Now create user_files as needed
    if ($status and ($restore->user_files)) {
        echo "<li>Copying User Files";
        $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>";
            echo "<li>User Zones: ".$status;
            echo "</ul>";
        }
    }

    //Now create course files as needed
    if ($status and ($restore->course_files)) {
        echo "<li>Copying Course Files";
        $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>";
            echo "<li>Main Files/Folders: ".$status;
            echo "</ul>";
        }       
    }

    //Now create course modules as needed
    if ($status) {
        echo "<li>Creating Course Modules";
        $status = restore_create_modules($restore,$xml_file);
    }

    














    //Now create log entries as needed
    if ($status and ($restore->logs)) {
        echo "<li>Creating Log Entries <b>(not implemented!!)</b>";
    }    

    //Now, if all is OK, adjust the instance field in course_modules !!
    if ($status) {
        echo "<li>Checking Instances";
        $status = restore_check_instances($restore);
    }

    //Now if all is OK, update course modinfo field !!
    if ($status) {
        echo "<li>Checking Course";
        rebuild_course_cache($restore->course_id);
    }

    //Cleanup temps (files and db)
    if ($status) {
        echo "<li>Cleaning up temp data";
        $status = clean_temp_data ($restore);
    }

    //End the main ul
    echo "</ul>";


    //End the main table     
    echo "</tr></td>";
    echo "</table>";

    if (!$status) {
        error ("An error has ocurred");
    }

?>
<commit_msg>Added some <br>...<commit_after><?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!");
    }

    //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;
            $modfile = "$mods_home/$modname/restorelib.php";
            //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);
            }
        }
    }

    //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) {
        echo "<li>Creating new course";
        $status = restore_create_new_course($restore,&$course_header);
        //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) {
            echo "<li>Using existing course"; 
            echo "<ul>";
            echo "<li>From: ".$course_header->course_fullname." (".$course_header->course_shortname.")";
            echo "<li>To: ".$course->fullname." (".$course->shortname.")";
            echo "</ul>";
        }
    }

    //Now create the course_sections and their associated course_modules
    if ($status) {
        if ($restore->restoreto == 1) {
            echo "<li>Creating sections";
            $status = restore_create_sections($restore,$xml_file);
        } else if ($restore->restoreto == 0) {
            echo "<li>Checking sections";
            $status = restore_create_sections($restore,$xml_file);
        } else {
            $status = false;
        }
    }


    //Now create users as needed 
    if ($status and ($restore->users == 0 or $restore->users == 1)) {
        echo "<li>Creating users<br>";
        $status = restore_create_users($restore,$xml_file);
        //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;
                //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++;
                    }
                }
                //Now print information gathered
                echo " (new: ".$new_count.", existing: ".$exists_count.")";
                echo "<ul>";
                echo "<li>Students: ".$student_count;
                echo "<li>Teachers: ".$teacher_count;
                echo "<li>Course Creators: ".$coursecreator_count;
                echo "<li>Admins: ".$admin_count;
                echo "<li>Other: ".$other_count;
                echo "</ul>";
            } else {
                //Something is wrong. There is no users !!
                $status = false;
            }
        }
    }

    //Now create user_files as needed
    if ($status and ($restore->user_files)) {
        echo "<li>Copying User Files<br>";
        $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>";
            echo "<li>User Zones: ".$status;
            echo "</ul>";
        }
    }

    //Now create course files as needed
    if ($status and ($restore->course_files)) {
        echo "<li>Copying Course Files<br>";
        $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>";
            echo "<li>Main Files/Folders: ".$status;
            echo "</ul>";
        }       
    }

    //Now create course modules as needed
    if ($status) {
        echo "<li>Creating Course Modules";
        $status = restore_create_modules($restore,$xml_file);
    }

    














    //Now create log entries as needed
    if ($status and ($restore->logs)) {
        echo "<li>Creating Log Entries <b>(not implemented!!)</b>";
    }    

    //Now, if all is OK, adjust the instance field in course_modules !!
    if ($status) {
        echo "<li>Checking Instances";
        $status = restore_check_instances($restore);
    }

    //Now if all is OK, update course modinfo field !!
    if ($status) {
        echo "<li>Checking Course";
        rebuild_course_cache($restore->course_id);
    }

    //Cleanup temps (files and db)
    if ($status) {
        echo "<li>Cleaning up temp data";
        $status = clean_temp_data ($restore);
    }

    //End the main ul
    echo "</ul>";


    //End the main table     
    echo "</tr></td>";
    echo "</table>";

    if (!$status) {
        error ("An error has ocurred");
    }

?>

{'fraction_non_alphanumeric': 0.13784126560309726, 'fraction_numerical': 0.0017355316734530405, 'mean_word_length': 1.6849462365591399, 'pattern_counts': {'":': 2, '<': 96, '<?xml version=': 0, '>': 178, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '785855', 'n_tokens_mistral': 4192, 'n_tokens_neox': 4021, 'n_words': 1128}