Skip to content

Fix handling PHP version from Jetpack backup meta file - #1024

Merged
wojtekn merged 1 commit into
trunkfrom
fix/jetpack-backup-php-version-handling
Mar 10, 2025
Merged

Fix handling PHP version from Jetpack backup meta file#1024
wojtekn merged 1 commit into
trunkfrom
fix/jetpack-backup-php-version-handling

Conversation

@wojtekn

@wojtekn wojtekn commented Mar 7, 2025

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

Recently, Jetpack Backup files started including correct meta.json. It looks like Studio doesn't validate the PHP version correctly, so user who imports such site gets an error.

I propose to add PHP version detection support for Jetpack backups. When importing a Jetpack backup, Studio will now properly detect and use the PHP version from the backup's meta.json file, falling back to the default PHP version if the detected version is not supported.

Changes

  • Added PHP version parsing to JetpackImporter
  • Refactored PHP version parsing into a shared method
  • Added validation against supported PHP versions
  • Updated meta file parsing to match Jetpack backup format

Testing Instructions

  1. Create a Jetpack backup from a site running PHP 8.1
  2. Import the backup into Studio
  3. Verify that:
    • The site is created with PHP 8.1
    • If you import a backup with an unsupported PHP version (e.g., 8.5), it falls back to the default version
    • The WordPress version is correctly detected from the backup

You can find a sample meta.json structure in a Jetpack backup:

{
"wordpressVersion": "6.7.2",
"phpVersion": "8.1.31",
"siteUrl": "http://example.com",
"plugins": [...],
"themes": [...]
}

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@wojtekn
wojtekn requested a review from a team March 7, 2025 11:44
@wojtekn wojtekn self-assigned this Mar 7, 2025

@ivan-ottinger ivan-ottinger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The proposed changes look great.

  • I couldn't reproduce the https://github.com/Automattic/dotcom-forge/issues/10577 issue anymore.
  • The Jetpack imports are working correctly - setting the PHP version as expected (based on value in meta.json). If the PHP version is not supported, Studio uses the default PHP version.

Thank you for including helpful testing instructions. It made it easier to test.

Comment on lines +210 to +222
protected parsePhpVersion( version: string | undefined ): string {
if ( ! version ) {
return DEFAULT_PHP_VERSION;
}
const phpVersion = semver.coerce( version );
if ( ! phpVersion ) {
return DEFAULT_PHP_VERSION;
}

const parsedVersion = `${ phpVersion.major }.${ phpVersion.minor }`;

return SupportedPHPVersionsList.includes( parsedVersion ) ? parsedVersion : DEFAULT_PHP_VERSION;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I appreciate moving out the logic into parsePhpVersion. 👌🏼

@wojtekn
wojtekn merged commit 63e91b6 into trunk Mar 10, 2025
@wojtekn
wojtekn deleted the fix/jetpack-backup-php-version-handling branch March 10, 2025 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants