Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions features/import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
5 changes: 3 additions & 2 deletions php/commands/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down