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

Add support for importing .wpress files #497

Merged
merged 28 commits into from
Oct 7, 2024
Merged

Conversation

danielbachhuber
Copy link
Contributor

@danielbachhuber danielbachhuber commented Sep 2, 2024

Related #496 and https://github.com/Automattic/dotcom-forge/issues/8380

Proposed Changes

Adds support for importing .wpress files from All-in-One WP Migration and Backup.

A lot of this code was generated by Cursor + Claude 😊

Props to https://github.com/ofhouse/wpress-extract/blob/main/lib/wpress-extract.js for guidance on how .wpress files are structured.

Testing Instructions

  1. Install All-in-One WP Migration and Backup plugin on Atomic or self-hosted site
  2. Change theme, upload media, install plugin, add post and page etc.
  3. Prepare file backup
  4. Import .wpress file in Studio
  5. Confirm that other formats are still imported

Pre-merge Checklist

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

@danielbachhuber danielbachhuber self-assigned this Sep 2, 2024
@danielbachhuber
Copy link
Contributor Author

Could I get an initial review on this? Also, what sort of tests would you suggest (particularly given .wpress' custom backup format?

Copy link
Contributor

@fluiddot fluiddot left a comment

Choose a reason for hiding this comment

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

Could I get an initial review on this?

The PR looks great, thanks @danielbachhuber for creating it 🙇 . I added some comments to the code but apart from using async file system operations, the approach looks solid.

However, I encountered an issue when testing it. After importing a wpress file, the active theme points to an empty theme. This makes the site render a blank page.

Screenshot 2024-09-05 at 14 08 00

Also, what sort of tests would you suggest (particularly given .wpress' custom backup format?

You check examples of other tests we made for other formats here. We mock the file reading operations, so I presume the tests for the wpress format would be similar to the ones we have.

Let me know if there's anything I can help further to move the PR forward 🙂.

} );

rl.on( 'line', ( line: string ) => {
writeStream.write( line.replace( /SERVMASK_PREFIX/g, 'wp' ) + '\n' );
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we could expand on why wpress format needs to modify the SQL code before importing it.

Copy link
Member

Choose a reason for hiding this comment

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

Do you refer that we should add a comment explaining why why we replace this fake prefix?
It seems that wpress replaces the original prefix with SERVMASK_PREFIX, probably to avoid prefix collisions when importing to a shared database.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you refer that we should add a comment explaining why why we replace this fake prefix? It seems that wpress replaces the original prefix with SERVMASK_PREFIX, probably to avoid prefix collisions when importing to a shared database.

Yep, I was curious why we need this. Thanks @sejas for explaining it 🙇 !

Copy link
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

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

Whoa! It's almost working!
Great work and All-in-One WP Migration and Backup format will be a great addition.

I've experienced the same error, where the theme is not selected. After accessing twice to /wp-admin/themes.php the 2024 theme was selected automatically instead of the correct theme used in the original site.

Screenshot 2024-09-06 at 00 08 38

At first I thought it was some errors with SQLite import, like not supporting "START TRANSACTION;", but after debugging it, I've found that my .wpress file has an empty string for the template and stylesheet options. It seems that the All in one plugin removes those options from the SQL dump on purpose.

Screenshot 2024-09-06 at 01 07 07

@danielbachhuber
Copy link
Contributor Author

However, I encountered an issue when testing it. After importing a wpress file, the active theme points to an empty theme. This makes the site render a blank page.

As it turns out, the .wpress archive includes a package.json file with some site configuration data:

CleanShot 2024-09-23 at 03 40 45@2x

I guess we need to process that post-import too.

await fsPromises.rename( tempOutputPath, tmpPath );
}

protected async parseWpressPackage(): Promise< {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to treat this package file as the metafile so we could implement this as a part of the parseMetaFile() method?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I was thinking in something like that.

Currently it's working and we set correctly the theme, but creating a more abstract way to set it can benefit future adaptations.

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't mean to create a more abstract way. I meant to use the abstraction that already exists (parseMetaFile), instead of adding new one (parseWpressPackage).

Copy link
Member

@sejas sejas Sep 30, 2024

Choose a reason for hiding this comment

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

I've updated the code to reuse the parseMetaFile function.

Now MetaFileData has WP and PHP versions as optional and template and stylesheet also optionals.

Changed on: 4a08615

@sejas sejas marked this pull request as ready for review September 30, 2024 21:16
@sejas
Copy link
Member

sejas commented Sep 30, 2024

@wojtekn , @fluiddot , I've updated the code. Let me know what you think.
I'll add some tests in the mean time, but feel free to review the PR.
Thanks!

@sejas sejas requested a review from a team September 30, 2024 21:29
@wojtekn
Copy link
Contributor

wojtekn commented Oct 1, 2024

@sejas thanks for taking this over. I've just updated the testing steps.

It works well for me, allowing me to import a .wpress file. I noticed two issues so far:

  • I can't drag and drop file. I need to use a file selector to pick up the file.
  • Plugins on imported sites are inactive.

@sejas
Copy link
Member

sejas commented Oct 1, 2024

@wojtekn , thanks for reviewing it.

I can't drag and drop file. I need to use a file selector to pick up the file.

Good catch! It took me a while find that it was failing only in the add site form.
Fixed! 876bcf2

UbxWD5.mp4

Plugins on imported sites are inactive.

I've found that wpress creates a variable with the active plugins on package.json > Plugins.
I'm creating a sql file to activate them. 952f8d6

Copy link
Contributor

@wojtekn wojtekn left a comment

Choose a reason for hiding this comment

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

I've found that wpress creates a variable with the active plugins on package.json > Plugins.
I'm creating a sql file to activate them. 952f8d6

I couldn't make it work - after importing .wpress from the Atomic site, none of the plugins is active.

src/lib/import-export/import/importers/importer.ts Outdated Show resolved Hide resolved
} );

rl.on( 'line', ( line: string ) => {
writeStream.write( line.replace( /SERVMASK_PREFIX/g, 'wp' ) + '\n' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you refer that we should add a comment explaining why why we replace this fake prefix? It seems that wpress replaces the original prefix with SERVMASK_PREFIX, probably to avoid prefix collisions when importing to a shared database.

Yep, I was curious why we need this. Thanks @sejas for explaining it 🙇 !

Copy link
Contributor

@fluiddot fluiddot left a comment

Choose a reason for hiding this comment

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

LGTM 🎊 ! I confirmed I can import a .wpress backup file and themes and plugins match the original site.
Great work @sejas !

I've added some comments but none should block the PR.

@fluiddot
Copy link
Contributor

fluiddot commented Oct 2, 2024

@sejas following #497 (comment), it would be great to add unit tests to cover the import of this backup type. WDYT?

@sejas sejas merged commit bae0104 into trunk Oct 7, 2024
10 checks passed
@sejas sejas deleted the improve/import-wpress-files branch October 7, 2024 06:49
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.

4 participants