Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --force-check flag to wp plugin list and wp theme list. #426

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
64 changes: 64 additions & 0 deletions features/plugin-list.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Feature: List WordPress plugins

Scenario: Refresh update_plugins transient when listing plugins with --force-check flag
Given a WP install
And I run `wp plugin uninstall --all`
And I run `wp plugin install hello-dolly`
And a update-transient.php file:
"""
<?php
$transient = get_site_transient( 'update_plugins' );
$transient->response['hello-dolly/hello.php'] = (object) array(
'id' => 'w.org/plugins/hello-dolly',
'slug' => 'hello-dolly',
'plugin' => 'hello-dolly/hello.php',
'new_version' => '100.0.0',
'url' => 'https://wordpress.org/plugins/hello-dolly/',
'package' => 'https://downloads.wordpress.org/plugin/hello-dolly.100.0.0.zip',
);
$transient->checked = array(
'hello-dolly/hello.php' => '1.7.2',
);
unset( $transient->no_update['hello-dolly/hello.php'] );
set_site_transient( 'update_plugins', $transient );
WP_CLI::success( 'Transient updated.' );
"""

# Populates the initial transient in the database
When I run `wp plugin list --fields=name,status,update`
Then STDOUT should be a table containing rows:
| name | status | update |
| hello-dolly | inactive | none |

# Modify the transient in the database to simulate an update
When I run `wp eval-file update-transient.php`
Then STDOUT should be:
"""
Success: Transient updated.
"""

# Verify the fake transient value produces the expected output
When I run `wp plugin list --fields=name,status,update`
Then STDOUT should be a table containing rows:
| name | status | update |
| hello-dolly | inactive | available |

# Repeating the same command again should produce the same results
ernilambar marked this conversation as resolved.
Show resolved Hide resolved
When I run `wp plugin list --fields=name,status,update`
Then STDOUT should be a table containing rows:
| name | status | update |
| hello-dolly | inactive | available |

# Using the --force-check flag should refresh the transient back to the original value
When I run `wp plugin list --fields=name,status,update --force-check`
Then STDOUT should be a table containing rows:
| name | status | update |
| hello-dolly | inactive | none |

When I try `wp plugin list --skip-update-check --force-check`
Then STDERR should contain:
"""
Error: plugin updates cannot be both force-checked and skipped. Choose one.
"""
And STDOUT should be empty
And the return code should be 1
64 changes: 64 additions & 0 deletions features/theme-list.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Feature: List WordPress themes

Scenario: Refresh update_themes transient when listing themes with --force-check flag
Given a WP install
And I run `wp theme delete --all --force`
And I run `wp theme install --force twentytwentyfour --version=1.1`
And a update-transient.php file:
"""
<?php
$transient = get_site_transient( 'update_themes' );
$transient->response['twentytwentyfour'] = (object) array(
ernilambar marked this conversation as resolved.
Show resolved Hide resolved
'theme' => 'twentytwentyfour',
'new_version' => '100.0.0',
'url' => 'https://wordpress.org/themes/twentytwentyfour/',
'package' => 'https://downloads.wordpress.org/theme/twentytwentyfour.100.zip',
'requires' => '6.4',
'requires_php' => '7.0'
);
$transient->checked = array(
'twentytwentyfour' => '1.1',
);
unset( $transient->no_update['twentytwentyfour'] );
set_site_transient( 'update_themes', $transient );
WP_CLI::success( 'Transient updated.' );
"""

# Populates the initial transient in the database
When I run `wp theme list --fields=name,status,update`
Then STDOUT should be a table containing rows:
| name | status | update |
| twentytwentyfour | active | none |

# Modify the transient in the database to simulate an update
When I run `wp eval-file update-transient.php`
Then STDOUT should be:
"""
Success: Transient updated.
"""

# Verify the fake transient value produces the expected output
When I run `wp theme list --fields=name,status,update`
Then STDOUT should be a table containing rows:
| name | status | update |
| twentytwentyfour | active | available |

# Repeating the same command again should produce the same results
When I run `wp theme list --fields=name,status,update`
Then STDOUT should be a table containing rows:
| name | status | update |
| twentytwentyfour | active | available |

# Using the --force-check flag should refresh the transient back to the original value
When I run `wp theme list --fields=name,status,update --force-check`
Then STDOUT should be a table containing rows:
| name | status | update |
| twentytwentyfour | active | none |

When I try `wp theme list --skip-update-check --force-check`
Then STDERR should contain:
"""
Error: theme updates cannot be both force-checked and skipped. Choose one.
"""
And STDOUT should be empty
And the return code should be 1
3 changes: 3 additions & 0 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,9 @@
* [--skip-update-check]
* : If set, the plugin update check will be skipped.
*
* [--force-check]
* : Bypass the transient cache and force a fresh update check.
*

Check failure on line 1330 in src/Plugin_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Tabs must be used to indent lines; spaces are not allowed
* [--recently-active]
* : If set, only recently active plugins will be shown and the status filter will be ignored.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Theme_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,9 @@ public function delete( $args, $assoc_args ) {
* [--skip-update-check]
* : If set, the theme update check will be skipped.
*
* [--force-check]
* : Bypass the transient cache and force a fresh update check.
*
* ## AVAILABLE FIELDS
*
* These fields will be displayed by default for each theme:
Expand Down
10 changes: 10 additions & 0 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,16 @@
// phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Whitelisting to provide backward compatibility to classes possibly extending this class.
protected function _list( $_, $assoc_args ) {

// If `--force-check` and `--skip-update-check` flags are both present, abort.
if ( true === (bool) Utils\get_flag_value( $assoc_args, 'force-check', false ) and true === (bool) Utils\get_flag_value( $assoc_args, 'skip-update-check', false ) ) {

Check failure on line 536 in src/WP_CLI/CommandWithUpgrade.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Logical operator "and" is prohibited; use "&&" instead
ernilambar marked this conversation as resolved.
Show resolved Hide resolved
WP_CLI::error("{$this->item_type} updates cannot be both force-checked and skipped. Choose one.");

Check failure on line 537 in src/WP_CLI/CommandWithUpgrade.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 537 in src/WP_CLI/CommandWithUpgrade.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Expected 1 spaces before closing parenthesis; 0 found
}

// If `--force-check` flag is present, delete the upgrade transient.
if ( true === (bool) Utils\get_flag_value( $assoc_args, 'force-check', false ) ) {
delete_site_transient( $this->upgrade_transient );
}

// Force WordPress to check for updates if `--skip-update-check` is not passed.
if ( false === (bool) Utils\get_flag_value( $assoc_args, 'skip-update-check', false ) ) {
call_user_func( $this->upgrade_refresh );
Expand Down
Loading