Merging dev and beta, users and posts (multisite with buddypress)

I have been building my site on a dev server, while I've had a live site running on another server. Both are multisites, with buddypress. And in the time since I started developing on a different server, new users and posts have been added to the live site.

Now I need to get the users and posts into the new site. I'll refer to the new site as "beta" from here on.

I thought I should do this by cherry picking the right tables in the database, but some things aren't going right.

The subsites have the same IDs on both servers. BuddyPress is network activated, but I also have the BP_ROOT_BLOG defined as a constant in wp-confg as site id=20.

Before I got started with the database, I synchronized the plugins on both sites and updated everything to the latest version.

Using phpMyAdmin, my export settings are to select "custom", leave everything as is except I check the "Add DROP TABLE" option.

I exported from the live site:

- wp_users
- wp_usermeta
- wp_wangguard* (our spam prevention plugin, which involves users)

then imported those tables to the beta site.

then I exported all the wp_20_bp_* tables and wp_options and imported those.

At this point, I realized that my users are all messed up. For example, a recently created test user on the beta site has been merged with a user from the live site. We see her username, and his profile information. It looks like it may have matched up user IDs from the two systems just on the more recent users. The older users seem to be OK. This tells me I might just need to delete all the test users before importing the user tables.

Anyway......I reverted those changes, and tried instead to export/import all the database tables for site 20. But that botched up my theme pretty badly, because the live site is using a different theme.

So I'm looking for advice on the best course of action.

My concerns here are -

- I need all the forum posts to match up with the users who created them.
- I need the users to be assigned to the right BP groups.
- I need all the users from the live site, particularly those created since May.
- I am fine with losing all the test users created since May.

Any advice will be greatly appreciated. I am supposed to have this done by Monday morning (Pacific time).

Thanks in advance!!

  • Luís

    Hi kalico ,

    Hope you're doing well today!

    By description you made and by all the requirements, I think you are following the right procedure. Honestly I never tried that by myself, but I am not seeing by your description what can be wrong (The "users" and "users_meta" table are being imported and all the buddypress tables from the subsite too).

    We have a blog article focused in this matter, that I think it may interest you:

    https://premium.wpmudev.org/blog/improve-wordpress-development-workflow-local-server/

    Josh suggest a tool to sync the database (WP Migrade DB Pro).

    I already pinged one of my teammates from the SLS team, to get their valuable feedback.

    Also, I hope our members can share their experience and bring more suggestions to this conversation.

    Cheers, Luís

  • kalico

    Thank you, Luís I appreciate the confirmation that I'm on the right track. The article was very helpful, and made me think more carefully about how I'm doing this (and how to handle it better in the future).

    I have discovered a couple things that are important here:

    1) The user association with wrong profile data was coming from BP Xprofiles. So I deleted the test users that had been created during development (using the WP user delete tool) and deleted all their created content as well. Then I was able to import the users from the active site without mucking everything up.

    2) The menus have been changed dramatically, and menu data is in the wp_posts table of the db. I'm surprised this isn't causing more problems for people in ongoing development with live sites. I can't seem to find much information about how to deal with it. I went through a lot of trials before deciding that there's really no good way to export my menus. I have used a plugin called Menu Exporter successfully in the past; however it didn't help me today -- probably because of other changes I'd made to the database.

    3) At some time in the past history of my site, BuddyPress was network activated and there was no root blog defined. So there is BP data in every subsite, but it's not all up to date. I eventually discovered that the most up to date content is in the main database (wp_bp_*) not the subsite database (wp_20_bp*) so that is ONE reason why I was getting weird results. I was using database tables that didn't have any current data.

    4) Since topics and replies in BP are "custom post types", they all live in the WP posts table - together with a bunch of content I created on the new site! So updating the forums with new posts turned out to be a surgical procedure.

    I had to export only records >= May 20 with a post_type of "topic" (did those first) and then "reply". After checking my existing db for duplicates and removing them (will have to recreate ones that are important) I was able to import just the recent ones and leave the rest intact. Fortunately, most of them were junk. (I viewed the db in BBedit to find the post IDs and phpMyAdmin to search the beta db.)

    I'm still in the midst of all this, working through things like friends, notifications, etc. I'm doing this all one table at a time, and taking lots of backups as I go.

    It's very tedious, so I'll be looking for ways to avoid this mess as we move forward with the new site. And that takes me back to the article you suggested! :slight_smile: In particular, using WP Migrate DB to keep the MySQL databases in sync will be vitally important to our future workflow.

    Thanks for your input! I'll post back with any other lessons learned, in hopes others might find some useful tips as a result of my situation. :slight_smile:

  • kalico

    One other thing I had to do.....

    I ran all the BuddyPress and Forum tools. In some cases, more than once!

    To anyone else undertaking this task: I highly recommend putting your site into a read-only mode. We have a very low-activity site, but still one person registered while I was working on this. On the weekend, no less! I had to duplicate several tasks after that.

    I put my site in read only mode by disabling registration in Network >> Settings and making some CSS changes using WPMUDEV Multisite Branding plugin.

    I also put a custom message on the login screen (in wp-content/mu-plugins/custom_functions.php), and checked all custom login pages across my site and disabled or wrote text to replace the login forms. Phew!

  • Luís

    Hi kalico ,

    Hope you're doing well today!

    Firstly, sorry for the late reply and all the problems it may have caused.

    After speak with one of my teammates from the SLS team, what can be causing your initial problem is, when you inserts the users from staging to the new site, users gets a new ID, so, maybe it can be messy.

    A suggestion could be:

    1) After fetch the info per user in the old site, you can do:

    $old_site_users = get_users($args);//<-Perhaps use some limit here as it can cause timeout issues
    foreach($old_site_users as $user) {
    
        $user_blogs = get_blogs_of_user( $user_id );
    
        foreach ($user_blogs as $blog) {
            //use $blog->$user_blog->userblog_id;
            //to select posts or cpts and meta...
    
        }
    
        //Here send user info and posts info to new site
    }

    2) In the new site, you should receive the info, insert new usesr and the posts for "user_id";

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.