The MU forums have moved to WordPress.org

Problem with blog options after changing MU domain name (6 posts)

  1. benfreefly
    Member
    Posted 17 years ago #

    I've setup 2 extra machines for a client I'm setting up wpmu for. We have had a production server that I'll call domain.com for a while and has all the current data on it. We've now also setup domaindev.com and domainqa.com. I'd like to get the data from the production server onto the dev and qa machines. I dumped the database from production, did a search/replace on the domain names and then imported the changed database onto the dev machine, everything seems to work except for some of the blog options.

    Specifically, any option in the wp_1_options table (also for any other blog id) that originally contained domain.com has now changed to domaindev.com, but the length defined in the option value has not updated and so the get_option function does not return the value as an array.

    As an example, below is the value of a widget_text option on my site in the production domain that would work:

    a:3:{i:1;a:2:{s:5:"title";s:0:"";s:4:"text";s:0:"";}
    s:6:"number";i:2;i:2;a:2:{s:21:"Check out other blogs";s:4:"text";
    s:65:"<ul><li><a href="http://test.domain.com/">Test Blog</a></li></ul>";}}

    After changing the domain to domaindev.com, the length of the last item (defined as 's' before the html the user entered as the widget text) would remain unchanged at 65, causing get_option to return the entire option as a string instead of an array, because the length should actually be 68, i.e.:

    a:3:{i:1;a:2:{s:5:"title";s:0:"";s:4:"text";s:0:"";}
    s:6:"number";i:2;i:2;a:2:{s:21:"Check out other blogs";s:4:"text";
    s:65:"<ul><li><a href="http://test.domaindev.com/">Test Blog</a></li></ul>";}}

    Can anyone think of a good way to go through the options for each blog and update the string lengths for options where the domain name has changed?

    If any of this does not make sense, please let me know and I will try to clarify.

  2. benfreefly
    Member
    Posted 17 years ago #

    OK so after a bunch of searching and experimentation I believe I've found a solution to my problem. I don't have a place to put this so that other people can download it, but it's not that much code so I will post it here for other people that might have this issue when changing domain names.

    READ BEFORE RUNNING THIS CODE!!!

    1) This code assumes that you have a working wpMU install on your new domain name.

    2) This code assumes that you have successfully changed all instances of the old domain name in your database to the new one. How you do this is entirely up to you. I used the following perl command:
    perl -pi -e "s/domain.com/domaindev.com/g" wpmu.sql.changed

    3) BACKUP YOUR DATABASE! Once this code is run, the changes cannot be undone! If it makes your problem worse and you can't go back, don't blame me.

    This code also includes some debugging output so you can see what changes it has made. Suggestions on how to make it better are welcome.

    EDIT: I tried pasting the code, but the forum is stripping out all of the backslashes. If anyone needs a solution to this problem please post here and I will get you the solution somehow. Or perhaps someone can tell me how to paste code without the forums removing the backslashes?

  3. lunabyte
    Member
    Posted 17 years ago #

    Put all code inside of backticks.

    You know, that funny apostrophe looking thing that's (usually) on the key to the left of the 1/! key...

    <?php echo "<tag rel="whatever" />"; ?>
  4. benfreefly
    Member
    Posted 17 years ago #

    Yeah, but putting code in backticks strips out any backslashes when you submit. That's the problem. All my regex and stuff like newline characters comes out wrong.

  5. meballard
    Member
    Posted 16 years ago #

    I would like to get access to your code as I have encountered that exact problem. Could you please email me at mballard@otis.edu ? I could even host the code for others if you want.

  6. raychampagne
    Member
    Posted 15 years ago #

    I know that this is super old, but I'm hoping that either the original author is still around to dole out some replace code - promise I won't ask for any more help than that. We're a pretty technical shop and could probably figure this out on our own, but Id love to not reinvent the wheel here.

About this Topic

  • Started 17 years ago by benfreefly
  • Latest reply from raychampagne