diff --git a/features/language-core.feature b/features/language-core.feature index ecab9c70..141f2c93 100644 --- a/features/language-core.feature +++ b/features/language-core.feature @@ -225,9 +225,12 @@ Feature: Manage core translation files for a WordPress install Given an empty directory And WP files And a database - And I run `wp core download --version= --force` + And I try `wp core download --version= --force` + And the return code should be 0 And wp-config.php - And I run `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1` + # The SQLite object cache drop-in might produce a "no such table: wp_options" STDERR during installation. + And I try `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1` + And the return code should be 0 When I run `wp language core list --fields=language,status,update` Then STDOUT should be a table containing rows: @@ -505,9 +508,12 @@ Feature: Manage core translation files for a WordPress install Given an empty directory And WP files And a database - And I run `wp core download --version= --force` + And I try `wp core download --version= --force` + And the return code should be 0 And wp-config.php - And I run `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1` + # The SQLite object cache drop-in might produce a "no such table: wp_options" STDERR during installation. + And I try `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1` + And the return code should be 0 When I run `wp language core install en_CA ja` Then STDERR should be empty diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index 16347599..25204657 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -370,10 +370,13 @@ public function uninstall( $args ) { } /** @var WP_Filesystem_Base $wp_filesystem */ - $deleted = $wp_filesystem->delete( WP_LANG_DIR . $dir . '/' . $file ); + if ( $wp_filesystem->delete( WP_LANG_DIR . $dir . '/' . $file ) ) { + $deleted = true; + } } if ( $deleted ) { + $this->clear_translation_files_cache( WP_LANG_DIR . $dir ); WP_CLI::success( 'Language uninstalled.' ); } else { WP_CLI::error( "Couldn't uninstall language." ); diff --git a/src/Plugin_Language_Command.php b/src/Plugin_Language_Command.php index e6f10d3e..dd47d74a 100644 --- a/src/Plugin_Language_Command.php +++ b/src/Plugin_Language_Command.php @@ -551,11 +551,13 @@ public function uninstall( $args, $assoc_args ) { if ( $count_files_to_remove === $count_files_removed ) { $result['status'] = 'uninstalled'; ++$successes; + $this->clear_translation_files_cache( $dir ); \WP_CLI::log( "Language '{$language_code}' for '{$plugin}' uninstalled." ); } elseif ( $count_files_removed ) { \WP_CLI::log( "Language '{$language_code}' for '{$plugin}' partially uninstalled." ); $result['status'] = 'partial uninstall'; ++$errors; + $this->clear_translation_files_cache( $dir ); } elseif ( $had_one_file ) { /* $count_files_removed == 0 */ \WP_CLI::log( "Couldn't uninstall language '{$language_code}' from plugin {$plugin}." ); $result['status'] = 'failed to uninstall'; diff --git a/src/Theme_Language_Command.php b/src/Theme_Language_Command.php index 7e5bce13..dd790438 100644 --- a/src/Theme_Language_Command.php +++ b/src/Theme_Language_Command.php @@ -570,11 +570,13 @@ public function uninstall( $args, $assoc_args ) { if ( $count_files_to_remove === $count_files_removed ) { $result['status'] = 'uninstalled'; ++$successes; + $this->clear_translation_files_cache( $dir ); \WP_CLI::log( "Language '{$language_code}' for '{$theme}' uninstalled." ); } elseif ( $count_files_removed ) { \WP_CLI::log( "Language '{$language_code}' for '{$theme}' partially uninstalled." ); $result['status'] = 'partial uninstall'; ++$errors; + $this->clear_translation_files_cache( $dir ); } elseif ( $had_one_file ) { /* $count_files_removed == 0 */ \WP_CLI::log( "Couldn't uninstall language '{$language_code}' from theme {$theme}." ); $result['status'] = 'failed to uninstall'; diff --git a/src/WP_CLI/CommandWithTranslation.php b/src/WP_CLI/CommandWithTranslation.php index dc2d1da3..b0efeccb 100644 --- a/src/WP_CLI/CommandWithTranslation.php +++ b/src/WP_CLI/CommandWithTranslation.php @@ -439,4 +439,16 @@ protected function get_all_languages( $slug = null ) { protected function get_formatter( &$assoc_args ) { return new Formatter( $assoc_args, $this->obj_fields, $this->obj_type ); } + + /** + * Clears the translation files cache for a given directory. + * + * As of WP 6.5, the presence of .mo and .l10n.php files is cached. + * + * @param string $dir The directory to clear the cache for. + */ + protected function clear_translation_files_cache( $dir ) { + $path = rtrim( $dir, '/' ) . '/'; + wp_cache_delete( md5( $path ), 'translation_files' ); + } }