Hi Werdna,
I've been trying to make my SocialProfile extension support user renaming, which it does not currently. I decided to ask for your help because you added the useful RenameUserSQL hook to SpecialRenameuser_body.php in r55189.
Here's the patch I came up with:
Index: SocialProfile.php =================================================================== --- SocialProfile.php (revision 59581) +++ SocialProfile.php (working copy) @@ -216,4 +216,47 @@ $wgExtNewTables[] = array( 'user_system_messages', "$dir/UserSystemMessages/user_system_messages.sql" ); } return true; +} + +// For Renameuser extension +$wgHooks['RenameUserSQL'][] = 'efSystemGiftsOnUserRename'; +$wgHooks['RenameUserSQL'][] = 'efUserBoardOnUserRename'; +$wgHooks['RenameUserSQL'][] = 'efUserGiftsOnUserRename'; +$wgHooks['RenameUserSQL'][] = 'efUserRelationshipOnUserRename'; +$wgHooks['RenameUserSQL'][] = 'efUserStatsOnUserRename'; +$wgHooks['RenameUserSQL'][] = 'efUserSystemMessagesOnUserRename'; + +function efSystemGiftsOnUserRename( $renameUserSQL ) { + $renameUserSQL->tables['user_system_gift'] = array( 'sg_user_name', 'sg_user_id' ); + return true; +} + +function efUserBoardOnUserRename( $renameUserSQL ) { + $renameUserSQL->tables['user_board'] = array( 'ub_user_name_from', 'ub_user_id_from' ); + return true; +} + +function efUserGiftsOnUserRename( $renameUserSQL ) { + $renameUserSQL->tables['user_gift'] = array( 'ug_user_name_to', 'ug_user_id_to' ); + $renameUserSQL->tables['gift'] = array( 'gift_creator_user_name', 'gift_creator_user_id' ); + return true; +} + +function efUserRelationshipOnUserRename( $renameUserSQL ) { + // <fixme> This sucks and only updates half of the rows...wtf? + $renameUserSQL->tables['user_relationship'] = array( 'r_user_name_relation', 'r_user_id_relation' ); + $renameUserSQL->tables['user_relationship'] = array( 'r_user_name', 'r_user_id' ); + // </fixme> + $renameUserSQL->tables['user_relationship_request'] = array( 'ur_user_name_from', 'ur_user_id_from' ); + return true; +} + +function efUserStatsOnUserRename( $renameUserSQL ) { + $renameUserSQL->tables['user_stats'] = array( 'stats_user_name', 'stats_user_id' ); + return true; +} + +function efUserSystemMessagesOnUserRename( $renameUserSQL ) { + $renameUserSQL->tables['user_system_messages'] = array( 'um_user_name', 'um_user_id' ); + return true; } \ No newline at end of file
As noted in function efUserRelationshipOnUserRename it doesn't work like I'd want it to. All other functions do work as they should, however. Here's some example data (and the table structure of user_relationship table) from my local testing wiki:
CREATE TABLE IF NOT EXISTS `user_relationship` ( `r_id` int(11) NOT NULL AUTO_INCREMENT, `r_user_id` int(5) unsigned NOT NULL DEFAULT '0', `r_user_name` varchar(255) NOT NULL DEFAULT '', `r_user_id_relation` int(5) unsigned NOT NULL DEFAULT '0', `r_user_name_relation` varchar(255) NOT NULL DEFAULT '', `r_type` int(2) DEFAULT NULL, `r_date` datetime DEFAULT NULL, PRIMARY KEY (`r_id`), KEY `r_user_id` (`r_user_id`), KEY `r_user_id_relation` (`r_user_id_relation`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- This signifies that User:Bar (user ID #2) is a friend of User:Foo (user id #1) -- and the other way around INSERT INTO `user_relationship` (`r_id`, `r_user_id`, `r_user_name`, `r_user_id_relation`, `r_user_name_relation`, `r_type`, `r_date`) VALUES (1, 2, 'Bar', 1, 'Foo', 1, '2009-12-03 22:28:33'), (2, 1, 'Foo', 2, 'Bar', 1, '2009-12-03 22:28:33');
When User:Bar is renamed to User:Baz, only one of the above entries is changed from 'Bar' to 'Baz' (can't remember which one) instead of both entries being changed. Is there a way to fix this and if so, how would I fix it?
Thanks in advance for your help!