Skip to content

Commit dad1359

Browse files
authored
Merge pull request #178 from wp-cli/fix/object-cache-tests
2 parents b0c6b6b + 8b1c0c4 commit dad1359

5 files changed

Lines changed: 30 additions & 5 deletions

File tree

features/language-core.feature

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,12 @@ Feature: Manage core translation files for a WordPress install
225225
Given an empty directory
226226
And WP files
227227
And a database
228-
And I run `wp core download --version=<original> --force`
228+
And I try `wp core download --version=<original> --force`
229+
And the return code should be 0
229230
And wp-config.php
230-
And I run `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1`
231+
# The SQLite object cache drop-in might produce a "no such table: wp_options" STDERR during installation.
232+
And I try `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1`
233+
And the return code should be 0
231234

232235
When I run `wp language core list --fields=language,status,update`
233236
Then STDOUT should be a table containing rows:
@@ -505,9 +508,12 @@ Feature: Manage core translation files for a WordPress install
505508
Given an empty directory
506509
And WP files
507510
And a database
508-
And I run `wp core download --version=<original> --force`
511+
And I try `wp core download --version=<original> --force`
512+
And the return code should be 0
509513
And wp-config.php
510-
And I run `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1`
514+
# The SQLite object cache drop-in might produce a "no such table: wp_options" STDERR during installation.
515+
And I try `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1`
516+
And the return code should be 0
511517

512518
When I run `wp language core install en_CA ja`
513519
Then STDERR should be empty

src/Core_Language_Command.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,13 @@ public function uninstall( $args ) {
370370
}
371371

372372
/** @var WP_Filesystem_Base $wp_filesystem */
373-
$deleted = $wp_filesystem->delete( WP_LANG_DIR . $dir . '/' . $file );
373+
if ( $wp_filesystem->delete( WP_LANG_DIR . $dir . '/' . $file ) ) {
374+
$deleted = true;
375+
}
374376
}
375377

376378
if ( $deleted ) {
379+
$this->clear_translation_files_cache( WP_LANG_DIR . $dir );
377380
WP_CLI::success( 'Language uninstalled.' );
378381
} else {
379382
WP_CLI::error( "Couldn't uninstall language." );

src/Plugin_Language_Command.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,13 @@ public function uninstall( $args, $assoc_args ) {
551551
if ( $count_files_to_remove === $count_files_removed ) {
552552
$result['status'] = 'uninstalled';
553553
++$successes;
554+
$this->clear_translation_files_cache( $dir );
554555
\WP_CLI::log( "Language '{$language_code}' for '{$plugin}' uninstalled." );
555556
} elseif ( $count_files_removed ) {
556557
\WP_CLI::log( "Language '{$language_code}' for '{$plugin}' partially uninstalled." );
557558
$result['status'] = 'partial uninstall';
558559
++$errors;
560+
$this->clear_translation_files_cache( $dir );
559561
} elseif ( $had_one_file ) { /* $count_files_removed == 0 */
560562
\WP_CLI::log( "Couldn't uninstall language '{$language_code}' from plugin {$plugin}." );
561563
$result['status'] = 'failed to uninstall';

src/Theme_Language_Command.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,13 @@ public function uninstall( $args, $assoc_args ) {
570570
if ( $count_files_to_remove === $count_files_removed ) {
571571
$result['status'] = 'uninstalled';
572572
++$successes;
573+
$this->clear_translation_files_cache( $dir );
573574
\WP_CLI::log( "Language '{$language_code}' for '{$theme}' uninstalled." );
574575
} elseif ( $count_files_removed ) {
575576
\WP_CLI::log( "Language '{$language_code}' for '{$theme}' partially uninstalled." );
576577
$result['status'] = 'partial uninstall';
577578
++$errors;
579+
$this->clear_translation_files_cache( $dir );
578580
} elseif ( $had_one_file ) { /* $count_files_removed == 0 */
579581
\WP_CLI::log( "Couldn't uninstall language '{$language_code}' from theme {$theme}." );
580582
$result['status'] = 'failed to uninstall';

src/WP_CLI/CommandWithTranslation.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,16 @@ protected function get_all_languages( $slug = null ) {
439439
protected function get_formatter( &$assoc_args ) {
440440
return new Formatter( $assoc_args, $this->obj_fields, $this->obj_type );
441441
}
442+
443+
/**
444+
* Clears the translation files cache for a given directory.
445+
*
446+
* As of WP 6.5, the presence of .mo and .l10n.php files is cached.
447+
*
448+
* @param string $dir The directory to clear the cache for.
449+
*/
450+
protected function clear_translation_files_cache( $dir ) {
451+
$path = rtrim( $dir, '/' ) . '/';
452+
wp_cache_delete( md5( $path ), 'translation_files' );
453+
}
442454
}

0 commit comments

Comments
 (0)