The error "restoreuserconflict" is only thrown when the usercheck is false and the setting "import_general_duplicate_admin_allowed" isn't set. The setting "import_general_duplicate_admin_allowed" mentions to check for duplicate admins. However the method restore_dbops::precheck_user does not check for admins, only for the existence of duplicate users under different conditions.
The method precheck users can return false in two occasions laid out below. These only check for the existence of the username in the environment and then check whether other information matches.
occasion 1:
// 1E - If match by username and mnethost and doesn't match by id => conflict, return falseoccasion 2:
if ($rec = $DB->get_record('user', array('username'=>$user->username, 'mnethostid'=>$user->mnethostid))) {
if ($user->id != $rec->id) {
return false; // Conflict, username already exists and belongs to another id
}
}
// 2D - If match by username and mnethost and not by (email or non-zero firstaccess) => conflict, return falseMy thought process would be to rework the semantics of the error messages and change the langauge of the setting. However I'm currently out of ideas of what it should be. Only that the problem is very confusing right now and has nothing to do with the existence of administrators in the environment.
if ($rec = $DB->get_record_sql("SELECT *
FROM {user} u
WHERE username = ?
AND mnethostid = ?
AND NOT (
UPPER(email) = UPPER(?)
OR (
firstaccess != 0
AND firstaccess = ?
)
)",
array($user->username, $user->mnethostid, $user->email, $user->firstaccess))) {
return false; // Conflict, username/mnethostid already exist and belong to another user (by email/firstaccess)
}