User Restore

Administration tool ::: tool_userrestore
Maintained by Sebsoft BV, Rogier van Dongen
The Sebsoft User Restore Plugin offers you the possibility to restore user accounts that were deleted from moodle.
Latest release:
373 sites
93 downloads
29 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

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

Comments RSS

Comments

  • Jarrod Miles
    Wed, 15 Feb 2017, 7:22 PM
    After attempting to load the restore.php page in admin tools in Moodle 2.9.1, it's hung (even after 30 minutes of waiting).
    Seems to be continually cycling through

    SELECT CONCAT(firstname, ' ', lastname) AS deletedby, u.id AS deletedbyid, l.timecreated AS timedeletedby FROM mdl_logstore_standard_log l JOIN mdl_user u ON l.userid=u.id WHERE component = 'core' AND action= 'deleted' AND l.target = 'user' AND l.objectid = 'XXXX' ORDER BY l.timecreated DESC LIMIT 1

    as well another query. There are almost 7000 users on the Moodle.
  • Sebsoft BV
    Thu, 23 Feb 2017, 5:36 AM
    Hi Jarrod,

    This seems to be the query to detect who deleted the user. It might be wiser to disable that field if the tables are too big...
    Did it work in the end?
  • Rogier van Dongen
    Fri, 12 May 2017, 7:44 PM
    New version is here!
    No real changes worth mentioning other than a code overhaul to comply to stricter Moodle Coding Standards.
    Functionality tested up to Moodle 3.3
    On the roadmap (Jarrod Miles, thanks for bringing up this issue): think of a better method of generating the lists for restoring users. Either by pagination or (preferred) a searchbox / user picklist.

    Cheers!
  • Rogier van Dongen
    Mon, 25 Sept 2017, 10:20 PM
    New version is here!
    Changes for Version 3.3.0 (build 2017092500)
    * Fixed deprecated pix_url references (replaced by image_url)
    * Added setting for maximum number of users to display on restore.php / restore form
    * Added paging bar on restore.php
    * Minimum required Moodle version: 3.3

    Cheers!
  • Ricardo Caiado
    Sat, 17 Mar 2018, 10:52 PM
    Hi,

    Any update to Moodle 3.4?

    Ricardo
  • Premi Sivanesan
    Tue, 29 May 2018, 2:59 PM
    Hi there
    I installed the plugin on 3.3 and every time I tried to use it, the Moodle site goes down.
    Any help would be appreciated.

    Premi
  • Christos Savva
    Thu, 30 May 2019, 6:49 PM
    When am trying to access /admin/tool/userrestore/view/restore.php the request times out. I think one of the queries take too long to finish. Is there a way to fix this? Maybe a CLI command?
  • Rogier van Dongen
    Mon, 17 June 2019, 5:16 PM
    New version!
    We've attempted to resolve the issues around timeouts and page load times.
    This means we're now using a caching mechanism, hoping to speed up the process. Please do note the cache must be filled before the restore page can work.
    Do note that caching the deleted user info can be a very lengthy process. If you run into any problems, please send me a note.
    Cheers & good luck!
  • Jinny Watson
    Wed, 19 June 2019, 5:35 PM
    I am really happy to say it’s an interesting tool
  • Gemma Lesterhuis
    Mon, 21 Oct 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.
  • Glen MacPherson
    Thu, 28 Nov 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?
  • Rogier van Dongen
    Thu, 5 Dec 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
  • Rogier van Dongen
    Thu, 5 Dec 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)
  • Сергей Жирнов
    Tue, 27 Oct 2020, 3:03 PM
    will there be support for moodle 3.9+?
  • Сергей Жирнов
    Tue, 27 Oct 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
Please login to post comments