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

Ability to import into a single site installation #26

Closed nicholasio closed 7 years ago

nicholasio commented 7 years ago

This PR makes it possible to import subsites previously exported with the tool into a single WordPress installation. #25

This is a work in progress, needs more testing:

soderlind commented 7 years ago

Am I doing it wrong,? The single site is not updated

In single site:

git clone -b feature/single-site-import --single-branch   https://github.com/10up/MU-Migration/
wp package install /path/MU-Migration
wp mu-migration import all subsite.zip

wp mu-migration import all subsite.zip --debug gives me:

Debug (bootstrap): No readable global config found (0.014s)
Debug (bootstrap): Using project config: //wp-cli.yml (0.015s)
Debug (bootstrap): Loading packages from: /root/.wp-cli/packages/vendor/autoload.php (0.074s)
Debug (bootstrap): Required file from config: /etc/scripts/wp-cli/fw-local-search-replace.php (0.082s)
Debug (bootstrap): ABSPATH defined: /app/public/ (0.082s)
Debug (bootstrap): Begin WordPress load (0.084s)
Debug (bootstrap): wp-config.php path: /app/public/wp-config.php (0.085s)
Debug (bootstrap): Loaded WordPress (0.496s)
Debug (bootstrap): Running command: mu-migration import all (0.496s)
Extracting zip package...
nicholasio commented 7 years ago

You'll need to install it as a plugin, and run composer install manually, if you install it via package install it will download from master branch.

Sent from my iPhone

On Aug 31, 2017, at 8:42 AM, Per Søderlind notifications@github.com wrote:

Am I doing it wrong,? The single site is not updated

In single site:

git clone -b feature/single-site-import --single-branch https://github.com/10up/MU-Migration/ wp package install /path/MU-Migration wp mu-migration import all subsite.zip wp mu-migration import all subsite.zip --debug gives me:

Debug (bootstrap): No readable global config found (0.014s) Debug (bootstrap): Using project config: //wp-cli.yml (0.015s) Debug (bootstrap): Loading packages from: /root/.wp-cli/packages/vendor/autoload.php (0.074s) Debug (bootstrap): Required file from config: /etc/scripts/wp-cli/fw-local-search-replace.php (0.082s) Debug (bootstrap): ABSPATH defined: /app/public/ (0.082s) Debug (bootstrap): Begin WordPress load (0.084s) Debug (bootstrap): wp-config.php path: /app/public/wp-config.php (0.085s) Debug (bootstrap): Loaded WordPress (0.496s) Debug (bootstrap): Running command: mu-migration import all (0.496s) Extracting zip package... — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

soderlind commented 7 years ago

You're almost there.

Front page looks fine, but it looks like search-replace hasn't been run, all links on front-page points to multisite.dev, wp-login.php redirects to multisite.dev: http://multisite.dev/subsite2/wp-login.php?redirect_to=http%3A%2F%2Fmumigration.dev%2Fwp-admin%2F&reauth=1

soderlind commented 7 years ago

eh .. wait a bit, I used the master branch plugin when I exported the site. Should I this feature branch plugin when I export also ?

nicholasio commented 7 years ago

You should use the feature branch to export and you should also pass the new_url parameter in case you want to change it

Sent from my iPhone

On Aug 31, 2017, at 12:31 PM, Per Søderlind notifications@github.com wrote:

eh .. wait a bit, I used the master branch plugin when I exported the site. Should I this feature branch plugin when I export also ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

nicholasio commented 7 years ago

I've tested this and it looks good to me.

When importing the site, this is what you need: wp mu-migration import all ./subsite.zip --new_url=mumigration.dev

Also make sure to export the subsite using this featured branch.

soderlind commented 7 years ago

--new_url=mumigration.devdid it.

The only errors I've found are:

$ unzip -l subsite.zip | grep uploads
        0  2017-08-31 09:44   wp-content/uploads/2017/08/
   106906  2017-08-31 09:44   wp-content/uploads/2016/12/01_NerverIEnBunt-mp3-image-1024x1024.jpg
   137512  2017-08-31 09:44   wp-content/uploads/2016/12/01_NerverIEnBunt-mp3-image-1200x1200.jpg
     6241  2017-08-31 09:44   wp-content/uploads/2016/12/01_NerverIEnBunt-mp3-image-150x150.jpg
    17547  2017-08-31 09:44   wp-content/uploads/2016/12/01_NerverIEnBunt-mp3-image-300x300.jpg
    69732  2017-08-31 09:44   wp-content/uploads/2016/12/01_NerverIEnBunt-mp3-image-768x768.jpg
   229856  2017-08-31 09:44   wp-content/uploads/2016/12/01_NerverIEnBunt-mp3-image.jpg
  8012144  2017-08-31 09:44   wp-content/uploads/2016/12/01_NerverIEnBunt.mp3
    86203  2017-08-31 09:44   wp-content/uploads/2016/12/06_Ekkoskritt-mp3-image-1024x1024.jpg
   110004  2017-08-31 09:44   wp-content/uploads/2016/12/06_Ekkoskritt-mp3-image-1200x1200.jpg
     5473  2017-08-31 09:44   wp-content/uploads/2016/12/06_Ekkoskritt-mp3-image-150x150.jpg
    14711  2017-08-31 09:44   wp-content/uploads/2016/12/06_Ekkoskritt-mp3-image-300x300.jpg
    56240  2017-08-31 09:44   wp-content/uploads/2016/12/06_Ekkoskritt-mp3-image-768x768.jpg
   187089  2017-08-31 09:44   wp-content/uploads/2016/12/06_Ekkoskritt-mp3-image.jpg
  6873218  2017-08-31 09:44   wp-content/uploads/2016/12/06_Ekkoskritt.mp3
nicholasio commented 7 years ago

I'll take a look at the uploads thing. The user could be just that you already had a user with that email before importing the site. When importing into a single install it does not copy the whole users table as is, instead it adds each user that belongs to the subsite into the single site separately.

nicholasio commented 7 years ago

@soderlind I wasn't able to replicate the uploads issue, you might have a permission problem on your server. I'm merging this PR to master, but feel free to open a new issue if something is not working as expected.

soderlind commented 7 years ago

Works like a charm, thank you :)