-
Notifications
You must be signed in to change notification settings - Fork 85
Add --auto-update-indicated flag to plugin update command #495
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
base: main
Are you sure you want to change the base?
Changes from all commits
14fc9be
5a4ad4e
4e3d71b
d1e1500
5ad764d
27ab4e6
7db7e24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,7 @@ class Plugin_Command extends CommandWithUpgrade { | |
| 'version', | ||
| 'update_version', | ||
| 'auto_update', | ||
| 'auto_update_indicated', | ||
| ); | ||
|
|
||
| public function __construct() { | ||
|
|
@@ -707,6 +708,9 @@ protected function install_from_repo( $slug, $assoc_args ) { | |
| * [--insecure] | ||
| * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. | ||
| * | ||
| * [--auto-update-indicated] | ||
| * : Only update plugins where the server response indicates an automatic update. Updates to the version indicated by the server, not necessarily the latest version. Cannot be used with `--version`, `--minor`, or `--patch`. | ||
| * | ||
| * ## EXAMPLES | ||
| * | ||
| * $ wp plugin update bbpress --version=dev | ||
|
|
@@ -756,7 +760,49 @@ protected function install_from_repo( $slug, $assoc_args ) { | |
| * @alias upgrade | ||
| */ | ||
| public function update( $args, $assoc_args ) { | ||
| $all = Utils\get_flag_value( $assoc_args, 'all', false ); | ||
| $all = Utils\get_flag_value( $assoc_args, 'all', false ); | ||
| $auto_update_indicated = Utils\get_flag_value( $assoc_args, 'auto-update-indicated', false ); | ||
|
|
||
| // Don't allow --version to be set with --auto-update-indicated, as the version comes from the server. | ||
| if ( $auto_update_indicated && isset( $assoc_args['version'] ) ) { | ||
| WP_CLI::error( 'Cannot use --version with --auto-update-indicated. The version is determined by the server.' ); | ||
| } | ||
|
|
||
swissspidy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Don't allow --minor or --patch to be set with --auto-update-indicated, as the version comes from the server. | ||
| if ( $auto_update_indicated && ( isset( $assoc_args['minor'] ) || isset( $assoc_args['patch'] ) ) ) { | ||
| WP_CLI::error( 'Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server.' ); | ||
| } | ||
|
|
||
| // Don't allow plugin names to be specified with --auto-update-indicated. | ||
| if ( $auto_update_indicated && ! empty( $args ) ) { | ||
| WP_CLI::error( 'Cannot specify plugin names with --auto-update-indicated. This flag updates all plugins with server-indicated automatic updates.' ); | ||
| } | ||
|
|
||
| // If --auto-update-indicated is set, we need to filter plugins by this flag. | ||
| if ( $auto_update_indicated ) { | ||
| // Get all plugins with their update info. | ||
| $items = $this->get_item_list(); | ||
|
|
||
| // Filter to only include plugins where auto_update_indicated is true. | ||
| $auto_update_plugins = array_filter( | ||
| $items, | ||
| function ( $item ) { | ||
| return ! empty( $item['auto_update_indicated'] ); | ||
| } | ||
| ); | ||
|
|
||
| // Get the plugin names to update. | ||
| $args = array_values( wp_list_pluck( $auto_update_plugins, 'name' ) ); | ||
|
|
||
| if ( empty( $args ) ) { | ||
| WP_CLI::success( 'No plugins with server-indicated automatic updates available.' ); | ||
| return; | ||
| } | ||
|
|
||
| // Process the updates. | ||
| parent::update_many( $args, $assoc_args ); | ||
| return; | ||
| } | ||
|
Comment on lines
+782
to
+805
|
||
|
|
||
| $args = $this->check_optional_args_and_all( $args, $all ); | ||
| if ( ! $args ) { | ||
|
|
@@ -806,8 +852,9 @@ protected function get_item_list() { | |
| $duplicate_names[ $name ] = array(); | ||
| } | ||
|
|
||
| $requires = isset( $update_info ) && isset( $update_info['requires'] ) ? $update_info['requires'] : null; | ||
| $requires_php = isset( $update_info ) && isset( $update_info['requires_php'] ) ? $update_info['requires_php'] : null; | ||
| $requires = isset( $update_info ) && isset( $update_info['requires'] ) ? $update_info['requires'] : null; | ||
| $requires_php = isset( $update_info ) && isset( $update_info['requires_php'] ) ? $update_info['requires_php'] : null; | ||
| $auto_update_indicated = isset( $update_info ) && isset( $update_info['autoupdate'] ) ? (bool) $update_info['autoupdate'] : false; | ||
|
|
||
| // If an update has requires_php set, check to see if the local version of PHP meets that requirement | ||
| // The plugins update API already filters out plugins that don't meet WordPress requirements, but does not | ||
|
|
@@ -849,6 +896,7 @@ protected function get_item_list() { | |
| 'description' => wordwrap( $details['Description'] ), | ||
| 'file' => $file, | ||
| 'auto_update' => in_array( $file, $auto_updates, true ), | ||
| 'auto_update_indicated' => $auto_update_indicated, | ||
| 'author' => $details['Author'], | ||
| 'tested_up_to' => '', | ||
| 'requires' => $requires, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test coverage for the --auto-update-indicated flag is missing scenarios for incompatibility with --minor and --patch flags. Consider adding test scenarios similar to the existing "Error when using --version with --auto-update-indicated" test (line 303) for these flags:
This would ensure the validation logic is properly tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added test scenarios for
--minorand--patchincompatibility in commit 7db7e24. The tests now cover:--minorwith--auto-update-indicated--patchwith--auto-update-indicated--auto-update-indicated