Moodle  2.2.1
http://www.collinsharper.com
restore_dbops Class Reference
Inheritance diagram for restore_dbops:

Static Public Member Functions

static get_included_tasks ($restoreid)
static load_inforef_to_tempids ($restoreid, $inforeffile)
static load_roles_to_tempids ($restoreid, $rolesfile)
static precheck_included_roles ($restoreid, $courseid, $userid, $samesite, $rolemappings)
static process_included_roles ($restoreid, $courseid, $userid, $samesite, $rolemappings)
static load_users_to_tempids ($restoreid, $usersfile)
static load_categories_and_questions_to_tempids ($restoreid, $questionsfile)
static precheck_categories_and_questions ($restoreid, $courseid, $userid, $samesite)
static prechek_precheck_qbanks_by_level ($restoreid, $courseid, $userid, $samesite, $contextlevel)
static restore_get_question_banks ($restoreid, $contextlevel=null)
static restore_get_question_categories ($restoreid, $contextid)
static restore_find_best_target_context ($categories, $courseid, $contextlevel)
static restore_get_questions ($restoreid, $qcatid)
static send_files_to_pool ($basepath, $restoreid, $component, $filearea, $oldcontextid, $dfltuserid, $itemname=null, $olditemid=null, $forcenewcontextid=null, $skipparentitemidctxmatch=false)
static create_included_users ($basepath, $restoreid, $userfiles, $userid)
static precheck_included_users ($restoreid, $courseid, $userid, $samesite)
static process_included_users ($restoreid, $courseid, $userid, $samesite)
static process_categories_and_questions ($restoreid, $courseid, $userid, $samesite)
static set_backup_files_record ($restoreid, $filerec)
static set_backup_ids_record ($restoreid, $itemname, $itemid, $newitemid=0, $parentitemid=null, $info=null)
static get_backup_ids_record ($restoreid, $itemname, $itemid)
static calculate_course_names ($courseid, $fullname, $shortname)
static set_course_role_names ($restoreid, $courseid)
static create_new_course ($fullname, $shortname, $categoryid)
static delete_course_content ($courseid, array $options=null)

Static Protected Member Functions

static get_best_assignable_role ($role, $courseid, $userid, $samesite)
static precheck_user ($user, $samesite)

Detailed Description

Base abstract class for all the helper classes providing DB operations

TODO: Finish phpdocs

Definition at line 30 of file restore_dbops.class.php.


Member Function Documentation

static calculate_course_names ( courseid,
fullname,
shortname 
) [static]

Given on courseid, fullname and shortname, calculate the correct fullname/shortname to avoid dupes

Definition at line 1272 of file restore_dbops.class.php.

Here is the caller graph for this function:

static create_included_users ( basepath,
restoreid,
userfiles,
userid 
) [static]

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. Also, annotate their newids once created for later reference

Insert the user_custom_profile_field

Definition at line 733 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static create_new_course ( fullname,
shortname,
categoryid 
) [static]

Creates a skeleton record within the database using the passed parameters and returns the new course id.

moodle_database $DB

Parameters:
string$fullname
string$shortname
int$categoryid
Returns:
int The new course id

Definition at line 1336 of file restore_dbops.class.php.

Here is the caller graph for this function:

static delete_course_content ( courseid,
array options = null 
) [static]

Deletes all of the content associated with the given course (courseid)

Parameters:
int$courseid
array$options
Returns:
bool True for success

Definition at line 1364 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static get_backup_ids_record ( restoreid,
itemname,
itemid 
) [static]

Definition at line 1251 of file restore_dbops.class.php.

Here is the caller graph for this function:

static get_best_assignable_role ( role,
courseid,
userid,
samesite 
) [static, protected]

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

Definition at line 159 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static get_included_tasks ( restoreid) [static]

Return one array containing all the tasks that have been included in the restore process. Note that these tasks aren't built (they haven't steps nor ids data available)

Definition at line 37 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static load_categories_and_questions_to_tempids ( restoreid,
questionsfile 
) [static]

Load the needed questions.xml file to backup_ids table for future reference

Definition at line 236 of file restore_dbops.class.php.

Here is the caller graph for this function:

static load_inforef_to_tempids ( restoreid,
inforeffile 
) [static]

Load one inforef.xml file to backup_ids table for future reference

Definition at line 81 of file restore_dbops.class.php.

Here is the caller graph for this function:

static load_roles_to_tempids ( restoreid,
rolesfile 
) [static]

Load the needed role.xml file to backup_ids table for future reference

Definition at line 97 of file restore_dbops.class.php.

Here is the caller graph for this function:

static load_users_to_tempids ( restoreid,
usersfile 
) [static]

Load the needed users.xml file to backup_ids table for future reference

Definition at line 220 of file restore_dbops.class.php.

Here is the caller graph for this function:

static precheck_categories_and_questions ( restoreid,
courseid,
userid,
samesite 
) [static]

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

Definition at line 293 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static precheck_included_roles ( restoreid,
courseid,
userid,
samesite,
rolemappings 
) [static]

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. At the same time, store all the mapping into backup_ids_temp and also put the information into $rolemappings (controller->info), so it can be reworked later by post-precheck stages while at the same time accept modified info in the same object coming from UI

Definition at line 117 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static precheck_included_users ( restoreid,
courseid,
userid,
samesite 
) [static]

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)

Definition at line 1101 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static precheck_user ( user,
samesite 
) [static, protected]

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 () and () 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 - 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 1C - 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 1D - Conflict: If match by username and mnethost and doesn't match by id => conflict, return false 1E - 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: If match by username and mnethost and (email or non-zero firstaccess) => ok, return target user 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()

Definition at line 934 of file restore_dbops.class.php.

Here is the caller graph for this function:

static prechek_precheck_qbanks_by_level ( restoreid,
courseid,
userid,
samesite,
contextlevel 
) [static]

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.

Definition at line 344 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static process_categories_and_questions ( restoreid,
courseid,
userid,
samesite 
) [static]

Process the needed question categories and questions to check all them, deciding about the action to perform (create/map) and target.

Just wrap over precheck_categories_and_questions(), returning exception if any problem is found

Definition at line 1195 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static process_included_roles ( restoreid,
courseid,
userid,
samesite,
rolemappings 
) [static]

Process the loaded roles, looking for their best mapping or skipping Any error will cause exception. Note this is one wrapper over precheck_included_roles, that contains all the logic, but returns errors/warnings instead and is executed as part of the restore prechecks

Definition at line 205 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static process_included_users ( restoreid,
courseid,
userid,
samesite 
) [static]

Process the needed users in order to decide which action to perform with them (create/map)

Just wrap over precheck_included_users(), returning exception if any problem is found

Definition at line 1174 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static restore_find_best_target_context ( categories,
courseid,
contextlevel 
) [static]

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

Definition at line 528 of file restore_dbops.class.php.

Here is the call graph for this function:

static restore_get_question_banks ( restoreid,
contextlevel = null 
) [static]

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

Definition at line 480 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static restore_get_question_categories ( restoreid,
contextid 
) [static]

Return one array of question_category records for a given restore operation and one restore context (question bank)

Definition at line 507 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static restore_get_questions ( restoreid,
qcatid 
) [static]

Return one array of question records for a given restore operation and one question category

Definition at line 605 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static send_files_to_pool ( basepath,
restoreid,
component,
filearea,
oldcontextid,
dfltuserid,
itemname = null,
olditemid = null,
forcenewcontextid = null,
skipparentitemidctxmatch = false 
) [static]

Given one component/filearea/context and optionally one source itemname to match itemids put the corresponding files in the pool

Definition at line 626 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static set_backup_files_record ( restoreid,
filerec 
) [static]

Definition at line 1208 of file restore_dbops.class.php.

Here is the caller graph for this function:

static set_backup_ids_record ( restoreid,
itemname,
itemid,
newitemid = 0,
parentitemid = null,
info = null 
) [static]

Definition at line 1217 of file restore_dbops.class.php.

Here is the caller graph for this function:

static set_course_role_names ( restoreid,
courseid 
) [static]

For the target course context, put as many custom role names as possible

Definition at line 1301 of file restore_dbops.class.php.

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations