Merge user accounts

Administration tool ::: tool_mergeusers
Maintained by Jordi Pujol-Ahulló, Nicolas Dunand
This administration tool will merge two Moodle user accounts into one.
Latest release:
2610 sites
3k downloads
89 fans
Current versions available: 6

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.

Help us

We do not give support in the comments section below. For any issue on the plugin, please, refer to GitHub and:

  1. Check if a related issue is already created with the exact detail or similar to the failure you're facing. Add your own experience too. Or
  2. Build a new issue clicking on https://github.com/jpahullo/moodle-tool_mergeusers/issues/new and add the necessary detail to replay the failure or the trace to help you out, and/or
  3. Contribute to the plugin with a PR addressing the problem you're solving.

Help us manage this plugin in a more comfortable way in our spare time by using GitHub. Thanks in advance!

Potential privacy issues

This plugin does not store any personal data.

Screenshots

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

Contributors

Jordi Pujol-Ahulló (Lead maintainer): author
Nicolas Dunand: author
Please login to view contributors details and/or to contact them

Comments RSS

Comments

  • Marie-Pierre Dionne
    Thu, 8 Jan 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!
    thanks
  • Nicolas Dunand
    Thu, 8 Jan 2015, 10:45 PM
    Hi again,
    Okay, please forward the error messages. The best way is to create an issue on GitHub at https://github.com/ndunand/moodle-tool_mergeusers/issues
  • Perry Way
    Fri, 16 Jan 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'
    Trace:
    #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.
  • Perry Way
    Fri, 16 Jan 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!

    Perry
  • Jordi Pujol-Ahulló
    Fri, 16 Jan 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!

    Best,

    Jordi
  • Arto Nieminen
    Fri, 16 Jan 2015, 5:54 PM
    Hi,

    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?
  • Nicolas Dunand
    Fri, 16 Jan 2015, 6:02 PM
    Hi,

    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?
  • Jordi Pujol-Ahulló
    Fri, 16 Jan 2015, 7:26 PM
    Hi!

    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!

    Jordi
  • Nicolas Dunand
    Mon, 19 Jan 2015, 10:40 PM
    OK, I just created https://github.com/ndunand/moodle-tool_mergeusers/issues/77 , to be discussed further.
  • Jordi Pujol-Ahulló
    Fri, 20 Feb 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!

    Jordi
  • Jordi Pujol-Ahulló
    Sat, 21 Feb 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!

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

    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.

    Jordi
  • Gary Lynch
    Thu, 4 Jun 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".

    Trace:
    #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
    Regards
    Gary
  • Jordi Pujol-Ahulló
    Thu, 4 Jun 2015, 10:05 PM
    Hi!

    I created an issue at: https://github.com/ndunand/moodle-tool_mergeusers/issues/102

    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!!

    Jordi
Please login to post comments