Skip to content

Commit 2020056

Browse files
committed
Add —force-check flag to wp plugin list and wp theme list. (wip)
1 parent f9bc3fd commit 2020056

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

features/plugin-list.feature

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Feature: List WordPress plugins
2+
3+
Background:
4+
Given a WP install
5+
And I run `wp plugin uninstall --all`
6+
And I run `wp plugin install hello-dolly`
7+
And a setup.php file:
8+
"""
9+
<?php
10+
$plugin_transient = get_site_transient('update_plugins') ;
11+
# manually set the version
12+
$fake_version = '10.0.0';
13+
$plugin_transient->no_update["hello-dolly/hello.php"]->new_version = $fake_version;
14+
$return = set_site_transient( 'update_plugins', $plugin_transient );
15+
"""
16+
# And a wp-content/mu-plugins/test-plugin-update.php file:
17+
# """
18+
# <?php
19+
# /**
20+
# * Plugin Name: Test Plugin Update
21+
# * Description: Fakes installed plugin's data to verify plugin version mismatch
22+
# * Author: WP-CLI tests
23+
# */
24+
#
25+
# add_filter( 'site_transient_update_plugins', function( $value ) {
26+
# if ( ! is_object( $value ) ) {
27+
# return $value;
28+
# }
29+
# $fake_version = '10.0.0';
30+
#
31+
# unset( $value->response['hello-dolly/hello.php'] );
32+
# $value->no_update['hello-dolly/hello.php']->new_version = $fake_version;
33+
#
34+
# return $value;
35+
# } );
36+
# ?>
37+
# """
38+
39+
Scenario: Refresh update_plugins transient when listing plugins with --force-check flag
40+
41+
# Listing the plugins will populate the transient in the database
42+
When I run `wp plugin list`
43+
Then STDOUT should not be empty
44+
And save STDOUT as {PLUGIN_LIST_ORIGINAL_VERSIONS}
45+
46+
# Write a test value
47+
When I run `wp eval-file setup.php`
48+
Then STDOUT should be empty
49+
50+
# Get value of plugin transient
51+
#When I run `wp option get _site_transient_update_plugins`
52+
#Then STDOUT should be empty
53+
54+
# Run list again
55+
When I run `wp plugin list`
56+
Then STDOUT should be empty
57+
And save STDOUT as {PLUGIN_LIST_FAKE_VERSIONS}
58+
59+
# TODO: compare {PLUGIN_LIST_ORIGINAL_VERSIONS} to {PLUGIN_LIST_FAKE_VERSIONS}
60+
# expected result: they should be different
61+
62+
# Get value of plugin transient
63+
When I run `wp option get _site_transient_update_plugins`
64+
Then STDOUT should be empty
65+
66+
When I run `wp plugin list --force-check`
67+
Then STDOUT should not be empty
68+
And save STDOUT as {PLUGIN_LIST_FORCE_CHECK_VERSIONS}
69+
70+
# TODO: compare {PLUGIN_LIST_ORIGINAL_VERSIONS} to {PLUGIN_LIST_FORCE_CHECK_VERSIONS}
71+
# expected result: they should be the same

features/theme-list.feature

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Feature: List WordPress themes
2+
3+
Background:
4+
Given a WP install
5+
And a setup.php file:
6+
"""
7+
<?php
8+
$theme_transient = new stdClass;
9+
$theme_transient->last_checked = time();
10+
$theme_transient->checked = [];
11+
$theme_transient->response = [];
12+
$theme_transient->no_update = [];
13+
$theme_transient->translations = [];
14+
$return = update_option( '_site_transient_update_themes', $theme_transient );
15+
"""
16+
And I run `wp transient delete update_themes --network`
17+
18+
Scenario: Refresh update_themes transient when listing themes with --force-check flag
19+
20+
# Listing the themes will populate the transient in the database
21+
When I run `wp theme list`
22+
Then STDOUT should not be empty
23+
24+
When I run `wp transient set update_themes test_value --network`
25+
And I run `wp theme list --force-check`
26+
27+
Then STDOUT should be empty

src/Plugin_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,9 @@ public function delete( $args, $assoc_args = array() ) {
13251325
* [--skip-update-check]
13261326
* : If set, the plugin update check will be skipped.
13271327
*
1328+
* [--force-check]
1329+
* : Bypass the transient cache and force a fresh update check.
1330+
*
13281331
* [--recently-active]
13291332
* : If set, only recently active plugins will be shown and the status filter will be ignored.
13301333
*

src/Theme_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,9 @@ public function delete( $args, $assoc_args ) {
857857
* [--skip-update-check]
858858
* : If set, the theme update check will be skipped.
859859
*
860+
* [--force-check]
861+
* : Bypass the transient cache and force a fresh update check.
862+
*
860863
* ## AVAILABLE FIELDS
861864
*
862865
* These fields will be displayed by default for each theme:

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,11 @@ static function ( $result ) {
532532
// phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Whitelisting to provide backward compatibility to classes possibly extending this class.
533533
protected function _list( $_, $assoc_args ) {
534534

535+
// If `--force-check` flag is present, delete the ${item_type} transient.
536+
if ( true === (bool) Utils\get_flag_value( $assoc_args, 'force-check', false ) ) {
537+
delete_site_transient( $this->item_type . 's' );
538+
}
539+
535540
// Force WordPress to check for updates if `--skip-update-check` is not passed.
536541
if ( false === (bool) Utils\get_flag_value( $assoc_args, 'skip-update-check', false ) ) {
537542
call_user_func( $this->upgrade_refresh );

0 commit comments

Comments
 (0)