两个Ucenter的合并

提示:本文更新于 5064 天前,技术内容可能已发生变化,仅供参考。

情况是这样的:因为一些历史原因,网站使用了两个互不相关的 Ucenter,一个库名为 Ucenter,版本是 1.0,给 UCHome 使用,另一个库名是 Ucenter2,版本为 1.5,给 Discuz! 7.2 和 Supersite 以及 X-Spaces 使用。现在因为要将所有的应用都升级到 Discuz X 1.5,所以需要先将两个 Ucenter 合并,再进行升级工作。

大概流程

一、解决重名问题

将 UChome 1.0 升级到 1.5 使其版本相同,由于 Ucenter2 更大,故以 Ucenter2 为合并后的主 Ucenter 程序,记录下此时 Ucenter2 的最大用户 uid(这里是 169327),由于检测到 Ucenter 和 Ucenter2 中有少量重名用户(暂无法判断是否为同一用户),于是先在 Ucenter 中重复用户名后添加 _home 以做标记:

-- 查找重名用户
-- SELECT a.`username` FROM `ucenter2`.uc_members a, `ucenter`.uc_members t WHERE a.`username` = t.`username`;

-- 以下更新语句有误,使用最终的正确语句
-- update `ucenter`.uc_members set username=concat(username,+'_home') where (`ucenter`.uc_members.username) in (select username from `ucenter2`.uc_members);

-- 以下更新语句有误,使用最终的正确语句
-- update `ucenter`.uc_members set username=concat(username,+'_home') where (`ucenter`.uc_members.username) in (SELECT a.`username` FROM `ucenter2`.uc_members a, `ucenter_bak`.uc_members t WHERE a.`username` = t.`username`);

-- 查找重复的 uid
-- SELECT 'uid' FROM  `ucenter2`.uc_members WHERE `ucenter2`.uc_members.uid in (SELECT `ucenter2`.uc_members.uid FROM `ucenter2`.uc_members GROUP BY `ucenter2`.uc_members.uid HAVING count(`ucenter2`.uc_members.uid) >1);

-- 创建临时表存储重名用户,以下为最终使用的正确语句
create table `ucenter2`.tmptable as (SELECT a.`username` FROM `ucenter2`.uc_members a, `ucenter`.uc_members t WHERE a.`username` = t.`username`);

-- 根据临时表更新重名用户,以下为最终使用的正确语句
update `ucenter`.uc_members set username=concat(username,'_home') where exists (SELECT username FROM `ucenter2`.tmptable where `ucenter2`.tmptable.username = `ucenter`.uc_members.username);

二、修改 Ucenter 中与 uid 有关的部分

接下来修改 Ucenter 中与 uid 有关的部分,在原来 Uid 的基础上加上 Ucenter2 中 Uid 的最大值(这里是 169327):

-- 修改次 ucenter 的 uid 号码
update `ucenter`.uc_friends set uid=uid+169327,friendid=friendid+169327,version=version+10555 ;
update `ucenter`.uc_members set uid=uid+169327 ;

三、将 ucenter 数据导入 Ucenter2 中

完成 Ucenter 中的相关修改后将 ucenter 数据导入 Ucenter2 中:

-- 将次 ucenter 导入主 ucenter2 中
-- insert ignore into ucenter2.uc_members select * from ucenter_gbk.uc_members;
insert into ucenter2.uc_members select * from `ucenter`.uc_members;
insert into `ucenter2`.uc_friends select * from `ucenter`.uc_friends;

四、修改 Uchome 中与 Uid 有关的部分

接下来修改 Uchome 中与 Uid 有关的部分:

-- 修改 uchome 中的 uid
update `uchome_gbk`.uch_member set uid=uid+169327;
update `uchome_gbk`.uch_userappfield set uid=uid+169327;
update `uchome_gbk`.uch_blogfield set uid=uid+169327;
update `uchome_gbk`.uch_space set uid=uid+169327;
update `uchome_gbk`.uch_comment set uid=uid+169327,authorid=authorid+169327;
update `uchome_gbk`.uch_spacefield set uid=uid+169327;
update `uchome_gbk`.uch_blog set uid=uid+169327;
update `uchome_gbk`.uch_pic set uid=uid+169327;
update `uchome_gbk`.uch_friend set uid=uid+169327,fuid=fuid+169327;
update `uchome_gbk`.uch_spaceinfo set uid=uid+169327;
update `uchome_gbk`.uch_tagspace set uid=uid+169327;
update `uchome_gbk`.uch_poke set uid=uid+169327,fromuid=fromuid+169327;
update `uchome_gbk`.uch_post set uid=uid+169327;
update `uchome_gbk`.uch_feed set uid=uid+169327;
update `uchome_gbk`.uch_creditlog set uid=uid+169327;

update `uchome_gbk`.uch_notification set uid=uid+169327;
update `uchome_gbk`.uch_tag set uid=uid+169327;
update `uchome_gbk`.uch_vote set user_id=user_id+169327;
update `uchome_gbk`.uch_doing set uid=uid+169327;
update `uchome_gbk`.uch_share set uid=uid+169327;

update `uchome_gbk`.uch_sheep set uid=uid+169327;
update `uchome_gbk`.uch_stockmarket set UserID=UserID+169327;
update `uchome_gbk`.uch_thread set uid=uid+169327;

update `uchome_gbk`.uch_docomment set uid=uid+169327;
update `uchome_gbk`.uch_stock_wealthlist set uid=uid+169327;
update `uchome_gbk`.uch_album set uid=uid+169327;
update `uchome_gbk`.uch_usertask set uid=uid+169327;
update `uchome_gbk`.uch_visitor set uid=uid+169327,vuid=vuid+169327;

update `uchome_gbk`.uch_class set uid=uid+169327;
update `uchome_gbk`.uch_userapp set uid=uid+169327;
update `uchome_gbk`.uch_magicinlog set uid=uid+169327;
update `uchome_gbk`.uch_invite set uid=uid+169327;
update `uchome_gbk`.uch_magicuselog set uid=uid+169327;
update `uchome_gbk`.uch_im_config set uid=uid+169327;
update `uchome_gbk`.uch_clickuser set uid=uid+169327;
update `uchome_gbk`.uch_usermagic set uid=uid+169327;

update `uchome_gbk`.uch_poll set uid=uid+169327;
update `uchome_gbk`.uch_eventinvite set uid=uid+169327;
update `uchome_gbk`.uch_mtaginvite set uid=uid+169327,fromuid=fromuid+169327;
update `uchome_gbk`.uch_userevent set uid=uid+169327;
update `uchome_gbk`.uch_show set uid=uid+169327;

update `uchome_gbk`.uch_spacelog set uid=uid+169327;
update `uchome_gbk`.uch_event set uid=uid+169327;
update `uchome_gbk`.uch_topicuser set uid=uid+169327;
update `uchome_gbk`.uch_show set uid=uid+169327;
update `uchome_gbk`.uch_show set uid=uid+169327;

至此,两个 Ucenter 的合并就基本完成了,经过测试,此时 uchome 和 Discuz x 7.2、Supersite、X-Space 已经可以互通,唯一的缺陷是原来 Ucenter 中的用户头像可能会丢失。

五、升级到 Discuz X 1.5

接下来可以用 Discuz 官方提供的所有版本升级到 Discuz X 1.5 程序将所有数据导入到 Discuz x 1.5,其实官方提供的所谓升级工具只是一个数据转换工具,转换之后很多原来应用中的特性都会丢失,比如 X-Space 的用户附件空间、文件空间等,所以请使用的用户注意这一点。

六、合并重复账户

待升级到 Discuz x 1.5 完成之后,可以通过以下方法合并之前账户名重复的帐号:

原账号:Holmesian
UID:7791

计划合并账号:Holmesan_home
UID:188785

UPDATE `ecjtu_discuzx`.`ecjtu_home_friend` SET fuid = '7791' where fuid='188785';
UPDATE `ecjtu_discuzx`.`ecjtu_home_friend` SET uid = '7791' where uid='188785';
UPDATE `ecjtu_discuzx`.`ecjtu_home_blog` SET uid= '7791' where uid='188785';
UPDATE `ecjtu_discuzx`.`ecjtu_home_blogfield` SET uid = '7791' where uid='188785';

「倘若有所帮助,不妨酌情赞赏!」

Holmesian

感谢您的支持!

使用微信扫描二维码赞赏


相关文章

发表新评论