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

Playground plugin: export data and catch load errors #219

Merged
merged 8 commits into from
Apr 5, 2024

Conversation

bgrgicak
Copy link
Collaborator

@bgrgicak bgrgicak commented Apr 5, 2024

Fixes #213 #208

What?

This PR adds support for exporting Playground data and implements an error modal when Playground fails to load.

Why?

We would like to allow users to export snapshots of their sites that can later be imported into Playground (a feature in Playground isn't implemented).

Some users reported errors like CORS issues and we need to ensure users have a next step to debug the issue.

How?

Playground snapshot is now an option in Tools > Export.

By catching errors while Playground is loading and displaying an alert.

Testing Instructions

  1. Check out the branch.
  2. Start a site with the plugin running for example by using wp-env
cd packages/playground
wp-env start
  1. Go to wp-admin > Tools > Export
  2. Select Playground snapshot and export it
  3. Ensure that the downloaded zip contains data
  4. Add one of the headers to the top of playground.php
header("Content-Security-Policy: default-src 'self'");

header("Content-Security-Policy: default-src 'self' style-src 'self' 'unsafe-inline' 'unsafe-eval'; script-src 'self' 'unsafe-inline' 'unsafe-eval';");
  1. Try starting a sandbox
  2. Confirm that you see an error alert

@bgrgicak bgrgicak added Bug Something isn't working Playground plugin labels Apr 5, 2024
@bgrgicak bgrgicak self-assigned this Apr 5, 2024
}
$user = get_user_by( 'id', ${playground.userId} );
if( $user ) {
wp_set_current_user( $user->ID, $user->user_login );
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be moved to the login step in core

resource: 'url',
url: playground.zipUrl,
},
extractToPath: '/wordpress',
Copy link
Collaborator

@adamziel adamziel Apr 5, 2024

Choose a reason for hiding this comment

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

It just struck me that it's writing over the WordPress instance that's already in /wordpress. Oh well 🤷 Are we compressing the entire WordPress installation with wp-admin and wp-includes? I wonder if this step would be more appropriate:

    {
      "step": "importWordPressFiles",
      "wordPressFilesZip": {
        "resource": "url",
        "url": playground.zipUrl
      },
      "progress": {
        "weight": 20,
        "caption": "Installing WordPress site"
      }
    }

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or, even better:

			features: {
				networking: true,
			},
			preferredVersions: {
				wp: playground.zipUrl,
				php: playground.phpVersion
			},

Copy link
Collaborator

@adamziel adamziel left a comment

Choose a reason for hiding this comment

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

I left some notes on how to lean more on Blueprints core, but nothing blocking. LGTM 👍

@bgrgicak
Copy link
Collaborator Author

bgrgicak commented Apr 5, 2024

Thanks! Both make sense and we will need to do it as part of enabling imports in Playground.

@bgrgicak bgrgicak merged commit 5d352f4 into trunk Apr 5, 2024
2 checks passed
@bgrgicak bgrgicak deleted the update/playground-plugin-release branch April 5, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Playground plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Playground plugin: Unable to start a sandbox
2 participants