Merge user accounts

Reports ::: report_mergeusers
Maintained by Nicolas Dunand
This script will merge two Moodle user accounts, "user A" and "user B". The intent of the script 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.

Merge user accounts 1.1

Moodle 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1
Released: Wednesday, 14 August 2013, 8:06 PM
Merge users script for Moodle 2.x
=================================


This script will merge two Moodle user accounts, "user A" and "user B".
The intent of the script 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. The basic function of the script is to
loop through the tables and update the userid of every record from user A to
user B. This works well for most tables. We do however, have a few special
cases:

Special Case #1: The grade_grades table has a compound unique key on userid
and itemid. This prevents a simple update statement if the two users have
done the same activity. What this script does is determine which activities
have been completed by both users and delete the entry for the old user
from this table. Data is not lost because a duplicate entry can be found in
the grade_grades_history table, which is correctly updated by the regular
processing of the script.

Special Case #2: The user_enrolments table controls which user is enrolled
in which course. Rather than unenroll the old user from the course, this
script simply updates their access to the course to "2" which makes them
completely unable to access the course. To remove these records all
together I recomend disabling or deleting the entire old user account once
the migration has been successful.

Special Case #3: There are 3 logging/preference tables
(user_lastaccess, user_preferences,user_private_key) which exist in
Moodle 2.0. This script is simply skipping these tables since there's no
legitimate purpose to updating the userid value here. This would lead to
duplicate rows for the new user which is silly. Again, if you want to
remove these records I would recommend deleting the old user after this
script runs sucessfully.

BEFORE YOU RUN THIS SCRIPT, BACK UP YOUR DATABASE.
There is no provision in this script for rollbacks, so if something
were to fail midway through you will end up with a half-updated DB.
This. Is. Bad. Practice safe script. Always backup first.


MINIMUM REQUIREMENTS:
- MySQL v5.x or MSSQL or Postgres
- Moodle v2.x

Based on the mergeusers_v2.php script written by Nicolas Dunand.
Updated for Moodle 2.0 by Mike Holzer [m.e.holzer AT gmail DOT com]
Moodle 2.x report by Forrest Gaston
Plugin maintained by Nicolas Dunand [nicolas.dunand AT unil DOT ch]


Version information

Version build number
2013050100
Version release name
1.1
Can be updated from
1.0 (2013010100)
Maturity
Beta
MD5 Sum
c47f31fa9c602e1a1ff3830b8bf62e92
Supported software
PHP 5.3, PHP 5.4, Moodle 2.2, Moodle 2.3, Moodle 2.4, Moodle 2.5, Moodle 2.6, Moodle 2.7, Moodle 2.8, Moodle 2.9, Moodle 3.0, Moodle 3.1
  • Latest release for Moodle 2.2
  • Latest release for Moodle 2.3
  • Latest release for Moodle 2.4
  • Latest release for Moodle 2.5
  • Latest release for Moodle 2.6
  • Latest release for Moodle 2.7
  • Latest release for Moodle 2.8
  • Latest release for Moodle 2.9
  • Latest release for Moodle 3.0
  • Latest release for Moodle 3.1

Version control information

Version control system (VCS)
GIT
VCS repository URL

Default installation instructions for plugins of the type Reports

  1. Make sure you have all the required versions.
  2. Download and unpack the module.
  3. Place the folder (eg "myreport") in the "report" subdirectory.
  4. Visit http://yoursite.com/admin to finish the installation