During the testing or development times there may be chances when you might have accidentally lost access to your admin account and couldn’t reset it without any means like no forget password (which may not be working on localhost).
It may happen while working around with roles where tempering with admin role will result in no admin account for the site like it happened with Pedro Cruz.
Ken Task as usual comes with his ‘Spirit of Sharing’ with another very great and useful tip through which you can assign admin role to any user without any changes in the database, nothing to restart. All you need to know is the user ID of the account and then you can directly login with that user account in a normal way.
To assign the admin role to any user all you need to change is to add a single line of code in your config.php file and save it. Just add the following:
where 2 is the original admin user established when first installing, and [yourotheradminid] the ID number of the other user you setup as admin levels. The ID number of the other user can be checked in the database table mdl_user (where mdl is your database prefix).
Here is a snapshot of my development Moodle database user table to show where to check out for the ID of a user.After adding the line of code to my config.php file, when I logged in with the standard student account, I was having all admin account priviledges and then I again reset my normal admin account.
Hope this tip also helps you in case of any such emergency. Do you any other tips and tricks which can be helpful in cases of disaster like this? If yes, please share with us in the comments below.