Skip to content

Fix backup import for Jetpack, Local, Wpress and Studio formats - #2422

Merged
bcotrim merged 1 commit into
trunkfrom
stu-1217-fix-backup-import-database-error
Jan 20, 2026
Merged

Fix backup import for Jetpack, Local, Wpress and Studio formats#2422
bcotrim merged 1 commit into
trunkfrom
stu-1217-fix-backup-import-database-error

Conversation

@bcotrim

@bcotrim bcotrim commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

  • Fix PHP version type conversion in CLI: yargs-parser converts --php-version 8.3 from string to number, causing Zod validation to fail silently. Now explicitly converts back to string.
  • Fix SQL file path for standalone PHP-WASM: The sqlite import command needs an absolute path /wordpress/<file> because standalone PHP-WASM mounts the site at /wordpress but doesn't set the working directory there.

Testing Instructions

  1. Create a new site in Studio
  2. Export a backup from the site
  3. Create another new site
  4. Import the backup using "Import" option
  5. Verify the import completes successfully without "Database import failed" error
  6. Test with different backup formats: Jetpack, Local, Wpress, Studio backups

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@bcotrim bcotrim self-assigned this Jan 19, 2026
@bcotrim
bcotrim requested a review from a team January 19, 2026 20:59
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 3e1e771 vs trunk

site-editor

Metric trunk 3e1e771 Diff Change
load 2930.00 ms 2930.00 ms 0.00 ms ⚪ 0.0%

site-startup

Metric trunk 3e1e771 Diff Change
siteCreation 8106.00 ms 8092.00 ms -14.00 ms 🟢 -0.2%
siteStartup 3936.00 ms 3939.00 ms +3.00 ms 🔴 0.1%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change

@fredrikekelund fredrikekelund 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.

Good catch! This works great 👍

Comment thread cli/commands/wp.ts
);
}

const phpVersion = parsedWpCliArgs[ 'php-version' ] as string | undefined;

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.

		const parsedWpCliArgs = yargsParser( wpCliArgv, {
			string: [ 'php-version' ],
		} );

		if ( parsedWpCliArgs._[ 0 ] === 'shell' ) {
			throw new LoggerError(
				__(
					'Studio CLI does not support the WP-CLI `shell` command. Consider adding your code to a file and using the `eval` command.'
				)
			);
		}

		const phpVersion = parsedWpCliArgs[ 'php-version' ];

Unfortunately, yargs-parser doesn't properly type parsedWpCliArgs[ 'php-version' ] if we do this, so I still prefer your solution.

I wanted to mention the possibility of configuring yargs-parser, though, since it fixes the underlying issue of --php-version being parsed by yargs as a number.

@katinthehatsite katinthehatsite 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 changes look good to me, I was able to import .wpress, Studio and Jetpack files. I got this warning with .wpress but I don't think it is related to this PR:

Warning during replacing URLs (https:\/\/mxhtestpremium3.wpcomstaging.com): Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /wordpress/wp-content/mu-plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-pdo-user-defined-functions.php on line 511

I also noticed something strange with the database export for older sites where it was failing so asked on Slack: p1768898334187009/1768816016.045449-slack-C06DRMD6VPZ but again it is not related to this PR 👍

@wojtekn wojtekn 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.

Thanks for the fix. The code change looks reasonable.

@bcotrim
bcotrim merged commit 9ac00a7 into trunk Jan 20, 2026
10 checks passed
@bcotrim
bcotrim deleted the stu-1217-fix-backup-import-database-error branch January 20, 2026 09:34
@bcotrim bcotrim mentioned this pull request Jan 27, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants