1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'XenForo Questions and Support' started by DRE, Mar 17, 2013.

  1. DRE

    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?
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    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.
     
  3. Kent

    Kent Active Member

    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 */
     
    DRE likes this.
  4. DRE

    DRE Well-Known Member

  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  6. DRE

    DRE Well-Known Member

  7. Brogan

    Brogan XenForo Moderator Staff Member

    In most cases, if you ask your host they will run the query for you.
     

Share This Page