Admin tools: Merge user accounts

Maintained by Picture of Nicolas Dunand Nicolas Dunand, Picture of Jordi Pujol-Ahulló Jordi Pujol-Ahulló
This administration tool will merge two Moodle user accounts into one.
853 sites
40 fans
Moodle 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2

The intent is to assign all activity & records from user A to user B. This will give the effect of user B seeming to have done everything both users have ever done in Moodle.

This tool replaces the old report_mergeusers, which is now obsolete.


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


Picture of Nicolas Dunand
Nicolas Dunand (Lead maintainer): author
Picture of Jordi Pujol-Ahulló
Jordi Pujol-Ahulló: author
Picture of Forrest Gaston
Forrest Gaston: contributor
Mike Holzer
Mike Holzer: contributor
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Petr Khl
    Sat, 2 Sep 2017, 3:16 PM
    Thank you for your plugin, it is really great but something went wrong in our case.
    We are testing it right now before applying to a real system and there is one problem we faced with. It is about forum grades.
    After merging two user accounts it has happend that the user does not have grades for any forum.
    When I started digging into the problem, it turned out that the grades have left in ratings table but not in grade_grades table?

    Can you please help me with this problem? May be I am doing something wrong?
    Serenely, Petr.
  • Picture of Petr Khl
    Sat, 2 Sep 2017, 3:18 PM
    Sorry, forgot to mention that we are using moodle 3.1 and have just moved from 1.9
  • Picture of Jordi Pujol-Ahulló
    Mon, 4 Sep 2017, 2:31 PM

    It may be possible, but this is the first time it was known for us. When you told us about the tables (grades and grade_grades or something like that), would you please explain a bit more about that? Which table was updated and which table was not?

    We dealt about grades on quiz attempts to be updated correspondingly, thanks to a contribution. Maybe this is a particular case to be updated too.

  • Picture of Simon Allison
    Sun, 10 Sep 2017, 5:15 PM
    I'm getting Fatal error: Class '\tool_mergeusers\event\user_merged_success' not found in E:\moodle\admin\tool\mergeusers\lib\mergeusertool.php on line 221

    Moodle 2.5.9 (Build: 20141110)
  • Picture of Jordi Pujol-Ahulló
    Tue, 12 Sep 2017, 2:18 PM
    Hi Simon!

    Thanks for the feedback. There is a point to consider on Moodle, that classes autoloading ( is available only from Moodle 2.6 and on. If you are using the last version of this plugin, this will not work properly. Consider using an older version or using a newer Moodle version.

    Thanks for sharing.

  • Picture of Bruno Tavares
    Wed, 11 Oct 2017, 8:48 PM

    On Moodle 2.6.11+ (build 20150619), either using v1.14.1 and v1.12 of the plugin, I'm getting the following error:

    Coding error detected, it must be fixed by a programmer: level must be specified in init() method of each method

    Debug info:
    Error code: codingerror
    Stack trace:
    line 427 of /lib/classes/event/base.php: coding_exception thrown
    line 489 of /lib/classes/event/base.php: call to core\event\base->validate_before_trigger()
    line 231 of /admin/tool/mergeusers/lib/mergeusertool.php: call to core\event\base->trigger()
    line 135 of /admin/tool/mergeusers/index.php: call to MergeUserTool->merge()

    What other information can I provide, to help getting to the problem's origin?

    Thanks in advance.

    Bruno Tavares
  • Picture of Roland Sherwood
    Fri, 24 Nov 2017, 10:36 AM

    Many thanks for this plugin (which really should be in Moodle core, imo). Unfortunately, we've just tried to merge two users and have hit this error:

    Exception thrown when merging: 'Can not find workshop activity with id 23".

    #0 /var/www/html/moodle/admin/tool/mergeusers/lib/mergeusertool.php(291): MergeUserTool->updateGrades('14592', '5162')
    #1 /var/www/html/moodle/admin/tool/mergeusers/lib/mergeusertool.php(216): MergeUserTool->_merge('14592', '5162')
    #2 /var/www/html/moodle/admin/tool/mergeusers/index.php(135): MergeUserTool->merge('14592', '5162')
    #3 {main}

    Merge failed!
    Your database engine supports transactions. Therefore, the whole current transaction has been rolled back and no modification has been made to your database.

    I've checked within the database and the message is correct about there being no workshop activity with ID 23 (presumably it was deleted at some stage). Do you have any ideas on on how we can proceed?
  • Picture of Jordi Pujol-Ahulló
    Fri, 24 Nov 2017, 3:33 PM

    Thanks for the comments and for giving us feedback.

    The case you show is a bit weird. It's like the course module was deleted but not its related grades (from tables grade_grades and grade_items). This is why the process hangs up.

    Did you proceed the workshop deletion properly?

    Meanhile, if you want to try it out and pass through this incongruence, you could change the line at admin/tool/mergeusers/lib/mergeusertool.php, lines 486 and 489 where there is a "throw new \Exception(...);" for a "continue;", to just omit this grade item.

    Better if you can test in a test instance, prior to run it in production.

    Let us know!

  • Picture of Jordi Pujol-Ahulló
    Tue, 27 Feb 2018, 2:05 AM
    Hi! Several rounds ago, and also for the round of January-July 2018 we are proposing this issue as a MUA project here:

    Looking to see you there and also voting!
  • Picture of Beto de Oliveira
    Tue, 13 Mar 2018, 4:48 AM

    Does the plugin works with external db accounts?
  • Picture of Constance Horne
    Tue, 13 Mar 2018, 4:50 AM
    It merges two users in a moodle database.
  • Picture of Jordi Pujol-Ahulló
    Tue, 13 Mar 2018, 4:06 PM

    Thanks Constance for the reply.

    Hi Beto. This plugin is a Moodle plugin. As such, it only operates on the Moodle database, and not on external databases.

    Thanks to all of you.
  • Renaat
    Wed, 23 May 2018, 9:26 PM
    Moodle 3.5 compatible and no privacy provider?

    As a result the phpunit tests fail:

    provider_testcase::test_all_providers_compliant with data set "tool_mergeusers" ('tool_mergeusers', 'tool_mergeusers\privacy\provider')
    Failed asserting that false is true.


    To re-run:
    vendor/bin/phpunit provider_testcase privacy/tests/provider_test.php
  • Picture of Jordi Pujol-Ahulló
    Wed, 23 May 2018, 11:12 PM
    You're right. Sorry about that. We will check it.
1 2 3 4 5 6 7
Please login to post comments