From 2aac1f8cb4a16459d51aba4490897f4de8472a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Thu, 6 Jun 2024 16:26:45 +0200 Subject: [PATCH] Try to fix the self-update command --- composer.json | 2 +- composer.lock | 12 ++-- src/N98/Magento/Command/SelfUpdateCommand.php | 59 +++++++++++++++---- 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 9a19fe7c0..2660b7326 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "fakerphp/faker": "^1.20", "n98/junit-xml": "~1.0", "psy/psysh": "~0.4", - "rmccue/requests": "^2.0", + "rmccue/requests": "^2.0.11", "symfony/console": "~5.4", "symfony/event-dispatcher": "~5.4", "symfony/finder": "~5.4", diff --git a/composer.lock b/composer.lock index a42915373..e017c6760 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "41450af4e859c474773a8c3eaad9da9b", + "content-hash": "4030da981d8fe9a2636b5e323c51867a", "packages": [ { "name": "fakerphp/faker", @@ -351,16 +351,16 @@ }, { "name": "rmccue/requests", - "version": "v2.0.10", + "version": "v2.0.11", "source": { "type": "git", "url": "https://github.com/WordPress/Requests.git", - "reference": "bcf1ac7fe8c0b2b18c1df6d24694cfc96b44b391" + "reference": "31435a468e2357e68df743f2527bda32556a0818" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/Requests/zipball/bcf1ac7fe8c0b2b18c1df6d24694cfc96b44b391", - "reference": "bcf1ac7fe8c0b2b18c1df6d24694cfc96b44b391", + "url": "https://api.github.com/repos/WordPress/Requests/zipball/31435a468e2357e68df743f2527bda32556a0818", + "reference": "31435a468e2357e68df743f2527bda32556a0818", "shasum": "" }, "require": { @@ -434,7 +434,7 @@ "issues": "https://github.com/WordPress/Requests/issues", "source": "https://github.com/WordPress/Requests" }, - "time": "2024-01-08T11:14:32+00:00" + "time": "2024-03-25T10:48:46+00:00" }, { "name": "symfony/console", diff --git a/src/N98/Magento/Command/SelfUpdateCommand.php b/src/N98/Magento/Command/SelfUpdateCommand.php index c9d6f2487..3ae1bc646 100644 --- a/src/N98/Magento/Command/SelfUpdateCommand.php +++ b/src/N98/Magento/Command/SelfUpdateCommand.php @@ -49,14 +49,6 @@ protected function configure() ); } - /** - * @return bool - */ - public function isEnabled() - { - return $this->getApplication()->isPharMode(); - } - /** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output @@ -66,6 +58,13 @@ public function isEnabled() protected function execute(InputInterface $input, OutputInterface $output) { $isDryRun = $input->getOption('dry-run'); + + if (!$this->getApplication()->isPharMode()) { + $isDryRun = true; + $output->writeln('Self-update is supported only for phar files.'); + $output->writeln('Dry-run mode is enabled.'); + } + $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0]; $tempFilename = dirname($localFilename) . '/' . basename($localFilename, '.phar') . '-temp.phar'; @@ -92,7 +91,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $remotePharDownloadUrl = self::MAGERUN_DOWNLOAD_URL_STABLE; } - $response = Requests::get($versionTxtUrl, [], ['verify' => false]); + $response = Requests::get( + $versionTxtUrl, + [], + [ + 'verify' => true, + ] + ); if (!$response->success) { throw new RuntimeException('Cannot get version: ' . $response->status_code); @@ -162,7 +167,16 @@ private function downloadNewPhar(OutputInterface $output, string $remoteUrl, str $hooks = new Hooks(); - $response = Requests::head($remoteUrl, [], ['verify' => false]); + $response = Requests::head( + $remoteUrl, + [], + [ + 'verify' => true, + 'headers' => [ + 'Accept-Encoding' => 'deflate, gzip, br, zstd' + ] + ] + ); if (!$response->success) { throw new RuntimeException('Cannot download phar file: ' . $response->status_code); @@ -183,7 +197,18 @@ function ($data, $responseBytes, $responseByteLimit) use ($progressBar) { } ); - $response = Requests::get($remoteUrl, [], ['blocking' => true, 'hooks' => $hooks, 'verify' => false]); + $response = Requests::get( + $remoteUrl, + [], + [ + 'blocking' => true, + 'hooks' => $hooks, + 'verify' => true, + 'headers' => [ + 'Accept-Encoding' => 'deflate, gzip, br, zstd' + ] + ] + ); if (!$response->success) { throw new RuntimeException('Cannot download phar file: ' . $response->status_code); @@ -240,7 +265,17 @@ private function getChangelog(OutputInterface $output, $loadUnstable) } else { $changeLogUrl = self::CHANGELOG_DOWNLOAD_URL_STABLE; } - $response = Requests::get($changeLogUrl, [], ['verify' => false]); + + $response = Requests::get( + $changeLogUrl, + [], + [ + 'verify' => true, + 'headers' => [ + 'Accept-Encoding' => 'deflate, gzip, br, zstd' + ] + ] + ); if (!$response->success) { throw new RuntimeException('Cannot download changelog: ' . $response->status_code);