Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/backup/util/dbops/restore_dbops.class.php

    r136 r1331  
    124124        // Set up progress tracking (indeterminate).
    125125        if (!$progress) {
    126             $progress = new \core\progress\null();
     126            $progress = new \core\progress\none();
    127127        }
    128128        $progress->start_progress('Loading inforef.xml file');
     
    431431        // Set up progress tracking (indeterminate).
    432432        if (!$progress) {
    433             $progress = new \core\progress\null();
     433            $progress = new \core\progress\none();
    434434        }
    435435        $progress->start_progress('Loading users into temporary table');
     
    12881288    *
    12891289    *  if restoring from another site backup (cannot match by id here, replace it by email/firstaccess combination):
    1290     *      2A - Normal check: If match by username and mnethost and (email or non-zero firstaccess) => ok, return target user
     1290    *      2A - Normal check:
     1291    *           2A1 - If match by username and mnethost and (email or non-zero firstaccess) => ok, return target user
     1292    *           2A2 - Exceptional handling (MDL-21912): Match "admin" username. Then, if import_general_duplicate_admin_allowed is
     1293    *                 enabled, attempt to map the admin user to the user 'admin_[oldsiteid]' if it exists. If not,
     1294    *                 the user 'admin_[oldsiteid]' will be created in precheck_included users
    12911295    *      2B - Handle users deleted in DB and "alive" in backup file:
    12921296    *           2B1 - If match by mnethost and user is deleted in DB and not empty email = md5(username) and
     
    13061310    *       hence we are looking there for usernames if not empty. See delete_user()
    13071311    */
    1308     protected static function precheck_user($user, $samesite) {
     1312    protected static function precheck_user($user, $samesite, $siteid = null) {
    13091313        global $CFG, $DB;
    13101314
     
    13771381        } else {
    13781382
    1379             // 2A - If match by username and mnethost and
     1383            // 2A1 - If match by username and mnethost and
    13801384            //     (email or non-zero firstaccess) => ok, return target user
    13811385            if ($rec = $DB->get_record_sql("SELECT *
     
    13921396                                           array($user->username, $user->mnethostid, $user->email, $user->firstaccess))) {
    13931397                return $rec; // Matching user found, return it
     1398            }
     1399
     1400            // 2A2 - If we're allowing conflicting admins, attempt to map user to admin_[oldsiteid].
     1401            if (get_config('backup', 'import_general_duplicate_admin_allowed') && $user->username === 'admin' && $siteid
     1402                    && $user->mnethostid == $CFG->mnet_localhost_id) {
     1403                if ($rec = $DB->get_record('user', array('username' => 'admin_' . $siteid))) {
     1404                    return $rec;
     1405                }
    13941406            }
    13951407
     
    15011513        $context = context_course::instance($courseid);
    15021514
     1515        // When conflicting users are detected we may need original site info.
     1516        $restoreinfo = restore_controller_dbops::load_controller($restoreid)->get_info();
     1517
    15031518        // Calculate if we have perms to create users, by checking:
    15041519        // to 'moodle/restore:createuser' and 'moodle/restore:userinfo'
     
    15361551
    15371552            // Now, precheck that user and, based on returned results, annotate action/problem
    1538             $usercheck = self::precheck_user($user, $samesite);
     1553            $usercheck = self::precheck_user($user, $samesite, $restoreinfo->original_site_identifier_hash);
    15391554
    15401555            if (is_object($usercheck)) { // No problem, we have found one user in DB to be mapped to
     
    15431558
    15441559            } else if ($usercheck === false) { // Found conflict, report it as problem
    1545                  $problems[] = get_string('restoreuserconflict', '', $user->username);
     1560                if (!get_config('backup', 'import_general_duplicate_admin_allowed')) {
     1561                    $problems[] = get_string('restoreuserconflict', '', $user->username);
     1562                } else if ($user->username == 'admin') {
     1563                    if (!$cancreateuser) {
     1564                        $problems[] = get_string('restorecannotcreateuser', '', $user->username);
     1565                    }
     1566                    if ($user->mnethostid != $CFG->mnet_localhost_id) {
     1567                        $problems[] = get_string('restoremnethostidmismatch', '', $user->username);
     1568                    }
     1569                    if (!$problems) {
     1570                        // Duplicate admin allowed, append original site idenfitier to username.
     1571                        $user->username .= '_' . $restoreinfo->original_site_identifier_hash;
     1572                        self::set_backup_ids_record($restoreid, 'user', $recuser->itemid, 0, null, (array)$user);
     1573                    }
     1574                }
    15461575
    15471576            } else if ($usercheck === true) { // User needs to be created, check if we are able
Note: See TracChangeset for help on using the changeset viewer.