Your Moodle version

Admin tools: Merge user accounts

tool_mergeusers
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.
5k
309
8
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.

Screenshots

Screenshot #0
Screenshot #1
Screenshot #2

Contributors

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 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!
    thanks
  • 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 https://github.com/ndunand/moodle-tool_mergeusers/issues
  • 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'
    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.
  • 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!

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

    Best,

    Jordi
  • Picture of Arto Nieminen
    Fri, Jan 16, 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?
  • Picture of Nicolas Dunand
    Fri, Jan 16, 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?
  • Picture of Jordi Pujol-Ahulló
    Fri, Jan 16, 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
  • Picture of Nicolas Dunand
    Mon, Jan 19, 2015, 10:40 PM
    OK, I just created https://github.com/ndunand/moodle-tool_mergeusers/issues/77 , 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!

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

    Jordi
  • 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
    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
  • 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".

    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
  • Picture of Jordi Pujol-Ahulló
    Thu, Jun 4, 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
1 2 3 4
Please login to post comments