Skip to content

Commit 364548b

Browse files
committed
Fix stale cache & slug issue
1 parent 78deb28 commit 364548b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

features/plugin-install.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ Feature: Install WordPress plugins
323323
"""
324324
Warning: Plugin already installed.
325325
"""
326+
And STDERR should not contain:
327+
"""
328+
plugin could not be found
329+
"""
326330
And STDOUT should contain:
327331
"""
328332
Success: Plugin already installed.

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@ public function install( $args, $assoc_args ) {
254254
} else {
255255
// $result is WP_Error here
256256
WP_CLI::warning( $result->get_error_message() );
257-
if ( 'already_installed' !== $result->get_error_code() ) {
257+
if ( 'already_installed' === $result->get_error_code() ) {
258+
if ( $result->get_error_data( 'slug' ) ) {
259+
$slug = $result->get_error_data( 'slug' );
260+
}
261+
} else {
258262
++$errors;
259263
}
260264
}
@@ -338,6 +342,11 @@ public function install( $args, $assoc_args ) {
338342
}
339343
}
340344

345+
// Only plugins cache really exists.
346+
if ( 'plugin' === $this->item_type ) {
347+
wp_cache_delete( 'plugins', 'plugins' );
348+
}
349+
341350
// Check extension is available or not.
342351
$extension = $this->fetcher->get_many( array( $slug ) );
343352

@@ -411,7 +420,10 @@ protected function install_from_php_file( $url, $assoc_args ) {
411420

412421
// Check if plugin is already installed before downloading.
413422
if ( file_exists( $dest_path ) && ! Utils\get_flag_value( $assoc_args, 'force' ) ) {
414-
return new WP_Error( 'already_installed', 'Plugin already installed.' );
423+
$error = new WP_Error( 'already_installed', 'Plugin already installed.' );
424+
// An easy way to provide the slug of the installed plugin.
425+
$error->add_data( $dest_filename, 'slug' );
426+
return $error;
415427
}
416428

417429
// Ensure plugin directory exists.

0 commit comments

Comments
 (0)