Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tools to import/export content #3354

Closed
wants to merge 3 commits into from
Closed

Conversation

pbking
Copy link
Contributor

@pbking pbking commented Feb 24, 2021

Changes proposed in this Pull Request:

This change adds tools to import/export content from the local wp-env
instance.

Content can be pulled from your sandbox, themedemo.wordpress.com or from
the theme-unit-test repository.

The sandbox.sh script was changed to power the "export" (from sandbox or
themedemo) functionality.

The .wp-env.json was changed to supply the content from theme-unit-test
repository, map local folders for import/export of the rest of the
resources and to provide the import plugin.

npm scripts have been added to package.json in order to drive the
commands.

Documentation in readme has been updated to reflect the additional
capabilities.

Testing

Theam and Sandbox content export

From the root of the project run npm run wp-env:export:theam (or ./sandbox.sh export-theam) and note the file copied to ./export/theamdemo.wordpress.xml reflects the content on theamdemo.wordpress.com

From the root of the project run npm run wp-env:export:sandbox (or ./sandbox.sh export) and note the file copied to ./export/sandbox.wordpress.xml reflects the content on your sandbox

NOTE: The following will remove & replace all of the content in the targeted instance of WordPress. Make sure you don't mind it going away.

Make sure there are no instances of wp-env running. (Checking Docker Dashboard is helpful for this just to make sure...)

Spin up a new wp-env instance from the root of the project folder: npm run wp-env and ensure that it's running properly: http://localhost:8888

Run npm run wp-env:empty and ensure that there is no content to be found on our local wp-env instance

Run npm run wp-env:import:sandbox and ensure that the content on your local wp-env instance reflects the same content found on your sandbox. (Ensure you have downloaded the ./export/sandbox.wordpress.xml file from above instructions first.)

Run npm run wp-env:empty again to clean our your local environment and then npm run wp-env:import:theam and ensure that the content on your local wp-env instance reflects the same content found on theamdemo.wordpress.com (Ensure you have downloaded the ./export/theamdemo.wordpress.xml file from above instructions first.)

Run npm run wp-env:empty again to clean our your local environment and then npm run wp-env:import:unittest and ensure that the content on your local wp-env instance reflects the content from the theme-unit-test repository. (For this one you don't have to download anything first, it should be made available due to the mappings configuration in .wp-env.json. However that is dependent on this change which might not be available via npm yet so ymmv.)

Run npm run wp-env:export:local and ensure that the file ./export/local.wordpress.xml reflects the same XML content found in the theme-unit-test repository (since that's the content that you last imported if you're playing along in order).

Lastly run npm run wp-env:cleanslate. Your local content will be wiped, the content from theamdemo.wordpress.com will be downloaded to your local ./export folder and then imported into your wp-env instance.

This change adds tools to import/export content from the local wp-env
instance.

Content can be pulled from your sandbox, themedemo.wordpress.com or from
the theme-unit-test repository

The sandbox.sh script was changed to power the "export" (from sandbox or
themedemo) functionality.

The .wp-env.json was changed to supply the content from theme-unit-test
repository, map local folders for import/export of the rest of the
resources and to provide the import plugin by default.

npm scripts have been added to package.json in order to drive the
commands.

Documentation in readme has been updated to reflect the additional
capabilities.
@jffng
Copy link
Contributor

jffng commented Feb 25, 2021

This is great! Thank you for the play by play testing instructions, it was a pleasure to follow along. This is going to help standardize and ease our testing processes significantly, thank you!

Here are some notes from my testing.

./sandbox.sh export-theam

  • I get the following: rm: cannot remove '/home/wpcom/export/*': No such file or directory
  • Three Warning: cannot modify header information warnings
  • It still successfully creates the theamdemo.wordpress.xml

./sandbox.sh export

  • I get the following: mkdir: cannot create directory '/home/wpcom/export': File exists
  • It still successfully creates the theamdemo.wordpress.xml

npm run wp-env:empty

npm run wp-env:import:sandbox

  • This takes a minute (~3) but I guess that makes sense.

npm run wp-env:import:theam

  • This takes a minute (~3) but I guess that makes sense.

npm run wp-env:import:theam

  • Maybe I am not running the latest wp-env? It looks like the change you mentioned is merged, but this didn't import any content for me.

npm run wp-env:export:local

  • Same console messages as the export-theam command, which makes sense.
  • Love this one

@@ -141,7 +141,30 @@ How do you wish to proceed? [1]"
cmd="rsync -av --no-p --no-times --exclude-from='.sandbox-ignore' --exclude=$ignore_string ./ $SANDBOX_USER@$SANDBOX_LOCATION:$SANDBOX_PUBLIC_THEMES_FOLDER/"
eval $cmd

elif [[ $1 == "export" ]]; then
# Export the site content from your sandbox to a local file
export_command='ssh $SANDBOX_USER@$SANDBOX_LOCATION "mkdir /home/wpcom/export ; rm /home/wpcom/export/* ; /home/wpcom/public_html/bin/wp export --dir=/home/wpcom/export"'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this command assumes I have some exported content in /home/wpcom/export already? Is there a way I could specify a specific site of mine to export from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that command will create the file in the /home/wpcom/export folder and then copy it locally.

It's a pretty hacky way to do it I think but I couldn't quite get things to work in another way. And Bash always just seems like a giant roll of duct tape to me anyway...

It would be a simple change to target a particular site defined in the command execution, yea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truth be told I have NO idea where there's a mkdir followed by an immediate rm so that's probably something that should change (even if it doesn't not work)


elif [[ $1 == "export-theam" ]]; then
# Export the site content from theamdemo to a local file
export_command='ssh $SANDBOX_USER@$SANDBOX_LOCATION "mkdir /home/wpcom/export ; rm /home/wpcom/export/* ; /home/wpcom/public_html/bin/wp export --dir=/home/wpcom/export --url=theamdemo.wordpress.com"'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should probably just change to use whatever URL you pass in like:

./sandbox.sh export theamdemo.wordpress.com

instead of

./sandbox.sh export-theam

allowing for

./sandbox.sh export peanutbutterbatter.wordpress.com

@scruffian
Copy link
Member

As mentioned in Slack, I think this really belongs outside the themes repo as it's so specific to a8c. IMO a8c-wp-env would be a good home for it.

@pbking
Copy link
Contributor Author

pbking commented Mar 2, 2021

Closing this and adding to a8c-wp-env instead via: https://github.com/Automattic/a8c-wp-env/pull/81

@pbking pbking closed this Mar 2, 2021
@scruffian scruffian deleted the enhance/add-wp-testdata branch March 2, 2021 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants