File tree Expand file tree Collapse file tree 3 files changed +58
-5
lines changed
Expand file tree Collapse file tree 3 files changed +58
-5
lines changed Original file line number Diff line number Diff line change 2222 },
2323 "config" : {
2424 "process-timeout" : 7200 ,
25- "sort-packages" : true
25+ "sort-packages" : true ,
26+ "allow-plugins" : {
27+ "dealerdirect/phpcodesniffer-composer-installer" : true ,
28+ "johnpbloch/wordpress-core-installer" : true
29+ }
2630 },
2731 "extra" : {
2832 "branch-alias" : {
Original file line number Diff line number Diff line change @@ -306,3 +306,38 @@ Feature: Import content.
306306 """
307307 (in file wordpress.000.xml)
308308 """
309+
310+ Scenario : Handling of non-existing files and directories
311+ Given a WP install
312+ And I run `wp plugin install --activate wordpress-importer`
313+ And I run `wp export`
314+ And save STDOUT 'Writing to file %s' as {EXPORT_FILE}
315+ And an empty 'empty_test_directory' directory
316+
317+ When I try `wp import non_existing_relative_file_path.xml --authors=skip`
318+ Then STDERR should contain:
319+ """
320+ Warning:
321+ """
322+ Then the return code should be 1
323+
324+ When I try `wp import non_existing_relative_file_path.xml {EXPORT_FILE} --authors=skip`
325+ Then STDERR should contain:
326+ """
327+ Warning:
328+ """
329+ Then the return code should be 0
330+
331+ When I try `wp import empty_test_directory --authors=skip`
332+ Then STDERR should contain:
333+ """
334+ Warning:
335+ """
336+ Then the return code should be 1
337+
338+ When I try `wp import empty_test_directory non_existing_relative_file_path.xml --authors=skip`
339+ Then STDERR should contain:
340+ """
341+ Warning:
342+ """
343+ Then the return code should be 1
Original file line number Diff line number Diff line change @@ -65,18 +65,32 @@ public function __invoke( $args, $assoc_args ) {
6565 if ( ! empty ( $ files ) ) {
6666 $ new_args = array_merge ( $ new_args , $ files );
6767 }
68+
69+ if ( empty ( $ files ) ) {
70+ WP_CLI ::warning ( "No files found in the import directory ' $ arg'. " );
71+ }
6872 } else {
69- if ( file_exists ( $ arg ) ) {
73+ if ( ! file_exists ( $ arg ) ) {
74+ WP_CLI ::warning ( "File ' $ arg' doesn't exist. " );
75+ continue ;
76+ }
77+
78+ if ( is_readable ( $ arg ) ) {
7079 $ new_args [] = $ arg ;
80+ continue ;
7181 }
82+
83+ WP_CLI ::warning ( "Cannot read file ' $ arg'. " );
7284 }
7385 }
86+
87+ if ( empty ( $ new_args ) ) {
88+ WP_CLI ::error ( 'Import failed due to missing or unreadable file/s. ' );
89+ }
90+
7491 $ args = $ new_args ;
7592
7693 foreach ( $ args as $ file ) {
77- if ( ! is_readable ( $ file ) ) {
78- WP_CLI ::warning ( "Can't read ' $ file' file. " );
79- }
8094
8195 $ ret = $ this ->import_wxr ( $ file , $ assoc_args );
8296
You can’t perform that action at this time.
0 commit comments