Admin tools: User Restore

tool_userrestore
Maintained by Picture of Sebsoft PluginsSebsoft Plugins, Picture of Rogier van DongenRogier van Dongen
The Sebsoft User Restore Plugin offers you the possibility to restore user accounts that were deleted from moodle.
349 sites
290 downloads
25 fans
Current versions available: 5

The Sebsoft User Restore Plugin offers you the possibility to restore user accounts that were deleted from moodle.

When the plugin has been installed, you can select a number of user accounts to restore and optionally send an email informing them their accounts have been restored.

This plugin takes the following into account:

  • Users to be restored are checked on e-mail: if an e-mail address already exists for an active account, this user will not be restored.
  • Users to be restored are checked on username: if an username already exists for an active account, this user will not be restored.
  • Users to be restored are checked on MNET host: if the MNET host of the account to be restored is not the locally configured one, this user will not be restored.

Important note

Moodle removes ALL relevant data upon deleting a user account, and only the record in the user table itself remains. This utility can't do anything about this and is only capable of restoring the record from the user table.

Important note for moodle 2.7 and up

Before Moodle 2.7 there is NO way we can retrieve all information. However, with Moodle 2.7 and the new event logging tables, the original user information is stored in the event data. Therefore, from Moodle 2.7 onwards, this plugin will try and restore the original user information from there.

This effectively means, that from Moodle 2.7 onwards, we will have the correct original username, email, idnumber, picture and mnethostid. Before that, only the email could be restored, and even that method is not foolproof (due to the fact the username is cleaned with PARAM_USERNAME upon deletion).

Screenshots

Screenshot #0
Screenshot #1
Screenshot #2
Screenshot #3
Screenshot #4

Contributors

Picture of Sebsoft Plugins
Sebsoft Plugins (Lead maintainer)
Picture of Rogier van Dongen
Rogier van Dongen: Project leader
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Gemma Lesterhuis
    Mon, Oct 21, 2019, 9:23 PM
    I just send an email, it took me awhile to figure out why deleting users took so long until someone pointed this change out.
    This change has a increasing impact on deleting users. You should be aware of a difference between a few seconds up until half an hour depending on the number of users your deleted at the same time. I delete batches of users between the 30 and 2000.
  • Picture of Glen MacPherson
    Thu, Nov 28, 2019, 2:43 AM
    Hi. When I try to restore deleted users, it detects 118 Users to restore, but the username and email fields are blank for all of them, and I get an "error writing to database" if I try to restore one or more of them. Any thoughts?
  • Picture of Rogier van Dongen
    Thu, Dec 5, 2019, 5:55 PM
    Hello Glen,
    I do have an idea, but this would have to be checked before I can be certain this assumption is correct.
    Assuming you run a newer Moodle version, I'm making the assumption Moodle's most recent record in the logstore for any of the deleted users might lack the correct information.
    This would be the information that should be available in the "other" field of the table.
    If you have access to the database you could try and see if my assumption is correct by filtering the logstore under the following conditions:
    component = 'core'
    action= 'deleted'
    target = 'user'
    objectid = Do note you should sort in descending order on the timecreated field of the logstore, then lookat the first record found (i.e. the most recent one for the specific user)

    I have tried to message you from moodle.org's messaging system but I seem to be unable to send you a message at all.
    If you need/want more support, I advice you to contact me directly, you can send me a message on moodle.org if needed so we can go from there.

    ---
    For everyone else reading along: the note Gemma added on Oct 21 is one of the side effects of a rewrite.
    Older version of this plugin worked directly on the logstore table. This caused an gigantic CPU load and in many cases, a timeout when trying to load the overview page.
    The newer version works by hooking in to Moodle's user_deleted event handler, which executes on a per user basis, directly after the user has been deleted.
    To speed up loading the information on the overview pages in this plugin, information is stored in a cache record (which of course is cleaned after a purge).
    While this does speed up the overview pages, it does have the side effect of potentially massively slowing down the process of batch-deleting 100s or 1000s of users.

    As soon as I have the time, I'm willing to look into a solution to resolve this new side effect. However, for the time being I cannot make any promises yet.

    Cheers,
    Rogier
  • Picture of Rogier van Dongen
    Thu, Dec 5, 2019, 5:59 PM
    ^ for the message above: objectid = "ID of the moodle user".
    This information went missing. Apparently this message window cleans out anything resembling HTML tags (would be nice if Moodle would convert this to visible characters instead of completely cleaning it)
  • Picture of Сергей Жирнов
    Tue, Oct 27, 2020, 3:03 PM
    will there be support for moodle 3.9+?
  • Picture of Сергей Жирнов
    Tue, Oct 27, 2020, 3:15 PM
    i did cache refill by CLI script (\tool_userrestore\deletedusercache::fill_cache(true);) because of i have 330 deleted users (LDAP plugin bug), and can't do it in web, so after it was completed, i'm still getting warning message about cache refill. How can i pass that? Moodle 3.9.2
  • Picture of Rogier van Dongen
    Mon, Nov 2, 2020, 6:16 PM
    Hi Сергей Жирнов,
    There's a simple reason for this: the cache refill should fill all deleted users and this warning message (or better said: informative message) is basically telling you there are deleted users that are not in the cache. There's no real way to get around this message for now but I'll see if I can change this for one of the next versions.
    The plugin should work for 3.9 btw (as you already found out); the supported Moodle versions however havent (yet) been updated (or verified for all that matters).
    Cheers, Rogier
  • Picture of Сергей Жирнов
    Mon, Nov 2, 2020, 6:29 PM
    thanks for the reply. I am already tested amd found few bugs, which blocking good parsing. In moodle 3.9 at least we should use json_encode() instead of unserialize() in utils.php. It works for me, but if we using unserialize() we'll get error because in last version we have data like JSON string, not serialized object.
  • Picture of Сергей Жирнов
    Mon, Nov 2, 2020, 6:30 PM
    oops, sorry for words mistakes, wrote it from phone
  • Picture of Rogier van Dongen
    Mon, Nov 2, 2020, 6:47 PM
    Hi Сергей Жирнов, I will try and release a new version as soon as possible. Thanks for the report!
    Cheers, Rogier
  • Picture of Jordan Tomkinson
    Mon, Dec 14, 2020, 5:59 PM
    source control url is broken (404)
    Can you please provide an up to date source control url for Moodle 3.10 ?
  • Picture of Rogier van Dongen
    Thu, Dec 17, 2020, 7:05 PM
    New version is here!
    Checked up to Moodle 3.10.
    Note the following changes:
    - Decoding the event data now takes the JSON format setting of the logstore into account (decoding should hence be transparent no matter what serialisation method is used).
    - user_deleted handler now no longer works by default. It must be enabled to work (reason: see Gemma's comment; bulk deletion is severely impacted)
    - Cache refill can now be done 10 records at the time (apart from the full refill and smart refill that already existed).
    - Added notification indicating the number of missing cache records.

    Source control URL has been fixed (sorry for the massive delays; this year has been messy and chaotic indeed).
    Cheers!
    Rogier
  • Picture of Егор Сибирский
    Fri, Jan 15, 2021, 10:22 AM
    Hi Rogier van Dongen!
    Please, help me, I have about 30,000 accounts, 1464 of them have been deleted. The plugin is installed 3.6.1 (LTS Moodle 3.5), just a week ago the plugin worked and restored users. Now he says fill the cache. I tried to append and full refill the cache, tried it the same way through CLI (--execute = tool_userrestore \ task \ filldeletedcache) I waited for a couple of hours, reinstalled the plugin .... it did not help. I see that the task is starting, but it does nothing, there is no load on the CPU. What else to try?

  • Picture of David Heuring
    Sat, Feb 13, 2021, 11:44 AM
    Same problem - Moodle 3.10.1. Ubuntu 18.04 Plugin 3.6.2 Cache never fills regardless whether full or append. 3,859 total deleted records. Deleted user cache is missing 3149 records/user

    Dave
  • Picture of David Heuring
    Sun, Feb 14, 2021, 1:19 PM
    Okay, it took quite a few time outs before the cache finally filled with the 3,900 deleted users. However, once the restore page showed (39 of them), there is no way to sort any of the columns which renders this virtually unusable, unless I'm missing something. The sequence in each column is totally scrambled so none of this makes any sense. Like I said, maybe I'm missing something or something is wrong with the way my cache filled, but this plugin is essentially not usable, at least for me.
1 2 3
Please login to post comments