Non instantiable helper class providing DB support to the @restore_controller.
More...
|
static | apply_config_defaults (restore_controller $controller) |
| Sets the default values for the settings in a restore operation. More...
|
|
static | calculate_course_names ($courseid, $fullname, $shortname) |
| Given on courseid, fullname and shortname, calculate the correct fullname/shortname to avoid dupes.
|
|
static | create_included_users ($basepath, $restoreid, $userid, core\progress\base $progress) |
| Given one restoreid, create in DB all the users present in backup_ids having newitemid = 0, as far as precheck_included_users() have left them there ready to be created. More...
|
|
static moodle_database | create_new_course ($fullname, $shortname, $categoryid) |
| Creates a skeleton record within the database using the passed parameters and returns the new course id. More...
|
|
static | create_restore_temp_tables ($restoreid) |
|
static | delete_course_content ($courseid, array $options=null) |
| Deletes all of the content associated with the given course (courseid) More...
|
|
static | drop_restore_temp_tables ($backupid) |
|
static | get_backup_ids_record ($restoreid, $itemname, $itemid) |
|
static | get_included_tasks ($restoreid) |
| Return one array containing all the tasks that have been included in the restore process. More...
|
|
static | load_categories_and_questions_to_tempids ($restoreid, $questionsfile) |
| Load the needed questions.xml file to backup_ids table for future reference.
|
|
static | load_controller ($restoreid) |
|
static | load_inforef_to_tempids ($restoreid, $inforeffile, core\progress\base $progress=null) |
| Load one inforef.xml file to backup_ids table for future reference. More...
|
|
static | load_roles_to_tempids ($restoreid, $rolesfile) |
| Load the needed role.xml file to backup_ids table for future reference.
|
|
static | load_users_to_tempids ($restoreid, $usersfile, core\progress\base $progress=null) |
| Load the needed users.xml file to backup_ids table for future reference. More...
|
|
static | precheck_categories_and_questions ($restoreid, $courseid, $userid, $samesite) |
| Check all the included categories and questions, deciding the action to perform for each one (mapping / creation) and returning one array of problems in case something is wrong. More...
|
|
static | precheck_included_roles ($restoreid, $courseid, $userid, $samesite, $rolemappings) |
| Precheck the loaded roles, return empty array if everything is ok, and array with 'errors', 'warnings' elements (suitable to be used by restore_prechecks) with any problem found. More...
|
|
static | precheck_included_users ($restoreid, $courseid, $userid, $samesite, core\progress\base $progress) |
| Check all the included users, deciding the action to perform for each one (mapping / creation) and returning one array of problems in case something is wrong (lack of permissions, conficts) More...
|
|
static | prechek_precheck_qbanks_by_level ($restoreid, $courseid, $userid, $samesite, $contextlevel) |
| This function will process all the question banks present in restore at some contextlevel (from CONTEXT_SYSTEM to CONTEXT_MODULE), finding the target contexts where each bank will be restored and returning warnings/errors as needed. More...
|
|
static | process_categories_and_questions ($restoreid, $courseid, $userid, $samesite) |
| Process the needed question categories and questions to check all them, deciding about the action to perform (create/map) and target. More...
|
|
static | process_included_roles ($restoreid, $courseid, $userid, $samesite, $rolemappings) |
| Process the loaded roles, looking for their best mapping or skipping Any error will cause exception. More...
|
|
static | process_included_users ($restoreid, $courseid, $userid, $samesite, core\progress\base $progress=null) |
| Process the needed users in order to decide which action to perform with them (create/map) More...
|
|
static | reset_backup_ids_cached () |
| Reset the ids caches completely. More...
|
|
static | restore_find_best_target_context ($categories, $courseid, $contextlevel) |
| Calculates the best context found to restore one collection of qcats, al them belonging to the same context (question bank), returning the target context found (object) or false.
|
|
static | restore_get_question_banks ($restoreid, $contextlevel=null) |
| Return one array of contextid => contextlevel pairs of question banks to be checked for one given restore operation ordered from CONTEXT_SYSTEM downto CONTEXT_MODULE If contextlevel is specified, then only banks corresponding to that level are returned.
|
|
static | restore_get_question_categories ($restoreid, $contextid) |
| Return one array of question_category records for a given restore operation and one restore context (question bank)
|
|
static | restore_get_questions ($restoreid, $qcatid) |
| Return one array of question records for a given restore operation and one question category.
|
|
static | save_controller ($controller, $checksum, $includeobj=true, $cleanobj=false) |
| Send one restore controller to DB. More...
|
|
static | send_files_to_pool ($basepath, $restoreid, $component, $filearea, $oldcontextid, $dfltuserid, $itemname=null, $olditemid=null, $forcenewcontextid=null, $skipparentitemidctxmatch=false, core\progress\base $progress=null) |
| Given one component/filearea/context and optionally one source itemname to match itemids put the corresponding files in the pool. More...
|
|
static | set_backup_files_record ($restoreid, $filerec) |
|
static | set_backup_ids_record ($restoreid, $itemname, $itemid, $newitemid=0, $parentitemid=null, $info=null) |
|
static | set_course_role_names ($restoreid, $courseid) |
| For the target course context, put as many custom role names as possible.
|
|
|
static | get_backup_ids_cached ($restoreid, $itemname, $itemid) |
| Return cached backup id's. More...
|
|
static | get_best_assignable_role ($role, $courseid, $userid, $samesite) |
| Given one role, as loaded from XML, perform the best possible matching against the assignable roles, using different fallback alternatives (shortname, archetype, editingteacher => teacher, defaultcourseroleid) returning the id of the best matching role or 0 if no match is found.
|
|
static | get_missing_file_result ($file) |
| Returns suitable entry to include in log when there is a missing file. More...
|
|
static | precheck_user ($user, $samesite, $siteid=null) |
| Given one user object (from backup file), perform all the neccesary checks is order to decide how that user will be handled on restore. More...
|
|
static | set_backup_ids_cached ($restoreid, $itemname, $itemid, $extrarecord) |
| Cache backup ids'. More...
|
|
static | update_backup_cached_record ($record, $extrarecord, $key, $existingrecord=null) |
| Updates existing backup record. More...
|
|
Non instantiable helper class providing DB support to the @restore_controller.
This class contains various static methods available for all the DB operations performed by the restore_controller class
TODO: Finish phpdocs
static restore_dbops::precheck_categories_and_questions |
( |
|
$restoreid, |
|
|
|
$courseid, |
|
|
|
$userid, |
|
|
|
$samesite |
|
) |
| |
|
staticinherited |
Check all the included categories and questions, deciding the action to perform for each one (mapping / creation) and returning one array of problems in case something is wrong.
There are some basic rules that the method below will always try to enforce:
Rule1: Targets will be, always, calculated for whole question banks (a.k.a. contexid source), so, given 2 question categories belonging to the same bank, their target bank will be always the same. If not, we can be incurring into "fragmentation", leading to random/cloze problems (qtypes having "child" questions).
Rule2: The 'moodle/question:managecategory' and 'moodle/question:add' capabilities will be checked before creating any category/question respectively and, if the cap is not allowed into upper contexts (system, coursecat)) but in lower ones (course), the whole question bank will be created there.
Rule3: Coursecat question banks not existing in the target site will be created as course (lower ctx) question banks, never as "guessed" coursecat question banks base on depth or so.
Rule4: System question banks will be created at system context if user has perms to do so. Else they will created as course (lower ctx) question banks (similary to rule3). In other words, course ctx if always a fallback for system and coursecat question banks.
Also, there are some notes to clarify the scope of this method:
Note1: This method won't create any question category nor question at all. It simply will calculate which actions (create/map) must be performed for each element and where, validating that all those actions are doable by the user executing the restore operation. Any problem found will be returned in the problems array, causing the restore process to stop with error.
Note2: To decide if one question bank (all its question categories and questions) is going to be remapped, then all the categories and questions must exist in the same target bank. If able to do so, missing qcats and qs will be created (rule2). But if, at the end, something is missing, the whole question bank will be recreated at course ctx (rule1), no matter if that duplicates some categories/questions.
Note3: We'll be using the newitemid column in the temp_ids table to store the action to be performed with each question category and question. newitemid = 0 means the qcat/q needs to be created and any other value means the qcat/q is mapped. Also, for qcats, parentitemid will contain the target context where the categories have to be created (but for module contexts where we'll keep the old one until the activity is created)
Note4: All these "actions" will be "executed" later by restore_create_categories_and_questions
static restore_dbops::precheck_user |
( |
|
$user, |
|
|
|
$samesite, |
|
|
|
$siteid = null |
|
) |
| |
|
staticprotectedinherited |
Given one user object (from backup file), perform all the neccesary checks is order to decide how that user will be handled on restore.
Note the function requires $user->mnethostid to be already calculated so it's caller responsibility to set it
This function is used both by @restore_precheck_users() and @restore_create_users() to get consistent results in both places
It returns:
- one user object (from DB), if match has been found and user will be remapped
- boolean true if the user needs to be created
- boolean false if some conflict happened and the user cannot be handled
Each test is responsible for returning its results and interrupt execution. At the end, boolean true (user needs to be created) will be returned if no test has interrupted that.
Here it's the logic applied, keep it updated:
If restoring users from same site backup: 1A - Normal check: If match by id and username and mnethost => ok, return target user 1B - If restoring an 'anonymous' user (created via the 'Anonymize user information' option) try to find a match by username only => ok, return target user MDL-31484 1C - Handle users deleted in DB and "alive" in backup file: If match by id and mnethost and user is deleted in DB and (match by username LIKE 'backup_email.' or by non empty email = md5(username)) => ok, return target user 1D - Handle users deleted in backup file and "alive" in DB: If match by id and mnethost and user is deleted in backup file and match by email = email_without_time(backup_email) => ok, return target user 1E - Conflict: If match by username and mnethost and doesn't match by id => conflict, return false 1F - None of the above, return true => User needs to be created
if restoring from another site backup (cannot match by id here, replace it by email/firstaccess combination): 2A - Normal check: 2A1 - If match by username and mnethost and (email or non-zero firstaccess) => ok, return target user 2A2 - Exceptional handling (MDL-21912): Match "admin" username. Then, if import_general_duplicate_admin_allowed is enabled, attempt to map the admin user to the user 'admin_[oldsiteid]' if it exists. If not, the user 'admin_[oldsiteid]' will be created in precheck_included users 2B - Handle users deleted in DB and "alive" in backup file: 2B1 - If match by mnethost and user is deleted in DB and not empty email = md5(username) and (username LIKE 'backup_email.' or non-zero firstaccess) => ok, return target user 2B2 - If match by mnethost and user is deleted in DB and username LIKE 'backup_email.' and non-zero firstaccess) => ok, return target user (to cover situations were md5(username) wasn't implemented on delete we requiere both) 2C - Handle users deleted in backup file and "alive" in DB: If match mnethost and user is deleted in backup file and by email = email_without_time(backup_email) and non-zero firstaccess=> ok, return target user 2D - Conflict: If match by username and mnethost and not by (email or non-zero firstaccess) => conflict, return false 2E - None of the above, return true => User needs to be created
Note: for DB deleted users email is stored in username field, hence we are looking there for emails. See delete_user() Note: for DB deleted users md5(username) is stored sometimes in the email field, hence we are looking there for usernames if not empty. See delete_user()
static restore_dbops::prechek_precheck_qbanks_by_level |
( |
|
$restoreid, |
|
|
|
$courseid, |
|
|
|
$userid, |
|
|
|
$samesite, |
|
|
|
$contextlevel |
|
) |
| |
|
staticinherited |
This function will process all the question banks present in restore at some contextlevel (from CONTEXT_SYSTEM to CONTEXT_MODULE), finding the target contexts where each bank will be restored and returning warnings/errors as needed.
Some contextlevels (system, coursecat), will delegate process to course level if any problem is found (lack of permissions, non-matching target context...). Other contextlevels (course, module) will cause return error if some problem is found.
At the end, if no errors were found, all the categories in backup_temp_ids will be pointing (parentitemid) to the target context where they must be created later in the restore process.
Note: at the time these prechecks are executed, activities haven't been created yet so, for CONTEXT_MODULE banks, we keep the old contextid in the parentitemid field. Once the activity (and its context) has been created, we'll update that context in the required qcats
Caller precheck_categories_and_questions will, simply, execute this function for all the contextlevels, acting as a simple controller of warnings and errors.
The function returns 2 arrays, one containing errors and another containing warnings. Both empty if no errors/warnings are found.
- Parameters
-
int | $restoreid | The restore ID |
int | $courseid | The ID of the course |
int | $userid | The id of the user doing the restore |
bool | $samesite | True if restore is to same site |
int | $contextlevel | (CONTEXT_SYSTEM, etc.) |
- Return values
-
array | A separate list of all error and warnings detected |