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

Improve logic for checking valid exporters #414

Merged
merged 4 commits into from
Aug 2, 2024

Conversation

fluiddot
Copy link
Contributor

@fluiddot fluiddot commented Aug 1, 2024

Related to 8409-gh-Automattic/dotcom-forge.

Proposed Changes

  • Update the logic to determine a valid export. Specifically, the matching of required paths, which we weren't checking full paths for files (e.g. wp-config.php).

Testing Instructions

  • Run the app with the command STUDIO_IMPORT_EXPORT=true npm start.
  • Select a site/Create a site.
  • Navigate to the Import/Export tab.
  • Click on Export entire site.
  • Observe the export process succeeds.
  • Open the site's folder via the Finder button located in the Overview tab.
  • Remove the file wp-config.php.
  • Click again on Export entire site.
  • Observe that the export process fails and that an error message is shown.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@fluiddot fluiddot requested a review from a team August 1, 2024 16:44
@fluiddot fluiddot self-assigned this Aug 1, 2024
@@ -53,7 +53,7 @@ describe( 'DefaultExporter', () => {
{ path: '/path/to/site/wp-content/plugins/plugin1', name: 'plugin1.php', isFile: () => true },
{ path: '/path/to/site/wp-content/themes/theme1', name: 'index.php', isFile: () => true },
{ path: '/path/to/site/wp-includes/index.php', name: 'index.php', isFile: () => true },
{ path: '/path/to/site/wp-load.php', name: 'wp-load.php', isFile: () => true },
{ path: '/path/to/site', name: 'wp-load.php', isFile: () => true },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were getting false positives in the export unit tests due to the previous logic of canHandle.

Comment on lines 22 to 23
onEvent( { event: ExportEvents.EXPORT_ERROR, data: null } );
throw new Error( 'No suitable exporter found for the site' );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that we weren't raising an error when no exporter are found.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this, I had a similar concern earlier in #391 (comment) 👍

@fluiddot fluiddot mentioned this pull request Aug 1, 2024
1 task
Copy link
Contributor

@katinthehatsite katinthehatsite left a comment

Choose a reason for hiding this comment

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

It works as expected, thank you for improving the logic 👍

@wojtekn
Copy link
Contributor

wojtekn commented Aug 2, 2024

@fluiddot it works as expected.

I'm wondering what the best behavior for the exporter would be. Export gracefully, so if any path is missing, Studio still produces the backup file? Or fail early and do not allow to product export files that miss some files or directories?

@fluiddot
Copy link
Contributor Author

fluiddot commented Aug 2, 2024

I'm wondering what the best behavior for the exporter would be. Export gracefully, so if any path is missing, Studio still produces the backup file? Or fail early and do not allow to product export files that miss some files or directories?

I understand that the files we check are required so I'd lean toward fail early and mark the export as failed. However, we can re-evaluate this logic and consider some of the paths optional.

@fluiddot fluiddot merged commit bcf3c4f into trunk Aug 2, 2024
10 checks passed
@fluiddot fluiddot deleted the update/improve-export-can-handle branch August 2, 2024 09:32
Copy link

sentry-io bot commented Aug 8, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ Error: No suitable exporter found for the site <anonymous>(main/studio/./src/lib/import-export... View Issue

Did you find this useful? React with a 👍 or 👎

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