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.

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.




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 Nicolas Dunand
    Thu, Dec 11, 2014, 11:55 PM
    Hi Constance,
    Once the files are copied into admin/tools/mergeusers, you should visit your site's notifications (under Site Administration > Notificatoins). This should take care of installing the tool. The tool will then be visible under Site Administration > Users > Accounts.
  • Picture of Constance Horne
    Thu, Dec 11, 2014, 11:58 PM
    I've been there and there isn't anything to install.
  • Picture of Constance Horne
    Fri, Dec 12, 2014, 12:15 AM
    I installed V2.8.1 on my windows machine and was able to install it by going to site administration => Plugins => Install plugins. But V2.4.0 doesn't have that method. Usually I see an upgrade as soon as I log in as admin which I don't with this one. Is it not compatible with v2.4.0? My actual dev, stage, prod versions are linux, not windows.
  • Picture of Jordi Pujol-Ahulló
    Fri, Dec 12, 2014, 12:49 AM

    It is like Nicalas told you. Just install the plugin as any other plugin.

    Our plugin requires Moodle 2.2 ( so, it should be detected automatically going to Notifications.

    Anyway, just check for "Merge users" option into "Site Administration" -> "Users".

    Operating system should have no effect on that.

  • Picture of Marie-Pierre Dionne
    Thu, Jan 8, 2015, 10:41 PM
    Hello there,

    Our Moodle Partner is having issues with some indexes. Can I foward the error messages and see if you can help fix them? We really like this tool. It is a great innovation for moodle!
  • Picture of Nicolas Dunand
    Thu, Jan 8, 2015, 10:45 PM
    Hi again,
    Okay, please forward the error messages. The best way is to create an issue on GitHub at
  • Picture of Perry Way
    Fri, Jan 16, 2015, 2:26 AM
    Hello, it seems your tool is attempting to update views in addition to tables. I added a print_r($data); line to the function merge() in /admin/tool/mergeusers/lib/table/generictablemerger.php at line 61 to find out where the problem was and it happened on a view that I made in our system to help with some external reporting purposes. Views should be eliminated from this tool's searching. Here is the error message I received on the web page after it failed:

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

    Exception thrown when merging: 'Error reading from database".
    Unknown column 'id' in 'field list'
    #0 C:\Websites\moodle\lib\dml\mysqli_native_moodle_database.php(1014): moodle_database->query_end(false)
    #1 C:\Websites\moodle\admin\tool\mergeusers\lib\table\generictablemerger.php(65): mysqli_native_moodle_database->get_records_sql('SELECT id FROM ...')
    #2 C:\Websites\moodle\admin\tool\mergeusers\lib\mergeusertool.php(277): GenericTableMerger->merge(Array, Array, Array)
    #3 C:\Websites\moodle\admin\tool\mergeusers\lib\mergeusertool.php(212): MergeUserTool->_merge('535', '1331')
    #4 C:\Websites\moodle\admin\tool\mergeusers\index.php(135): MergeUserTool->merge('535', '1331')
    #5 {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.
  • 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!

1 2 3 4
Please login to post comments