Your Moodle version

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.
Moodle 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8

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


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 Perry Way
    Fri, Jan 16, 2015, 4:00 AM
    To add to my previous comment, I have a worthy enhancement to make things work right.

    In /admin/tool/mergeusers/lib/mergeusertool.php line 135, if you take this code here:

    $this->sqlListTables = 'SHOW TABLES like "' . $CFG->prefix . '%"';

    and replace it with this:

    $this->sqlListTables = "SHOW FULL TABLES WHERE `Tables_in_moodle` LIKE '" . $CFG->prefix . "%' AND `Table_type` = 'BASE TABLE'";

    it should avoid attempting to set the values of records in views because it filters all views out from the results.

    Once I did this then everything worked nicely!

    Thanks for this tool!

  • Picture of Jordi Pujol-Ahulló
    Fri, Jan 16, 2015, 6:37 AM
    Thanks for the comments and contribution Perry!

    I'm adding this to the github as an issue to be included asap.

    My worries are about the SQL proposed, that it should be tested in all testbeds (mainly mysql, oracle and postgresql).

    Thanks again! Please, keep testing, commenting and contributing!


  • Picture of Arto Nieminen
    Fri, Jan 16, 2015, 5:54 PM

    Could this tool be allowed also for manager role? Managers have access to all other links on Users > Accounts menu anyway. Maybe a new capability?
  • Picture of Nicolas Dunand
    Fri, Jan 16, 2015, 6:02 PM

    I imagine we could easily add a specific capability for that, but then of course you would need to be manager at the site level for that.

    What do you think, Jordi?
  • Picture of Jordi Pujol-Ahulló
    Fri, Jan 16, 2015, 7:26 PM

    I like this proposal for the new capacity. However, I need to check it and remember who can see the administration menu or parts of it.

    In the other hand, we should remember that merging a user is a highly critical operation and it should not be available for a broad number and kind of users (in my honest opinion). This is the counterpart that makes me think about the opposite direction (i.e., a new capacity should be not available, and only for site administrators).

    Above all, for the sake of flexibility and a broader adoption, I think we should include a new capability. In particular, two capabilities: one for merging users, and another one to see logs. This way, for forensic uses, it would be very interesting to allow managers to check what happened to a given user.

    If you agree, we could add it as a new issue in the github.

    Thanks for your comments! Always are welcome!

  • Picture of Nicolas Dunand
    Mon, Jan 19, 2015, 10:40 PM
    OK, I just created , to be discussed further.
  • Picture of Jordi Pujol-Ahulló
    Fri, Feb 20, 2015, 6:29 PM
    Hi all!

    We have updated the plugin version to the current last 1.10.1. This is a minor version not including new features, but several solutions for bugs like these ones among others:

    1. Detected new compound indexes.
    2. Added support for mariadb (mysqli) and mssql (sqlsrv) database types.
    3. Revisited sqls to work with sqlsrv and postgresql
    4. Renaming classes and revisited class autoloading for compatibility on upper versions of Moodle.

    Thanks to all of you that contributed in any way, not only for reporting bugs and problems, but also for contributing with a patch to solve them.

    Keep tune in!

  • Picture of Jordi Pujol-Ahulló
    Sat, Feb 21, 2015, 1:25 AM
    Hi all!

    We have updated this plugin to a last release 1.10.2 to solve a bug included in the prior 1.10.1.

    Sorry for that. If you have downloaded the 1.10.1, you have to download the last release 1.10.2.

    Thanks for all your contributions!

  • Picture of Gary Lynch
    Wed, Jun 3, 2015, 10:13 PM
    Is there an update for this to 2.9 in the pipeline?
  • Picture of Jordi Pujol-Ahulló
    Wed, Jun 3, 2015, 11:17 PM

    We will be checking for its compatibility with M2.9 and make it public as soon as possible.

    Thanks for your interest. We will inform it here.

  • Picture of Gary Lynch
    Thu, Jun 4, 2015, 6:14 PM
    Thanks Jordi
    i have tried to use with 2.9 but it throws up an error as follows

    For further reference, these results are recorded in the log id 2.
    Some error occurred:

    Exception thrown when merging: 'Error writing to database".

    #0 /var/www/moodle/lib/dml/pgsql_native_moodle_database.php(244): moodle_database->query_end(false)
    #1 /var/www/moodle/lib/dml/pgsql_native_moodle_database.php(682): pgsql_native_moodle_database->query_end(false)
    #2 /var/www/moodle/admin/tool/mergeusers/lib/table/generictablemerger.php(225): pgsql_native_moodle_database->execute('UPDATE mdl_cour...')
    #3 /var/www/moodle/admin/tool/mergeusers/lib/table/generictablemerger.php(80): GenericTableMerger->updateRecords(Array, Array, 'userid', Array, Array)
    #4 /var/www/moodle/admin/tool/mergeusers/lib/mergeusertool.php(281): GenericTableMerger->merge(Array, Array, Array)
    #5 /var/www/moodle/admin/tool/mergeusers/lib/mergeusertool.php(216): MergeUserTool->_merge('15104', '2202')
    #6 /var/www/moodle/admin/tool/mergeusers/index.php(135): MergeUserTool->merge('15104', '2202')
    #7 {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.

    Hope this helps smile
  • Picture of Jordi Pujol-Ahulló
    Thu, Jun 4, 2015, 10:05 PM

    I created an issue at:

    You can review the resolution status there.

    Remember that we maintain this plugin at our spare time. As soon as possible we get it working on M2.9, I will inform you.

    By the way, could you find and provide us the whole SQL sentence about the "UPDATE mdl_cour..." ? I think you will be able to find it in the log record stated with id 2.

    Thanks in advance!!

  • Picture of Tyreese Davis
    Wed, Oct 7, 2015, 10:25 PM
    Good morning currently using the merge tool on Moodle 2.8, Version Release 1.10.2 (Build: 2015022001)
    Seeing the following
    Exception thrown when merging: 'Error writing to database".
    Exception thrown when merging: 'Error writing to database".
    Duplicate entry '27054-3022-0-0' for key 'mdl_assisubm_assusegroatt_uix'
    #0 /moodle_sand/lib/dml/mysqli_native_moodle_database.php(974): moodle_database->query_end(false)
    #1 /moodle_sand/admin/tool/mergeusers/lib/table/generictablemerger.php(225): mysqli_native_moodle_database->execute('UPDATE mdl_assi...')
    #2 /moodle_sand/admin/tool/mergeusers/lib/table/generictablemerger.php(80): GenericTableMerger->updateRecords(Array, Array, 'userid', Array, Array)
    #3 /moodle_sand/admin/tool/mergeusers/lib/mergeusertool.php(281): GenericTableMerger->merge(Array, Array, Array)
    #4 /moodle_sand/admin/tool/mergeusers/lib/mergeusertool.php(216): MergeUserTool->_merge('3022', '44677')
    #5 /moodle_sand/admin/tool/mergeusers/index.php(135): MergeUserTool->merge('3022', '44677')
    #6 {main}
  • Picture of Mono Lith
    Fri, Nov 6, 2015, 6:29 PM

    This is a very useful tool.

    Looking forward for 2.9 compatibility results!


  • Picture of Anna Krassa
    Wed, Nov 25, 2015, 4:30 PM
    Hello Nicolas and Jordi,

    Thank you very much for this great tool! We use it a lot in our site.

    +1 for Arto's suggestion on setting up the capabilities. I also want to give merging rights to Managers. Of course I share Jordi's worries about safety, but imagine how risky it would be if instead of allowing Managers merge users, we have to change the Manager's role into Admin!

    Plus, I don't know if this is the "default" attribute, but in our site, whenever we merge two users, the account to be removed is not deleted but suspended. Which is also a very good "just in case" solution...

    I have already said in GitHub, that I am not a developer but I am very interested in this feature and I 'll be glad to assist if I can.

    Best wishes,
1 2 3 4
Please login to post comments