User Restore

Admin tools ::: tool_userrestore
Maintained by Sebsoft Plugins, Rogier van Dongen
The Sebsoft User Restore Plugin offers you the possibility to restore user accounts that were deleted from moodle.
Latest release:
391 sites
64 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 Plugins (Lead maintainer)
Rogier van Dongen: Project leader
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • 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
  • 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
  • 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.
  • Mon, Nov 2, 2020, 6:30 PM
    oops, sorry for words mistakes, wrote it from phone
  • 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
  • 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 ?
  • 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
  • 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?

  • 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
  • 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.
  • Wed, Jun 9, 2021, 7:05 PM
    @David @Erop due to tight schedules and not that much time to work on this, there won't be that much of a short term solution.
    Every now and then I think about tackling this in a different way, but one of the major challenges is that we cannot resolve things without severe impact on processing time.
    The reasons for this are plenty: the log tables in Moodle, especially on MySQL, are notoriously slow due to the huge amount of records.
    This makes JOIN-ing virtually impossible, hence the reason to try and implement some form of caching. However, filling the cache is also tediously slow when there are a substantial amount of users that were marked as deleted.
    We might even end up doing a complete rewrite, implementing a range of ways to use this tool. For our original use cases the tool works flawlessly, but again: when there are 100's or even 100's of deleted users I agree with the process becoming rather unusable. I hope to be able to follow up on this some time soon, but it could take a while.
    Cheers, Rogier
  • Mon, Feb 7, 2022, 7:58 PM
    I have 67 users that i need to restore, but when i run the plugin (full cache refill), it runs for like 30-60 seconds and always get the error "Error reading from database", is there anyway we can resolve this problem?
    thanks in advance
  • Mon, Feb 7, 2022, 8:42 PM
    Hi Tiage,
    That depends on what causes the error. Without information as to why this error occured (you might want to enable full on screen debugging) it could have come from anywhere.
    Having said that; i think this error might be caused by the database layer itself.
    I would advise you to either add a so called "debuguser" to the Moodle config; temporarily enble full debugging mode ("show all errors" and "enable display" so you can see it in your browser).

    I would not be surprised if ultimately the message shown to you would be "MySQL has gone away"; which would be an indication the database server dropped/closed the connection.
    In that case; there's nothing I can do in code (something I already suspect because the process does run but ultimately fails).

    By the way: 67 users isn't that much. What may be more interesting to know because it highly influences the length of the "refill cache" process. How many deleted users does your target systeem have in total?
    Thanks for your answer in advance,
    Cheers
  • Mon, Feb 7, 2022, 10:36 PM
    Hello Rogier
    It is as you said it gives 2 error messages "MySQL server has gone away".
    Its really bad we cannot do anything, i really needed those users back...

    My target system only have 67 deleted users

    Thanks for reply,
    Cheers
  • Tue, Feb 15, 2022, 4:57 PM
    Hi Tiago,
    The only thing I can safely advise you for now is to have your systems administrator increase the timeout for MySQL.
    All cases we've seen with this specific type of error were resolved when the database management system is allowed to run longer.
    I've been wanting to update the process again so it's less prone to crashing due to the database dropping the connection/stopping the query but unfortunately lack the time to do so.
    Because the process dives deep into Moodle's event logs; I'm suspecting your log table might be on the large side (maybe gigantic). The whole issue is within this table and the fact MySQL does not have the best optimisation. Large tables, such as the event logs, therefore might be the cause for long running queries that in turn cause timeouts.
    I'm hoping I can generate some time soon to tackle this less than usable process of filling usercache and add some drop-in "instant query" methods to match userdat based on a selected user, but this also _might_ not be the best approach if any of the search variables for users are deleted through the Moodle user deletion process. In other words: a decent fix may lead to being less able to _search_ in relevant data.
    Cheers
1 2 3
Please login to post comments