Changing (or Swapping) User IDs

Changing (or Swapping) User IDs

by Daniel Zimmerman -
Number of replies: 1
I am leaving my current workplace, and need to make somebody else the "primary administrator" of my Moodle installation, while still retaining administrative access myself. I've read the threads on changing the primary administrator by changing the user IDs such that the new person has the lowest one; however, I don't know how to non-destructively do that ID change such that the individuals involved keep their associations with courses they were associated with, messages they posted, etc.

Is there a straightforward way of changing a user's ID globally?

(I could go for editing the PHP file to make it so that all admins can assign new admins, or so that only the new primary admin can assign new admins; but then their functionality would break at the next software update...)

Thanks!
Average of ratings: -
In reply to Daniel Zimmerman

Re: Changing (or Swapping) User IDs

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You don't need to change the users ID. You need to change the 'id' value of the mdl_user_admins table. Say you current primary admin user has an ID of '12' in the mdl_user table. If you have a look at the mdl_user_admins table, you'll find a record where the 'userid' field has that '12' value. Incidentally it'll have the lowest value for the 'id' field (always in the mdl_user_admins table).

So all you need to set the primary admin is setting the user you want the lowest 'id' value in that field. Say the new primary admin is a user whose user id is '345'. You'll need to:

  • set the old primary admin a higher id value in the mdl_user_admins table, with something like:

    UPDATE mdl_user_admins SET id='high-value-here' WHERE userid='12';

  • set the new primary admin the lowest id value in the mdl_user_admins table, with something like:

    UPDATE mdl_user_admins SET id='lowest-value-here' WHERE userid='345';

Saludos. Iñaki.