Flaw in the use of setting "import_general_duplicate_admin_allowed"

Flaw in the use of setting "import_general_duplicate_admin_allowed"

by Virgil Ashruf -
Number of replies: 0
I encountered a problem restoring a backup from another site in a target environment when a username from the source already exists in the target environment. The problem occurred to me when trying to restore a dataform preset which uses the backup and restore system. That restoration already has it's own problem that I describe here. This problem is related to the deeper issue of my problems and not dataform specific. The error message is restoreuserconflict.

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 false
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
}
}
occasion 2:
 // 2D - If match by username and mnethost and not by (email or non-zero firstaccess) => conflict, return false
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)
}
My 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.
Average of ratings: -