Skip to content

Conversation

bcotrim
Copy link
Contributor

@bcotrim bcotrim commented Sep 3, 2025

Related issues

Proposed Changes

  • Added detailed progress tracking during import with file counts and type-specific messages
  • Enhanced extraction progress to show "Extracting backup… (234/1,250 files)"
  • Added database import details showing "Importing database… (2/3 SQL files)"
  • Implemented WordPress content breakdown by type: "Importing plugins… (5/12)", "Importing themes… (2/3)", "Importing media uploads… (150/500)"
  • Added new progress events: BACKUP_EXTRACT_FILE_START, IMPORT_DATABASE_PROGRESS, IMPORT_WP_CONTENT_PROGRESS
  • Updated backup handlers (ZIP, tar.gz) to emit granular progress data
  • Fixed unit test expectations for tar.gz handler

Testing Instructions

  • Create a test site with multiple plugins, themes, and content (use FakerPress for posts with images)
  • Export the site as a backup
  • Import into a new site and observe detailed progress messages
  • Test with different backup types (ZIP, tar.gz, .wpress)
  • Verify progress shows file counts and content type information
  • For slower testing to observe messages, temporarily add delays in handlers (remove before merge)

Pre-merge Checklist

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

@bcotrim bcotrim self-assigned this Sep 3, 2025
@bcotrim bcotrim requested a review from a team September 3, 2025 16:19
@bcotrim bcotrim marked this pull request as draft September 3, 2025 16:44
@bcotrim bcotrim requested a review from Copilot September 3, 2025 16:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the import process with verbose progress tracking to provide more detailed feedback during backup extraction and import operations. The changes make the import process more transparent by showing file counts, content types, and granular progress updates.

Key changes:

  • Added granular progress tracking with file counts for extraction, database import, and WordPress content import
  • Implemented content categorization (plugins, themes, uploads, other) with type-specific progress messages
  • Enhanced backup handlers to emit detailed progress events with file counts and current file information

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/lib/import-export/import/types.ts Added new interface types for detailed progress event data
src/lib/import-export/import/events.ts Added new progress event constants for granular tracking
src/lib/import-export/import/importers/importer.ts Implemented content categorization and progress events for database and WordPress content import
src/lib/import-export/import/handlers/backup-handler-zip.ts Enhanced ZIP handler with file-level progress tracking
src/lib/import-export/import/handlers/backup-handler-tar-gz.ts Enhanced tar.gz handler with file-level progress tracking
src/hooks/use-import-export.tsx Updated UI progress handling to display detailed progress messages with file counts
src/lib/import-export/tests/import/importer/jetpack-importer.test.ts Added comprehensive tests for WordPress content categorization
src/lib/import-export/tests/import/handlers/backup-handler.test.ts Updated test expectations for tar.gz handler options
src/hooks/tests/use-import-export.test.tsx Added extensive tests for verbose progress tracking scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +46 to +48
// Get total file count first
const fileList = await this.listFiles( file );
const totalFiles = fileList.length;
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

This implementation requires reading the entire tar.gz file twice - once to count files and again to extract them. This could significantly impact performance for large backup files. Consider counting files during extraction or using a streaming approach to avoid the double read.

Copilot uses AI. Check for mistakes.

.pipe(
tar.extract( {
cwd: extractionDirectory,
onwarn: ( _code, message ) => console.warn( message ),
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

Direct console.warn usage bypasses the application's logging system. Consider using a proper logger or emitting a warning event that can be handled consistently with other error reporting in the application.

Suggested change
onwarn: ( _code, message ) => console.warn( message ),
onwarn: ( code, message ) => {
this.emit(ImportEvents.BACKUP_EXTRACT_WARNING, { code, message });
},

Copilot uses AI. Check for mistakes.

Comment on lines +216 to +217
for ( const [ type, files ] of Object.entries( filesByType ) ) {
for ( const file of files ) {
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The nested loop structure makes progress tracking complex and could lead to inaccurate progress calculations. The outer loop iterates by type but progress is tracked globally across all files. Consider flattening this to a single loop or adjusting progress calculation to account for the nested structure.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think tracking the progress this way makes sense, because we categorized the files into these types in the first place.

Comment on lines +264 to +269
if ( file.includes( '/plugins/' ) || file.includes( '\\plugins\\' ) ) {
categorized.plugins.push( file );
} else if ( file.includes( '/themes/' ) || file.includes( '\\themes\\' ) ) {
categorized.themes.push( file );
} else if ( file.includes( '/uploads/' ) || file.includes( '\\uploads\\' ) ) {
categorized.uploads.push( file );
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The string-based path categorization is fragile and could misclassify files. For example, a file named 'plugins-backup.txt' would be categorized as a plugin. Consider using path.sep and more robust path parsing with path.normalize() or regular expressions to match directory boundaries.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@gcsecsey gcsecsey left a comment

Choose a reason for hiding this comment

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

This looks good and IMO the added progress steps make the import process much more "interactive" from a UX perspective, it's great to see what's happening under the hood.

To test the changes, I configured a site on playground.wordpress.net with fake data and plugins, and exported it both as .wpress and .zip.

When importing the .wpress I ran into an SQL parse error at the end of the import process. I could recreate this error on trunk, so I don't think this is related to these changes:

CleanShot.2025-09-10.at.12.00.12.mp4

error-log.log

Importing the .zip file worked well without errors:

CleanShot.2025-09-10.at.11.27.37.mp4

Comment on lines +216 to +217
for ( const [ type, files ] of Object.entries( filesByType ) ) {
for ( const file of files ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think tracking the progress this way makes sense, because we categorized the files into these types in the first place.

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.

2 participants