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
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
},
"config": {
"process-timeout": 7200,
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"johnpbloch/wordpress-core-installer": true
}
},
"extra": {
"branch-alias": {
Expand Down
35 changes: 35 additions & 0 deletions features/import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,38 @@ Feature: Import content.
"""
(in file wordpress.000.xml)
"""

Scenario: Handling of non-existing files and directories
Given a WP install
And I run `wp plugin install --activate wordpress-importer`
And I run `wp export`
And save STDOUT 'Writing to file %s' as {EXPORT_FILE}
And an empty 'empty_test_directory' directory

When I try `wp import non_existing_relative_file_path.xml --authors=skip`
Then STDERR should contain:
"""
Warning:
"""
Then the return code should be 1

When I try `wp import non_existing_relative_file_path.xml {EXPORT_FILE} --authors=skip`
Then STDERR should contain:
"""
Warning:
"""
Then the return code should be 0

When I try `wp import empty_test_directory --authors=skip`
Then STDERR should contain:
"""
Warning:
"""
Then the return code should be 1

When I try `wp import empty_test_directory non_existing_relative_file_path.xml --authors=skip`
Then STDERR should contain:
"""
Warning:
"""
Then the return code should be 1
22 changes: 18 additions & 4 deletions src/Import_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,32 @@ public function __invoke( $args, $assoc_args ) {
if ( ! empty( $files ) ) {
$new_args = array_merge( $new_args, $files );
}

if ( empty( $files ) ) {
WP_CLI::warning( "No files found in the import directory '$arg'." );
}
} else {
if ( file_exists( $arg ) ) {
if ( ! file_exists( $arg ) ) {
WP_CLI::warning( "File '$arg' doesn't exist." );
continue;
}

if ( is_readable( $arg ) ) {
$new_args[] = $arg;
continue;
}

WP_CLI::warning( "Cannot read file '$arg'." );
}
}

if ( empty( $new_args ) ) {
WP_CLI::error( 'Import failed due to missing or unreadable file/s.' );
}

$args = $new_args;

foreach ( $args as $file ) {
if ( ! is_readable( $file ) ) {
WP_CLI::warning( "Can't read '$file' file." );
}

$ret = $this->import_wxr( $file, $assoc_args );

Expand Down