How to merge users in Confluence?
Asked by Taylor Zavala:

Last night some users were re-named in AD so now the user has two accounts within the user directory (Microsoft AD read only, with Local Groups) in Confluence 4.3.5. Is there a way to merge the old account with the new account? For example, bphillips was renamed to brucephillips in AD. Now, both accounts exist in Confluence's user directory. I would like all the old content associated with the bphillips user to be associated with brucephillips.


Answers:
author: J. Caldwell
body: Take a look at this plugin:

<https://marketplace.atlassian.com/plugins/com.onresolve.confluence.scripting.script-runner>

It is fantastic for Jira, I haven't used it for Confluence before. The rename a user functionality has the option to merge them into another.

comments: author: Gonchik Tsymzhitov
body: I tried but is not work on the Confluence 5.4.3


author: Esther Wien
body: The following is a re-name and migrate method we use for Confluence and JIRA:

Let's say you have a user with the username 'alice' in your local directory. Now you add an LDAP which contains a **NEW** user 'bob' and you want to migrate alice to bob. Follow these steps:

1. Make sure your local directory has priority over the LDAP. (local dir is positioned above the LDAP in the 'User Directories' admin screen)

2. rename 'alice' to 'bob'

3. Move LDAP to have priority over your local directory.

Result: The new 'bob' has taken over all the content of the user previously known as 'alice'.

This method has been tested when migrating from Local to AD and from AD to another AD.

**Warning:** This only works when migrating content to a new user. So far I have not yet been able to merge two existing (active) users with this method. I tested this and it results in the content of the 'lower priority'-user to be of 'Unknown User'.

comments: author: Maximilian Klingmann
body: By far the best answer here!

Used this exact method to merge users from remote LDAP to Crowd.

1. Users were in Confluence via LDAP Directory

2. Added User with same username in Crowd

3. Connected Crowd with Confluence

4. Set LDAP Directory as first prio

5. Synchronized Crowd Users

6. Tested Crowd User Login (dry-run in "User Directories")

7. Moved Crowd to first prio

8. Disabled LDAP

9. Changed Username in Crowd to E-Mail (since we wanted email to be login from now on)

10. Synchronized Crowd Directory again

9. Dance in Joy, as everything the LDAP user edited is now shown to be edited by the Crowd User!


author: Tobias Montagna-Hay
body: I used the SQL commands here to migrate a users activity and content to another user:

<https://gist.github.com/tobiasmh/3e5aa4f7a37d9e834647>

comments: author: Esther Wien
body: Cool, thanks! I had a hard time figuring out where the username was used to register activity. This cleared things up. :)


author: Nicolas Esteves
body: Hello Tobias,Thank you for the link! This would be useful. Did you get some feedbacks about those queries? On which version did you try them?Regards,Nicolas.


author: Tobias Montagna-Hay
body: I ran these on a production Confluence instance running 5.8.4


author: Nicolas Esteves
body: Thank you for your answer.


author: Nicolas Esteves
body: Hello Tobias,In order to avoid some duplicates in the database (and in the user management administration in Confluence), here are some additional queries:delete from cwd_user_attribute where user_id='28311553';delete from cwd_membership where child_user_id='28311553';delete from cwd_user where id ='28311553';Where "28311553" is the ID of the "old" user in the database.Then, this query (provided by Atlassian in this ticket <https://jira.atlassian.com/browse/CONF-30050>) helped me to clean everything that needed to be cleaned :DELETE FROM CONTENTWHERE contentid IN (select \* from (SELECT DISTINCT c1.contentid FROM CONTENT c1 JOIN CONTENT c2 ON c1.username = c2.username WHERE c1.contenttype = 'USERINFO' AND c2.contenttype = 'USERINFO' AND c1.prevver is null AND c2.prevver is null AND c1.contentid \> c2.contentid) as tmp);Note: For MySQL.Nicolas.


author: Patrick Richert
body: And now with recent upgrades, the script runner plugin no longer has merge capabilities. How can we merge user names?


author: Davin Studer
body: 5.3 added the ability to change a user's username, but merging after the fact ... dunno.

comments: author: Gonchik Tsymzhitov
body: Did you resolved this issue?


author: Justin Leader
body: nope


author: Gonchik Tsymzhitov
body: Why?


Tags: confluence-administration