wp-cli / extension-command

Manages plugins and themes, including installs, activations, and updates.
MIT License
90 stars 79 forks source link

Added `--minor` and `--patch` CLI option in `wp theme update` #393

Closed up1512001 closed 9 months ago

up1512001 commented 10 months ago

Fixes https://github.com/wp-cli/extension-command/issues/394

Added missing CLI option for --minor and --patch into wp theme update command list.

Output Before Adding CLI Options for --minor & --patch

Screenshot 2024-01-20 at 17 21 30

Output After Adding CLI Options for --minor & --patch

Screenshot 2024-01-20 at 17 21 55
swissspidy commented 10 months ago

OK so there are a couple of reasons why the tests are not currently working.

First, this PR right now only allows these two new args to be passed, but does not actually change the code to do anything with those args. Support for theme item types needs to be added in these two places:

https://github.com/wp-cli/extension-command/blob/955bd947d95ef91da501179c7e561d229ab3cc19/src/WP_CLI/CommandWithUpgrade.php#L351-L357

https://github.com/wp-cli/extension-command/blob/955bd947d95ef91da501179c7e561d229ab3cc19/src/WP_CLI/CommandWithUpgrade.php#L622

I just addressed this in 895e6ad5e406c9ca7b5de3933af5cd53147d1029

Second, and most importantly, the WordPress.org API by default does not actually return information about available versions for themes.

Here's the API response for Hello Dolly: https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request%5Blocale%5D=en_US&request%5Bslug%5D=hello-dolly

Here's the API response for Twenty Twelve: https://api.wordpress.org/themes/info/1.2/?action=theme_information&request%5Blocale%5D=en_US&request%5Bslug%5D=twentytwelve

See how there's no versions field.

To address this, we first need to add support for fetching additional fields. After those code modifications, this PR will work as expected.

See https://github.com/wp-cli/wp-cli/pull/5893 for where I add this support.

up1512001 commented 9 months ago

Hi @swissspidy @danielbachhuber may I know any update regarding https://github.com/wp-cli/wp-cli/pull/5893 PR and when can I expect feedback for my PR?

swissspidy commented 9 months ago

This PR is already in good shape. Once https://github.com/wp-cli/wp-cli/pull/5893 is merged, this PR only requires a dependency update and then it should be good to go.

I just pinged the other committers on https://github.com/wp-cli/wp-cli/pull/5893 to review it.

up1512001 commented 9 months ago

Hey @swissspidy I just checked the new theme update logic as I understand instead of getting info from style.css we will now fetch from the theme archive for its info am I right? Thanks for updating it.

swissspidy commented 9 months ago

Not sure what you mean, this doesn't really change how themes are looked up or anything.

The one thing I noticed while testing this patch is that filter_item_list() stored themes with their full directory path as the key. However, plugins are only stored with their slug. This caused problems when filtering the theme transient, as it turns out that didn't really work before, because we were using the full directory path and not the theme slug. That's why there are these changes to use get_stylesheet() instead of get_stylesheet_directory() for example.

Another interesting find was that the theme update transient is a list of arrays, whereas for plugins it's a list of objects apparently. So the PR now also caters for that.

As you can see, all existing tests are still passing and the new tests helped uncover these flaws.

up1512001 commented 9 months ago

Hey, @danielbachhuber as https://github.com/wp-cli/wp-cli/pull/5893 this PR is merged can you please update this PR status? Thank You.