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
12 changes: 6 additions & 6 deletions features/import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Import content.
Error: WordPress Importer needs to be installed. Try 'wp plugin install wordpress-importer --activate'.
"""

@require-wp-5.2
@require-wp-5.2 @require-mysql
Scenario: Basic export then import
Given a WP install
And I run `wp site empty --yes`
Expand Down Expand Up @@ -51,7 +51,7 @@ Feature: Import content.
When I run `wp import {EXPORT_FILE} --authors=skip --skip=image_resize`
Then STDOUT should not be empty

@require-wp-5.2
@require-wp-5.2 @require-mysql
Scenario: Export and import a directory of files
Given a WP install
And I run `mkdir export-posts`
Expand Down Expand Up @@ -101,7 +101,7 @@ Feature: Import content.
100
"""

@require-wp-5.2
@require-wp-5.2 @require-mysql
Scenario: Export and import a directory of files with .wxr and .xml extensions.
Given a WP install
And I run `mkdir export`
Expand Down Expand Up @@ -148,7 +148,7 @@ Feature: Import content.
2
"""

@require-wp-5.2
@require-wp-5.2 @require-mysql
Scenario: Export and import page and referencing menu item
Given a WP install
And I run `wp site empty --yes`
Expand Down Expand Up @@ -225,7 +225,7 @@ Feature: Import content.
2
"""

@require-wp-5.2
@require-wp-5.2 @require-mysql
Scenario: Export and import page and referencing menu item in separate files
Given a WP install
And I run `wp site empty --yes`
Expand Down Expand Up @@ -303,7 +303,7 @@ Feature: Import content.
2
"""

@require-wp-5.2
@require-wp-5.2 @require-mysql
Scenario: Indicate current file when importing
Given a WP install
And I run `wp plugin install --activate wordpress-importer`
Expand Down
30 changes: 12 additions & 18 deletions src/Import_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,12 @@ function ( $posts ) {

add_filter(
'wp_import_post_comments',
function ( $comments, $post_id, $post ) {
function ( $comments ) {
global $wpcli_import_counts;
$wpcli_import_counts['current_comment'] = 0;
$wpcli_import_counts['total_comments'] = count( $comments );
return $comments;
},
10,
3
}
);

add_filter(
Expand All @@ -249,7 +247,7 @@ function ( $post ) {

add_action(
'wp_import_insert_post',
function ( $post_id, $original_post_id, $post, $postdata ) {
function ( $post_id ) {
global $wpcli_import_counts;
if ( is_wp_error( $post_id ) ) {
WP_CLI::warning( '-- Error importing post: ' . $post_id->get_error_code() );
Expand All @@ -261,47 +259,43 @@ function ( $post_id, $original_post_id, $post, $postdata ) {
WP_CLI\Utils\wp_clear_object_cache();
WP_CLI::log( '-- Cleared object cache.' );
}
},
10,
4
}
);

add_action(
'wp_import_insert_term',
function ( $t, $import_term, $post_id, $post ) {
function ( $t, $import_term ) {
WP_CLI::log( "-- Created term \"{$import_term['name']}\"" );
},
10,
4
2
);

add_action(
'wp_import_set_post_terms',
function ( $tt_ids, $term_ids, $taxonomy, $post_id, $post ) {
function ( $tt_ids, $term_ids, $taxonomy ) {
WP_CLI::log( '-- Added terms (' . implode( ',', $term_ids ) . ") for taxonomy \"{$taxonomy}\"" );
},
10,
5
3
);

add_action(
'wp_import_insert_comment',
function ( $comment_id, $comment, $comment_post_id, $post ) {
function ( $comment_id ) {
global $wpcli_import_counts;
$wpcli_import_counts['current_comment']++;
WP_CLI::log( sprintf( '-- Added comment #%d (%s of %s)', $comment_id, number_format( $wpcli_import_counts['current_comment'] ), number_format( $wpcli_import_counts['total_comments'] ) ) );
},
10,
4
}
);

add_action(
'import_post_meta',
function ( $post_id, $key, $value ) {
function ( $post_id, $key ) {
WP_CLI::log( "-- Added post_meta $key" );
},
10,
3
2
);
}

Expand Down