当你打算合并的外部目录服务器(Crowd 或 Jira 应用)有大量的用户到 Confluence 数据库中的时候,请使用这个选项。你需要有基本的 SQL 知识才能完成这个任务。
下面的 SQL 命令假设你使用的数据库为 MySQL 数据库。如果你使用的数据库不是 MySQL 数据库的话,你需要针对你使用的数据库对你的脚本进行一些修改后才能执行。
第 1 步. 创建备份创建备份是在你对系统进行操作时候出现错误后恢复的唯一办法。
- 从 Confluence 中,你可以创建一个完整的 XML 站点备份包括所有的附件。
- 停止 Confluence。
- 将你服务器上的 Confluence home 和 安装目录中的所有文件和目录拷贝到系统的其他地方备份。
- 针对你的外部应用程序,重复上面的步骤。
- 从你的 MySQL 数据库管理工具中,为 Crowd/Jira 和 Confluence 都创建一个备份。
第 2 步. 替换 Confluence 用户管理使用下面的 SQL 脚本备份外部应用程序中的用户和用户组到 Confluence 表中。下面的脚本是针对 MySQL 数据库设计运行的,如果你使用其他的数据库,你需要对脚本进行修改。
找到你目录使用的 ID
- 运行下面的脚本,然后对返回的结果数进行记录,这个 ID 将会在后面的 参数中引用。
select id from cwd_directory where directory_name=‘Confluence Internal Directory’;
- 针对用户目录关里界面,找到你希望移动的用户,用户组名字。运行下面的脚本,然后对返回的结果数进行记录,这个 ID 将会在后面的 参数中引用。
select id from cwd_directory where directory_name=‘’;
移动用户组到 Confluence
- 在你的内部目录中,外部目录的名字是相同情况是被允许的,希望找到这些名字,请运行下面的脚本:
select distinct a.id, a.directory_id, a.group_name, d.directory_name from cwd_group a join cwd_group b on a.group_name=b.group_name join cwd_directory d on d.id=a.directory_id where a.directory_id != b.directory_id;
- 如果上面的脚本有返回插件结果,针对每一条记录表明的是名字出现了重复,在 Confluence 的内部目录中找到这些重复名字的 ID()和外部应用()。运行下面的脚本:
update cwd_group_attribute set group_id=, directory_id= where group_id=;
update cwd_membership set child_group_id= where child_group_id=;
update cwd_membership set parent_id= where parent_id=;
delete from cwd_group where id=;
- 移动所有外部应用中的所有组到 Confluence 内部目录中。
update cwd_group set directory_id= where directory_id=;
移动用户到 Confluence
- 在内部目录中是允许有多个相同的用户名的,如果这些用户组在不同的外部应用目录中的话。找到这些用户,运行:
select distinct a.id, a.directory_id, a.user_name, d.directory_name from cwd_user a join cwd_user b on a.user_name=b.user_name join cwd_directory d on d.id=a.directory_id where a.directory_id != b.directory_id;
- 如果上面的脚本返回了多条记录的话,表明的是你的系统中有多个用户具有相同的用户名在不同的外部目录中。在 Confluence 的内部目录中找到这些重复名字的 ID(()和外部应用()。运行下面的脚本:
update cwd_membership set child_user_id= where child_user_id=;
update cwd_user_credential_record set user_id= where user_id=;
update cwd_user_attribute set user_id=, directory_id= where user_id=;
delete from cwd_user where id=;
- 移动所有外部应用中的所有用户到 Confluence 内部目录中。
update cwd_user set directory_id= where directory_id=;
删除外部应用目录
-
你需要移动你的系统中的目录顺序,将内部用户目录移动到系统目录列表中的最顶端,然后激活它。
- 如果你仅仅有 2 个目录 - 内部和外部目录的删除可以用下面的脚本:
update cwd_app_dir_mapping set list_index = 0 where directory_id = ;
-
如果你具有超过 2 个的用户目录,你需要将你的内部目录移动到顶部(list_index 0)需要删除的外部目录在这个目录的后面。
- 列出所有用户的排序列表
select d.id, d.directory_name, m.list_index from cwd_directory d join cwd_app_dir_mapping m on d.id=m.directory_id order by m.list_index;
* 修改列表索引,这样这些目录将会按照你希望的顺序进行排序。用户目录的排序可以使用下面的方法进行重排序
update cwd_app_dir_mapping set list_index = where directory_id = ;
-
检查内部目录是否被启用。
- 列出内部目录。一个被激活的目录将会在字段 ‘active’ 中设置为 ‘T’
select id, directory_name, active from cwd_directory where id = ;
* 如果内部目录不是激活的,请激活它
update cwd_directory set active = ‘T’ where id = ;
- 当所有的目录排序是正确的话,从目录列表中删除外部应用目录:
delete from cwd_app_dir_operation where app_dir_mapping_id = (select id from cwd_app_dir_mapping where directory_id = );
delete from cwd_app_dir_mapping where directory_id = ;
- 如果被删除的外部目录在系统中与其他的表有约束的话,你需要根据这些约束从数据库中先删除其他表中的数据:
delete from cwd_directory_attribute where directory_id=;
delete from cwd_directory_operation where directory_id=;
- 所有引用的外部目录现在应该可以从系统中被删除了。使用下面的命令进行删除:
delete from cwd_directory where id = ;
重置密码
- 所有在你删除的外部目录中的用户现在还不能登录系统,包括外部目录的管理员。这些用户需要先重置密码后才能登录系统。你可以通知你的用户使用登录页面的 **忘记你的密码(Forgot your password)**连接重置密码。可选的你可以使用Restore Passwords To Recover Admin User Rights页面的内容重置管理员的密码,然后通过管理员界面中的管理用户选项为你的用户重置密码。