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:
2652 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

  • Manieer Chhettri
    Fri, 14 Nov 2014, 10:25 PM
    Hi there,
    I have tried to implement this plugin into my moodle/totara environment. But I stumbled across this error which I just didn't understand. Any ideas:

    Exception thrown when merging: 'Error writing to database".
    Duplicate entry '2-5' for key 'mdl_certcomp_ceruse_uix'
    Trace:
    #0 /home/coloexqc/public_html/totara26/lib/dml/mysqli_native_moodle_database.php(886): moodle_database->query_end(false)
    #1 /home/coloexqc/public_html/totara26/admin/tool/mergeusers/lib/table/generictablemerger.php(225): mysqli_native_moodle_database->execute('UPDATE mdl_cert...')
    #2 /home/coloexqc/public_html/totara26/admin/tool/mergeusers/lib/table/generictablemerger.php(80): GenericTableMerger->updateRecords(Array, Array, 'userid', Array, Array)
    #3 /home/coloexqc/public_html/totara26/admin/tool/mergeusers/lib/mergeusertool.php(277): GenericTableMerger->merge(Array, Array, Array)
    #4 /home/coloexqc/public_html/totara26/admin/tool/mergeusers/lib/mergeusertool.php(212): MergeUserTool->_merge('5', '3')
    #5 /home/coloexqc/public_html/totara26/admin/tool/mergeusers/index.php(135): MergeUserTool->merge('5', '3')
    #6 {main}

    Many thanks,
    M
  • Jordi Pujol-Ahulló
    Sat, 15 Nov 2014, 4:37 AM
    Hi Manieer!

    Please, report also the table name related to the index 'mdl_certcomp_ceruse_uix', as well as the columns related in that index.

    By now, compound indexes are managed manually by the plugin settings. With the information I asked you, you will be able to populate an additional setting for your third-party plugin (non-core plugin), with the information I will show you afterwards.

    Thank you for reporting!

    Jordi
  • Manieer Chhettri
    Sat, 15 Nov 2014, 7:50 AM
    Hi Jordi,
    The table is 'mdl_certif_completion'. Here is what the table looks like at the moment. Its a test site so doesn't have a lot of data. Also I am trying to merge two accounts with id 3(un: student) and id 5(un: student2). I am wanting to merge both accounts by removing id 3 and keeping id 5.

    -- --------------------------------------------------------

    --
    -- Table structure for table `mdl_certif_completion`
    --

    CREATE TABLE IF NOT EXISTS `mdl_certif_completion` (
    `id` bigint(10) NOT NULL AUTO_INCREMENT,
    `certifid` bigint(10) NOT NULL,
    `userid` bigint(10) NOT NULL,
    `certifpath` tinyint(2) NOT NULL,
    `status` tinyint(2) NOT NULL,
    `renewalstatus` tinyint(2) DEFAULT '0',
    `timewindowopens` bigint(10) DEFAULT NULL,
    `timeexpires` bigint(10) DEFAULT NULL,
    `timecompleted` bigint(10) DEFAULT NULL,
    `timemodified` bigint(10) NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `mdl_certcomp_ceruse_uix` (`certifid`,`userid`),
    KEY `mdl_certcomp_cer_ix` (`certifid`),
    KEY `mdl_certcomp_use_ix` (`userid`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Certifications completed' AUTO_INCREMENT=10 ;

    --
    -- Dumping data for table `mdl_certif_completion`
    --

    INSERT INTO `mdl_certif_completion` (`id`, `certifid`, `userid`, `certifpath`, `status`, `renewalstatus`, `timewindowopens`, `timeexpires`, `timecompleted`, `timemodified`) VALUES
    (4, 2, 3, 1, 1, 0, 0, 0, 0, 1406803377),
    (5, 2, 5, 1, 2, 0, 0, 0, 0, 1406804438),
    (6, 2, 6, 1, 1, 0, 0, 0, 0, 1406803378),
    (7, 1, 3, 1, 1, 0, 0, 0, 0, 1406806158),
    (8, 1, 5, 1, 2, 0, 0, 0, 0, 1406883073),
    (9, 1, 6, 1, 1, 0, 0, 0, 0, 1406806159);

    Many thanks,
    M

  • Jordi Pujol-Ahulló
    Mon, 17 Nov 2014, 1:04 AM
    Hi Manieer,

    Let's see, create a file named: MERGEUSERSPLUGIN/config/config.local.php (if you don't have it) and place this code into it:

    ==========================
    return array(
    'compoundindexes' => array(
    'certif_completion' => array(
    'userfield' => 'userid',
    'otherfields' => array('certifid'),
    ),
    ),
    );
    ==========================

    Just to explain, the settings on this file `config/config.local.php` replace/add to default settings on config.php. This way, when you'll update the plugin (whenever necessary) you will not have any conflicts.

    Thanks for your time. Please, confirm us that this works for you.

    Jordi

  • Manieer Chhettri
    Mon, 17 Nov 2014, 5:29 PM
    Hi Jordi,
    Just implemented your code but still facing errors. Here's the error.

    1. Choose users to merge / ▶ 2. Confirm users to merge / ▶ 3. Merging results and log

    Merged «student» (user ID = 3) into «student2» (user ID = 5)

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

    Exception thrown when merging: 'Error writing to database".
    Duplicate entry '5-519' for key 'mdl_courmoducomp_usecou_uix'
    Trace:
    #0 /home/coloexqc/public_html/totara26/lib/dml/mysqli_native_moodle_database.php(886): moodle_database->query_end(false)
    #1 /home/coloexqc/public_html/totara26/admin/tool/mergeusers/lib/table/generictablemerger.php(225): mysqli_native_moodle_database->execute('UPDATE mdl_cour...')
    #2 /home/coloexqc/public_html/totara26/admin/tool/mergeusers/lib/table/generictablemerger.php(80): GenericTableMerger->updateRecords(Array, Array, 'userid', Array, Array)
    #3 /home/coloexqc/public_html/totara26/admin/tool/mergeusers/lib/mergeusertool.php(277): GenericTableMerger->merge(Array, Array, Array)
    #4 /home/coloexqc/public_html/totara26/admin/tool/mergeusers/lib/mergeusertool.php(212): MergeUserTool->_merge('5', '3')
    #5 /home/coloexqc/public_html/totara26/admin/tool/mergeusers/index.php(135): MergeUserTool->merge('5', '3')
    #6 {main}

    The table its referring to is mdl_course_modules_completion

    Regards,
    M

  • Jordi Pujol-Ahulló
    Mon, 17 Nov 2014, 5:49 PM
    Hi Manieer!

    Thanks for reporting and sorry for the inconvenience.

    Please, try this total content in your local.config.php (note that this content also have my last suggestion):

    ===============
    return array(
    'compoundindexes' => array(
    'certif_completion' => array(
    'userfield' => 'userid',
    'otherfields' => array('certifid'),
    ),
    'course_modules_completion' => array(
    'userfield' => 'userid',
    'otherfields' => array('coursemoduleid'),
    ),
    ),
    );
    ===============

    Please, report us again if this works finally.

    Jordi
  • Manieer Chhettri
    Mon, 17 Nov 2014, 8:14 PM
    Hi Jordi, that worked. At least the script ran and there were no errors. Is this some kind of bug or is it just because I was using Moodle with ottar layer. Will you be updating the plugin with this code?

    Just wanted to check before I install it on our live server. I will also keep on sending you any problems I may encounter.

    Thank you for you help and quick response.

    Kind regards,
    M
  • Jordi Pujol-Ahulló
    Mon, 17 Nov 2014, 9:30 PM
    Hi Manieer,

    This is because compound indexes in Moodle tables is maintained manually. We did an effort to detect most common indexes with a user related field, but it was not exhaustive. For instance, the last error was on a Moodle core table, and this must be updated in our plugin. The first one was related to a third-party plugin (I think) related to certificates. Table indexes on third party plugins may be more difficult to detect, since any institution uses a subset of plugins out of all available ones.

    We will update the plugin with these changes. However, you can install this plugin always on a live server and copy this local.config.php file in the config/ directory, and that will work exactly the same way as if these changes where included by default in the default plugin settings. Don't worry about that.

    The next step regarding to this indexes is just to detect them in real time every time you use the tool, so that indexes containing user related fields are dinamically considered without further or manual settings. But this means an important effort and amount of time big grin

    Thanks for reporting, thank you so much!

    Jordi
  • Sebsoft BV
    Tue, 18 Nov 2014, 7:35 PM
    Since scorm is a well-known and often used activity plugin, we'd like to see the following addition to the compund configuration.
    Note: this has been directly taken from our loval configuration.

    return array(
    'compoundindexes' => array(
    'scorm_scoes_track' => array(
    'userfield' => 'userid',
    'otherfields' => array('scormid', 'scoid', 'attempt', 'element'), //mdl_scorscoetrac_usescosco_uix (unique)
    ),
    ),
    );
  • Jordi Pujol-Ahulló
    Tue, 18 Nov 2014, 7:50 PM
    Thank you so much!!

    I reported this into an issue: https://github.com/ndunand/moodle-tool_mergeusers/issues/73

    Thanks!!!
  • Constance Horne
    Thu, 11 Dec 2014, 5:34 AM
    I just uploaded the plugin to admin/tools but my 2.4.0 installation cannot find it to install it. Help is needed, please.
  • Nicolas Dunand
    Thu, 11 Dec 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.
  • Constance Horne
    Thu, 11 Dec 2014, 11:58 PM
    I've been there and there isn't anything to install.
  • Constance Horne
    Fri, 12 Dec 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.
  • Jordi Pujol-Ahulló
    Fri, 12 Dec 2014, 12:49 AM
    Hi!

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

    Our plugin requires Moodle 2.2 (https://docs.moodle.org/dev/Releases#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.

    Jordi
Please login to post comments