Skip to content

Commit

Permalink
Try to fix the self-update command
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuench committed Jun 6, 2024
1 parent 8ba70ba commit 2aac1f8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 47 additions & 12 deletions src/N98/Magento/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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('<warning>Self-update is supported only for phar files.</warning>');
$output->writeln('Dry-run mode is enabled.');
}

$localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
$tempFilename = dirname($localFilename) . '/' . basename($localFilename, '.phar') . '-temp.phar';

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2aac1f8

Please sign in to comment.