Skip to content

Commit bb93280

Browse files
Ensure a stable version is used when --minor or --patch specified (#355)
* Ensure a stable version is used when `--minor` or `--patch` specified * Use the parent class with `parseStability` method
1 parent 4518059 commit bb93280

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace WP_CLI;
44

5+
use Composer\Semver\VersionParser;
56
use Composer\Semver\Comparator;
67
use Exception;
78
use WP_CLI;
@@ -351,7 +352,7 @@ protected function update_many( $args, $assoc_args ) {
351352
$type = $minor ? 'minor' : 'patch';
352353
$insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false );
353354

354-
$items_to_update = self::get_minor_or_patch_updates( $items_to_update, $type, $insecure );
355+
$items_to_update = self::get_minor_or_patch_updates( $items_to_update, $type, $insecure, true );
355356
}
356357

357358
$exclude = Utils\get_flag_value( $assoc_args, 'exclude' );
@@ -610,9 +611,10 @@ private function get_color( $status ) {
610611
* @param array $items Plugins with updates.
611612
* @param string $type Either 'minor' or 'patch'.
612613
* @param bool $insecure Whether to retry without certificate validation on TLS handshake failure.
614+
* @param bool $require_stable Whether to require stable version when comparing versions.
613615
* @return array
614616
*/
615-
private function get_minor_or_patch_updates( $items, $type, $insecure ) {
617+
private function get_minor_or_patch_updates( $items, $type, $insecure, $require_stable ) {
616618
$wp_org_api = new WpOrgApi( [ 'insecure' => $insecure ] );
617619
foreach ( $items as $i => $item ) {
618620
try {
@@ -642,6 +644,10 @@ private function get_minor_or_patch_updates( $items, $type, $insecure ) {
642644
if ( 'minor' === $type && ! in_array( $update_type, array( 'minor', 'patch' ), true ) ) {
643645
continue;
644646
}
647+
if ( $require_stable && 'stable' !== VersionParser::parseStability( $version ) ) {
648+
continue;
649+
}
650+
645651
if ( $update_version && ! Comparator::greaterThan( $version, $update_version ) ) {
646652
continue;
647653
}

0 commit comments

Comments
 (0)