From 956d44c339a836f6a649dd49c06cdbd030c36712 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 1 Apr 2022 21:53:41 +0200 Subject: [PATCH] Add --2.2 flag to self-update for 2.2 LTS as well as EOL marker support --- src/Composer/Command/SelfUpdateCommand.php | 9 +++++++-- src/Composer/SelfUpdate/Versions.php | 14 ++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index daf1b55ff..244c54aaa 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -59,6 +59,7 @@ class SelfUpdateCommand extends BaseCommand new InputOption('snapshot', null, InputOption::VALUE_NONE, 'Force an update to the snapshot channel'), new InputOption('1', null, InputOption::VALUE_NONE, 'Force an update to the stable channel, but only use 1.x versions'), new InputOption('2', null, InputOption::VALUE_NONE, 'Force an update to the stable channel, but only use 2.x versions'), + new InputOption('2.2', null, InputOption::VALUE_NONE, 'Force an update to the stable channel, but only use 2.2.x LTS versions'), new InputOption('set-channel-only', null, InputOption::VALUE_NONE, 'Only store the channel as the default one and then exit'), )) ->setHelp( @@ -182,8 +183,12 @@ EOT } } - if ($requestedChannel && is_numeric($requestedChannel) && strpos($latestStable['version'], $requestedChannel) !== 0) { - $io->writeError('Warning: You forced the install of '.$latestVersion.' via --'.$requestedChannel.', but '.$latestStable['version'].' is the latest stable version. Updating to it via composer self-update --stable is recommended.'); + $effectiveChannel = $requestedChannel === null ? $versionsUtil->getChannel() : $requestedChannel; + if (is_numeric($effectiveChannel) && strpos($latestStable['version'], $effectiveChannel) !== 0) { + $io->writeError('Warning: You forced the install of '.$latestVersion.' via --'.$effectiveChannel.', but '.$latestStable['version'].' is the latest stable version. Updating to it via composer self-update --stable is recommended.'); + } + if (isset($latest['eol'])) { + $io->writeError('Warning: Version '.$latestVersion.' is EOL / End of Life. '.$latestStable['version'].' is the latest stable version. Updating to it via composer self-update --stable is recommended.'); } if (Preg::isMatch('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) { diff --git a/src/Composer/SelfUpdate/Versions.php b/src/Composer/SelfUpdate/Versions.php index 9e617fb13..823f4a5b5 100644 --- a/src/Composer/SelfUpdate/Versions.php +++ b/src/Composer/SelfUpdate/Versions.php @@ -12,6 +12,7 @@ namespace Composer\SelfUpdate; +use Composer\Pcre\Preg; use Composer\Util\HttpDownloader; use Composer\Config; @@ -21,7 +22,7 @@ use Composer\Config; class Versions { /** @var string[] */ - public static $channels = array('stable', 'preview', 'snapshot', '1', '2'); + public static $channels = array('stable', 'preview', 'snapshot', '1', '2', '2.2'); /** @var HttpDownloader */ private $httpDownloader; @@ -29,7 +30,7 @@ class Versions private $config; /** @var string */ private $channel; - /** @var array> */ + /** @var array> */ private $versionsData; public function __construct(Config $config, HttpDownloader $httpDownloader) @@ -50,7 +51,7 @@ class Versions $channelFile = $this->config->get('home').'/update-channel'; if (file_exists($channelFile)) { $channel = trim(file_get_contents($channelFile)); - if (in_array($channel, array('stable', 'preview', 'snapshot'), true)) { + if (in_array($channel, array('stable', 'preview', 'snapshot', '2.2'), true)) { return $this->channel = $channel; } } @@ -71,13 +72,14 @@ class Versions $channelFile = $this->config->get('home').'/update-channel'; $this->channel = $channel; - file_put_contents($channelFile, (is_numeric($channel) ? 'stable' : $channel).PHP_EOL); + // rewrite '2' and '1' channels to stable for future self-updates, but LTS ones like '2.2' remain pinned + file_put_contents($channelFile, (Preg::isMatch('{^\d+$}D', $channel) ? 'stable' : $channel).PHP_EOL); } /** * @param string|null $channel * - * @return array{path: string, version: string, min-php: int} + * @return array{path: string, version: string, min-php: int, eol?: true} */ public function getLatest($channel = null) { @@ -93,7 +95,7 @@ class Versions } /** - * @return array> + * @return array> */ private function getVersionsData() {