How To Move Info Fom One Custom User Field To Another?

DRE

Well-known member
Say I have created a facebook custom user field.

People are supposed to put their screen name there.

Well one day I find out that I've accidentally made two facebook custom user fields.

How do I transfer one of the user fields facebook info across the whole site, to the older facebook custom user field?
 
If you want to manually do it for all users then the only way really is by editing the database using SQL queries.

Take a backup first though.
 
I was bored, so I worked up some magic for you. Be sure to make a proper backup and test before using in production!

Code:
/* Create a temporary table with all the bad, less preferred fields */
CREATE TEMPORARY TABLE tmp_xf_user_field_value
SELECT *
FROM xf_user_field_value
WHERE field_id = 'bad_field'
AND field_value != '';
 
ALTER TABLE tmp_xf_user_field_value ADD PRIMARY KEY (user_id);
 
/* Replace bad_field with good_field if it exists */
INSERT INTO tmp_xf_user_field_value
 
SELECT *
FROM xf_user_field_value
WHERE xf_user_field_value.field_id = 'good_field'
AND xf_user_field_value.field_value != ''
 
ON DUPLICATE KEY UPDATE
tmp_xf_user_field_value.field_value = xf_user_field_value.field_value;
 
/* Rename everything to good_field */
UPDATE tmp_xf_user_field_value SET field_id = 'good_field';
 
/* Create or replace existing good_field */
INSERT INTO xf_user_field_value
SELECT * FROM tmp_xf_user_field_value
ON DUPLICATE KEY UPDATE
xf_user_field_value.field_value = tmp_xf_user_field_value.field_value;
 
DROP TABLE tmp_xf_user_field_value;
 
/* Now delete bad_field from XenForo */
 
  • Like
Reactions: DRE
Top Bottom