10up / MU-Migration

This WP-CLI plugin makes the process of moving sites from single WordPress sites to a Multisite instance (or vice-versa) much easier. It exports everything into a zip package which can be used to automatically import it within the desired Multisite installation.
MIT License
329 stars 47 forks source link

Search-replace of uploads paths is innefective when importing from multi-site into single-site #73

Open drebs opened 4 years ago

drebs commented 4 years ago

Describe the bug

If a blog is exported from a multi-site installation without passing --blog_id and then imported into a single-site installation with a --new_url, then the search-replace command for uploads paths does not effectivelly replace wp-content/uploads/sites/$blog_id for wp-content/uploads.

Steps to Reproduce

Export the website from a multi-site installation using exactly the following command line options:

wp mu-migration export all myblog.zip --url=myblog.example.com

Then import it into a single-site installation using exactly the following command line options:

wp mu-migration import all myblog.zip --new_url=example.com/myblog

In our case, we noticed that the logo was not showing up after migration. It so happens that the theme we're using stores logo info in the wp_options table and the path was not replaced at all (note that the URL was replaced correctly):

MariaDB [myblog]> select option_name, option_value from wp_options where option_name = 'theme_mods_morning';
+--------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| option_name        | option_value                                                                                                                                                                                                                                |
+--------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| theme_mods_morning | a:5:{i:0;b:0;s:18:"nav_menu_locations";a:1:{s:7:"primary";i:2;}s:11:"logo_upload";s:71:"https://example.com/myblog/wp-content/uploads/sites/30/2019/10/mama.png";s:10:"search_bar";s:4:"show";s:18:"custom_css_post_id";i:-1;} |
+--------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Expected behavior

Uploads paths should have been replaced correctly throughout the database (and the logo should appear in our blog).

Environment information

Additional context

I did some investigation and I found that:

wpbullet commented 4 years ago

FWIW when I made a script using this amazing package I worked around this with:

wp search-replace "/wp-content/uploads/" "/wp-content/uploads/sites/${SITEID}/" --url=${SITEURL} --report-changed-only