From 4cd8110e8be250c87143180f86b3ca2f014f7e9b Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 4 Oct 2018 13:14:49 +0200 Subject: [PATCH 1/9] Make use of report_batch_operation_results() for install commands --- src/Plugin_Language_Command.php | 12 +++++++++--- src/Theme_Language_Command.php | 13 ++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Plugin_Language_Command.php b/src/Plugin_Language_Command.php index 72996c4f3..29bab1b42 100644 --- a/src/Plugin_Language_Command.php +++ b/src/Plugin_Language_Command.php @@ -206,23 +206,29 @@ public function is_installed( $args, $assoc_args = array() ) { public function install( $args, $assoc_args ) { $plugin = array_shift( $args ); $language_codes = (array) $args; + $count = count( $language_codes ); $available = $this->get_installed_languages( $plugin ); foreach ( $language_codes as $language_code ) { if ( in_array( $language_code, $available, true ) ) { - \WP_CLI::warning( "Language '{$language_code}' already installed." ); + \WP_CLI::log( "Language '{$language_code}' already installed." ); + $skips++; } else { $response = $this->download_language_pack( $language_code, $plugin ); if ( is_wp_error( $response ) ) { - \WP_CLI::error( $response ); + WP_CLI::warning( $response ); + $errors++; } else { - \WP_CLI::success( 'Language installed.' ); + \WP_CLI::log( 'Language installed.' ); + $successes++; } } } + + \WP_CLI\Utils\report_batch_operation_results( 'language', 'install', $count, $successes, $errors, $skips ); } /** diff --git a/src/Theme_Language_Command.php b/src/Theme_Language_Command.php index 8a23c023b..dd6bca8b7 100644 --- a/src/Theme_Language_Command.php +++ b/src/Theme_Language_Command.php @@ -208,23 +208,30 @@ public function is_installed( $args, $assoc_args = array() ) { public function install( $args, $assoc_args ) { $theme = array_shift( $args ); $language_codes = (array) $args; + $count = count( $language_codes ); $available = $this->get_installed_languages( $theme ); + $successes = $errors = $skips = 0; foreach ( $language_codes as $language_code ) { if ( in_array( $language_code, $available, true ) ) { - \WP_CLI::warning( "Language '{$language_code}' already installed." ); + \WP_CLI::log( "Language '{$language_code}' already installed." ); + $skips++; } else { $response = $this->download_language_pack( $language_code, $theme ); if ( is_wp_error( $response ) ) { - \WP_CLI::error( $response ); + WP_CLI::warning( $response ); + $errors++; } else { - \WP_CLI::success( 'Language installed.' ); + \WP_CLI::log( 'Language installed.' ); + $successes++; } } } + + \WP_CLI\Utils\report_batch_operation_results( 'language', 'install', $count, $successes, $errors, $skips ); } /** From af4e62ca4f1e5401c796149eca82467f1a12c04d Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 4 Oct 2018 13:27:45 +0200 Subject: [PATCH 2/9] Fix whitespace usage --- src/Core_Language_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index 141289981..4713a2231 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -175,7 +175,7 @@ public function is_installed( $args, $assoc_args = array() ) { public function install( $args, $assoc_args ) { $language_codes = (array) $args; - if( 1 < count( $language_codes ) && in_array( true , $assoc_args , true ) ){ + if ( 1 < count( $language_codes ) && in_array( true, $assoc_args, true ) ) { WP_CLI::error( 'Only a single language can be active.' ); } From fdf8b973510e95db6c78ad9286079096503cca1d Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 4 Oct 2018 13:32:53 +0200 Subject: [PATCH 3/9] Make use of report_batch_operation_results() for core install command --- src/Core_Language_Command.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index 4713a2231..f85575dd7 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -174,24 +174,29 @@ public function is_installed( $args, $assoc_args = array() ) { */ public function install( $args, $assoc_args ) { $language_codes = (array) $args; + $count = count( $language_codes ); - if ( 1 < count( $language_codes ) && in_array( true, $assoc_args, true ) ) { + if ( $count > 1 && in_array( true, $assoc_args, true ) ) { WP_CLI::error( 'Only a single language can be active.' ); } $available = $this->get_installed_languages(); + $successes = $errors = $skips = 0; foreach ( $language_codes as $language_code ) { if ( in_array( $language_code, $available, true ) ) { - WP_CLI::warning( "Language '{$language_code}' already installed." ); + \WP_CLI::log( "Language '{$language_code}' already installed." ); + $skips++; } else { $response = $this->download_language_pack( $language_code ); if ( is_wp_error( $response ) ) { - WP_CLI::error( $response ); + WP_CLI::warning( $response ); + $errors++; } else { - WP_CLI::success( 'Language installed.' ); + \WP_CLI::log( 'Language installed.' ); + $successes++; } } @@ -199,6 +204,8 @@ public function install( $args, $assoc_args ) { $this->activate_language( $language_code ); } } + + \WP_CLI\Utils\report_batch_operation_results( 'language', 'install', $count, $successes, $errors, $skips ); } /** From e668ea077a5e507e8af0ab995f63a08ebf0d8fb3 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 4 Oct 2018 13:34:17 +0200 Subject: [PATCH 4/9] Define missing variables --- src/Plugin_Language_Command.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Plugin_Language_Command.php b/src/Plugin_Language_Command.php index 29bab1b42..ebc71adca 100644 --- a/src/Plugin_Language_Command.php +++ b/src/Plugin_Language_Command.php @@ -210,6 +210,7 @@ public function install( $args, $assoc_args ) { $available = $this->get_installed_languages( $plugin ); + $successes = $errors = $skips = 0; foreach ( $language_codes as $language_code ) { if ( in_array( $language_code, $available, true ) ) { From 9b8609a46cb7468732c8bb4720eb1039bcc7a034 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 4 Oct 2018 14:43:09 +0200 Subject: [PATCH 5/9] Update expected content of STDOUT and STDERR --- features/language-core.feature | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/features/language-core.feature b/features/language-core.feature index ec23efdf7..b3b2806b4 100644 --- a/features/language-core.feature +++ b/features/language-core.feature @@ -31,7 +31,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/en_AU.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty @@ -63,11 +63,12 @@ Feature: Manage translation files for a WordPress install """ When I try `wp language core install en_AU` - Then STDERR should be: + Then STDOUT should be: """ - Warning: Language 'en_AU' already installed. + Language 'en_AU' already installed. + Success: Installed 0 of 1 languages (1 skipped). """ - And STDOUT should be empty + And STDERR should be empty And the return code should be 0 When I run `wp language core list --fields=language,english_name,status` @@ -111,23 +112,25 @@ Feature: Manage translation files for a WordPress install | en_GB | English (UK) | active | When I try `wp language core install en_AU --activate` - Then STDERR should contain: - """ - Warning: Language 'en_AU' already installed. - """ + Then STDERR should be empty And STDOUT should be: """ + Language 'en_AU' already installed. Success: Language activated. + Success: Installed 0 of 1 languages (1 skipped). """ And the return code should be 0 When I try `wp language core install en_AU --activate` Then STDERR should contain: """ - Warning: Language 'en_AU' already installed. Warning: Language 'en_AU' already active. """ - And STDOUT should be empty + And STDOUT should contain: + """ + Language 'en_AU' already installed. + Success: Installed 0 of 1 languages (1 skipped). + """ And the return code should be 0 When I try `wp language core install en_CA ja --activate` From 6e5dd09cab57f4db20d7f2b26bc9b65b5a19b655 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 4 Oct 2018 15:00:14 +0200 Subject: [PATCH 6/9] Update expected content of STDOUT and STDERR --- features/language-core.feature | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/features/language-core.feature b/features/language-core.feature index b3b2806b4..694d9d7f1 100644 --- a/features/language-core.feature +++ b/features/language-core.feature @@ -48,7 +48,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/ja.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 2 of 2 languages. """ And STDERR should be empty @@ -194,8 +194,8 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/en_GB.po file should exist And STDOUT should contain: """ - Success: Language installed. Success: Language activated. + Success: Installed 1 of 1 languages. """ And STDERR should be empty @@ -231,7 +231,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/ja.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 2 of 2 languages. """ And STDERR should be empty @@ -348,7 +348,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/de_DE.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty @@ -395,7 +395,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/de_DE_formal.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty From e6c2dcca9fee27b8955659c1a1e66575c6a8aa62 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 4 Oct 2018 15:41:46 +0200 Subject: [PATCH 7/9] Update expected content of STDOUT and STDERR --- features/language-core.feature | 3 ++- features/language-plugin.feature | 16 +++++++++------- features/language-theme.feature | 16 +++++++++------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/features/language-core.feature b/features/language-core.feature index 694d9d7f1..4bf0bca36 100644 --- a/features/language-core.feature +++ b/features/language-core.feature @@ -202,7 +202,8 @@ Feature: Manage translation files for a WordPress install When I try `wp language core install invalid_lang` Then STDERR should be: """ - Error: Language 'invalid_lang' not found. + Warning: Language 'invalid_lang' not found. + Error: No languages installed (1 failed). """ And STDOUT should be empty And the return code should be 1 diff --git a/features/language-plugin.feature b/features/language-plugin.feature index 804e86b1f..4db29a55f 100644 --- a/features/language-plugin.feature +++ b/features/language-plugin.feature @@ -32,7 +32,7 @@ Feature: Manage translation files for a WordPress install Then the wp-content/languages/plugins/hello-dolly-en_GB.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty @@ -41,7 +41,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/plugins/hello-dolly-de_DE.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 2 of 2 languages. """ And STDERR should be empty @@ -62,11 +62,12 @@ Feature: Manage translation files for a WordPress install """ When I try `wp language plugin install hello-dolly en_GB` - Then STDERR should be: + Then STDERR should be empty + And STDOUT should be: """ - Warning: Language 'en_GB' already installed. + Language 'en_GB' already installed. + Success: Installed 0 of 1 languages (1 skipped). """ - And STDOUT should be empty And the return code should be 0 When I run `wp language plugin list hello-dolly --fields=language,english_name,status` @@ -141,7 +142,8 @@ Feature: Manage translation files for a WordPress install When I try `wp language plugin install hello-dolly invalid_lang` Then STDERR should be: """ - Error: Language 'invalid_lang' not found. + Warning: Language 'invalid_lang' not found. + Error: No languages installed (1 failed). """ And STDOUT should be empty And the return code should be 1 @@ -157,7 +159,7 @@ Feature: Manage translation files for a WordPress install Then the wp-content/languages/plugins/hello-dolly-en_GB.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty diff --git a/features/language-theme.feature b/features/language-theme.feature index 85aeb9552..1ac422748 100644 --- a/features/language-theme.feature +++ b/features/language-theme.feature @@ -31,7 +31,7 @@ Feature: Manage translation files for a WordPress install Then the wp-content/languages/themes/twentyten-en_GB.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty @@ -40,7 +40,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/themes/twentyten-de_DE.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 2 of 2 languages. """ And STDERR should be empty @@ -61,11 +61,12 @@ Feature: Manage translation files for a WordPress install """ When I try `wp language theme install twentyten en_GB` - Then STDERR should be: + Then STDERR should be empty + And STDOUT should be: """ - Warning: Language 'en_GB' already installed. + Language 'en_GB' already installed. + Success: Installed 0 of 1 languages (1 skipped). """ - And STDOUT should be empty And the return code should be 0 When I run `wp language theme list twentyten --fields=language,english_name,status` @@ -126,7 +127,8 @@ Feature: Manage translation files for a WordPress install When I try `wp language theme install twentyten invalid_lang` Then STDERR should be: """ - Error: Language 'invalid_lang' not found. + Warning: Language 'invalid_lang' not found. + Error: No languages installed (1 failed). """ And STDOUT should be empty And the return code should be 1 @@ -142,7 +144,7 @@ Feature: Manage translation files for a WordPress install Then the wp-content/languages/themes/twentyten-en_GB.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty From 9698a666b664802fedb9dd841e5fb1031cefa838 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 4 Oct 2018 16:20:42 +0200 Subject: [PATCH 8/9] Always include the language code for installation feedback --- features/language-core.feature | 5 ++++- features/language-plugin.feature | 5 ++++- features/language-theme.feature | 5 ++++- src/Core_Language_Command.php | 5 +++-- src/Plugin_Language_Command.php | 5 +++-- src/Theme_Language_Command.php | 5 +++-- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/features/language-core.feature b/features/language-core.feature index 4bf0bca36..bcf81f9c7 100644 --- a/features/language-core.feature +++ b/features/language-core.feature @@ -205,7 +205,10 @@ Feature: Manage translation files for a WordPress install Warning: Language 'invalid_lang' not found. Error: No languages installed (1 failed). """ - And STDOUT should be empty + And STDOUT should be: + """ + Language 'invalid_lang' not installed. + """ And the return code should be 1 @require-wp-latest @require-php-5.6 @less-than-php-7.0 diff --git a/features/language-plugin.feature b/features/language-plugin.feature index 4db29a55f..ca2662412 100644 --- a/features/language-plugin.feature +++ b/features/language-plugin.feature @@ -145,7 +145,10 @@ Feature: Manage translation files for a WordPress install Warning: Language 'invalid_lang' not found. Error: No languages installed (1 failed). """ - And STDOUT should be empty + And STDOUT should be: + """ + Language 'invalid_lang' not installed. + """ And the return code should be 1 @require-wp-4.0 diff --git a/features/language-theme.feature b/features/language-theme.feature index 1ac422748..175221d37 100644 --- a/features/language-theme.feature +++ b/features/language-theme.feature @@ -130,7 +130,10 @@ Feature: Manage translation files for a WordPress install Warning: Language 'invalid_lang' not found. Error: No languages installed (1 failed). """ - And STDOUT should be empty + And STDOUT should be: + """ + Language 'invalid_lang' not installed. + """ And the return code should be 1 @require-wp-4.0 diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index f85575dd7..2598a5406 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -192,10 +192,11 @@ public function install( $args, $assoc_args ) { $response = $this->download_language_pack( $language_code ); if ( is_wp_error( $response ) ) { - WP_CLI::warning( $response ); + \WP_CLI::warning( $response ); + \WP_CLI::log( "Language '{$language_code}' not installed." ); $errors++; } else { - \WP_CLI::log( 'Language installed.' ); + \WP_CLI::log( "Language '{$language_code}' installed." ); $successes++; } } diff --git a/src/Plugin_Language_Command.php b/src/Plugin_Language_Command.php index ebc71adca..f9a1164b5 100644 --- a/src/Plugin_Language_Command.php +++ b/src/Plugin_Language_Command.php @@ -220,10 +220,11 @@ public function install( $args, $assoc_args ) { $response = $this->download_language_pack( $language_code, $plugin ); if ( is_wp_error( $response ) ) { - WP_CLI::warning( $response ); + \WP_CLI::warning( $response ); + \WP_CLI::log( "Language '{$language_code}' not installed." ); $errors++; } else { - \WP_CLI::log( 'Language installed.' ); + \WP_CLI::log( "Language '{$language_code}' installed." ); $successes++; } } diff --git a/src/Theme_Language_Command.php b/src/Theme_Language_Command.php index dd6bca8b7..17cc5186a 100644 --- a/src/Theme_Language_Command.php +++ b/src/Theme_Language_Command.php @@ -222,10 +222,11 @@ public function install( $args, $assoc_args ) { $response = $this->download_language_pack( $language_code, $theme ); if ( is_wp_error( $response ) ) { - WP_CLI::warning( $response ); + \WP_CLI::warning( $response ); + \WP_CLI::log( "Language '{$language_code}' not installed." ); $errors++; } else { - \WP_CLI::log( 'Language installed.' ); + \WP_CLI::log( "Language '{$language_code}' installed." ); $successes++; } } From f4b79583a2a2ca3b736e3d77b5f82526ab153cb7 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 4 Oct 2018 16:39:38 +0200 Subject: [PATCH 9/9] Update output of installation examples --- src/Core_Language_Command.php | 7 ++++++- src/Plugin_Language_Command.php | 7 ++++++- src/Theme_Language_Command.php | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index 2598a5406..f5c5b1e14 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -168,7 +168,12 @@ public function is_installed( $args, $assoc_args = array() ) { * * # Install the Japanese language. * $ wp language core install ja - * Success: Language installed. + * Downloading translation from https://downloads.wordpress.org/translation/core/4.9.8/ja.zip... + * Unpacking the update... + * Installing the latest version... + * Translation updated successfully. + * Language 'ja' installed. + * Success: Installed 1 of 1 languages. * * @subcommand install */ diff --git a/src/Plugin_Language_Command.php b/src/Plugin_Language_Command.php index f9a1164b5..e5038a7e9 100644 --- a/src/Plugin_Language_Command.php +++ b/src/Plugin_Language_Command.php @@ -199,7 +199,12 @@ public function is_installed( $args, $assoc_args = array() ) { * * # Install the Japanese language for Akismet. * $ wp language plugin install akismet ja - * Success: Language installed. + * Downloading translation from https://downloads.wordpress.org/translation/plugin/akismet/4.0.3/ja.zip... + * Unpacking the update... + * Installing the latest version... + * Translation updated successfully. + * Language 'ja' installed. + * Success: Installed 1 of 1 languages. * * @subcommand install */ diff --git a/src/Theme_Language_Command.php b/src/Theme_Language_Command.php index 17cc5186a..5f4ce7a73 100644 --- a/src/Theme_Language_Command.php +++ b/src/Theme_Language_Command.php @@ -201,7 +201,12 @@ public function is_installed( $args, $assoc_args = array() ) { * * # Install the Japanese language for Twenty Seventeen. * $ wp language theme install twentyseventeen ja - * Success: Language installed. + * Downloading translation from https://downloads.wordpress.org/translation/theme/twentyseventeen/1.3/ja.zip... + * Unpacking the update... + * Installing the latest version... + * Translation updated successfully. + * Language 'ja' installed. + * Success: Installed 1 of 1 languages. * * @subcommand install */