From 819c2caccf45dc05b0e2363871d2eb9788d464df Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 10 Aug 2016 06:01:40 -0700 Subject: [PATCH] Indicate current file in WXR import progress indicator Doing so communicates the total count is of the current file, not all files. --- features/import.feature | 16 ++++++++++++++++ php/commands/import.php | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/features/import.feature b/features/import.feature index 54a06829b1..7398920dfb 100644 --- a/features/import.feature +++ b/features/import.feature @@ -232,3 +232,19 @@ Feature: Import content. """ 2 """ + + Scenario: Indicate current file when importing + Given a WP install + And I run `wp plugin install --activate wordpress-importer` + + When I run `wp export --filename_format=wordpress.{n}.xml` + Then save STDOUT 'Writing to file %s' as {EXPORT_FILE} + + When I run `wp site empty --yes` + Then STDOUT should not be empty + + When I run `wp import {EXPORT_FILE} --authors=skip` + Then STDOUT should contain: + """ + -- 1 of 2 (in file wordpress.000.xml) + """ diff --git a/php/commands/import.php b/php/commands/import.php index 8ae8208330..a2be901a87 100644 --- a/php/commands/import.php +++ b/php/commands/import.php @@ -167,6 +167,7 @@ private function import_wxr( $file, $args ) { add_filter( 'intermediate_image_sizes_advanced', array( $this, 'filter_set_image_sizes' ) ); } + $GLOBALS['wp_cli_import_current_file'] = basename( $file ); $wp_import->import( $file ); $this->processed_posts += $wp_import->processed_posts; @@ -198,13 +199,13 @@ private function add_wxr_filters() { }, 10, 3 ); add_filter( 'wp_import_post_data_raw', function( $post ) { - global $wpcli_import_counts; + global $wpcli_import_counts, $wp_cli_import_current_file; $wpcli_import_counts['current_post']++; WP_CLI::log(''); WP_CLI::log(''); WP_CLI::log( sprintf( 'Processing post #%d ("%s") (post_type: %s)', $post['post_id'], $post['post_title'], $post['post_type'] ) ); - WP_CLI::log( sprintf( '-- %s of %s', number_format( $wpcli_import_counts['current_post'] ), number_format( $wpcli_import_counts['total_posts'] ) ) ); + WP_CLI::log( sprintf( '-- %s of %s (in file %s)', number_format( $wpcli_import_counts['current_post'] ), number_format( $wpcli_import_counts['total_posts'] ), $wp_cli_import_current_file ) ); WP_CLI::log( '-- ' . date( 'r' ) ); return $post;