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

Importing site does not completely rewrite table data. #57

Closed pkarjala closed 5 years ago

pkarjala commented 6 years ago

Running:

PHP 7.2.10 WP-CLI 2.0.0-alpha-d0fe445

We have a blog that is part of a multisite that I exported, and the export went fine.

When I imported the site into a different multisite install on another server, setting a specific blog_id and new_url option, it did not correctly complete the rewrite, and did not add the site to the wp_blogs table correctly. The intent was to keep the same blog_id, and that there was no blog with this ID on the destination multisite install. Here is the command run (with URL made generic):

user@my-website:/var/www/html$ wp mu-migration import all ~/subsite-2.zip --new_url=my-website.com/program1 --blog_id=2
Extracting zip package...
Importing tables...
Moving files...
Moving Uploads...
Importing Users...
PHP Notice:  Trying to get property 'domain' of non-object in /home/ubuntu/.wp-cli/packages/vendor/10up/mu-migration/includes/helpers.php on line 176
Notice: Trying to get property 'domain' of non-object in /home/ubuntu/.wp-cli/packages/vendor/10up/mu-migration/includes/helpers.php on line 176
[316] Updating posts authors  100% [============================================================================================================================] 0:27 / 0:26Flushing rewrite rules...
Removing temporary files....
Success: All done, your new site is available at http://my-website.com/program1. Remember to flush the cache (memcache, redis etc).

Please note the two PHP Notices, not sure if this affected the import or not. Also, I specified the blog_id in the command run, but there was no existing blog with that ID; not sure if this affected the process or not.

After the import, I can see that the content was correctly set up in the various wp_2_* tables, but it was not added to the wp_blogs table:

mysql> select * from wp_blogs;
+---------+---------+---------------------------+------------------+---------------------+---------------------+--------+----------+--------+------+---------+---------+
| blog_id | site_id | domain                    | path             | registered          | last_updated        | public | archived | mature | spam | deleted | lang_id |
+---------+---------+---------------------------+------------------+---------------------+---------------------+--------+----------+--------+------+---------+---------+
|       1 |       1 | my-website.com| /                | 2018-05-30 09:16:32 | 2018-11-09 01:14:08 |      1 |        0 |      0 |    0 |       0 |       0 |
|       3 |       1 | my-website.com | /program-master/ | 2018-05-30 09:53:06 | 2018-05-30 19:53:15 |      1 |        0 |      0 |    0 |       0 |       0 |
|       4 |       1 | my-website.com | /some-site/           | 2018-06-26 14:37:39 | 2018-11-15 22:52:49 |      1 |        0 |      0 |    0 |       0 |       0 |
|       5 |       1 | my-website.com | /some-other/         | 2018-10-01 09:33:50 | 2018-11-10 02:18:53 |      1 |        0 |      0 |    0 |       0 |       0 |
+---------+---------+---------------------------+------------------+---------------------+---------------------+--------+----------+--------+------+---------+---------+
4 rows in set (0.00 sec)

Additionally, checking the wp_2_options table shows that none of the existing URL strings were rewritten during the import.

|         1 | siteurl | http://dev-site-url.org/program1 | yes |
|         2 | home  | http://dev-site-url.org/program1 | yes |

Is there a step that I'm missing? Does exporting from a Multisite install, and then importing into another Multisite install with this tool work correctly?

Or is it simply the case that if the blog_id option is used, but an existing site does not exist, it will not properly import? If this is so, then it would be useful to halt execution instead of creating all of the tables that will not properly function.

nicholasio commented 5 years ago

The blog_id option for importing is meant to be used only when overriding existing subsites. If you're just importing as a new site you just need to specify the --new_url option.