Skip to content

Commit

Permalink
Fix download progress bar max value
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuench committed Apr 14, 2022
1 parent a862c88 commit 2c1230d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/N98/Magento/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,32 @@ protected function _exit($statusCode = 0)
private function downloadNewPhar(OutputInterface $output, string $remoteUrl, string $tempFilename)
{
$progressBar = new ProgressBar($output);
$progressBar->setFormat('[%bar%] %current% downloaded');
$progressBar->setFormat('[%bar%] %current% of %max% bytes downloaded');

$hooks = new Hooks();

$response = Requests::head($remoteUrl, [], ['verify' => false]);

if (!$response->success) {
throw new RuntimeException('Cannot download phar file: ' . $response->status_code);
}

$filesize = $response->headers['content-length'];

$hooks->register('curl.after_request', function (&$headers, &$info) use (&$filesize) {
$filesize = $info['size_download'];
});

$progressBar->setMaxSteps($filesize);

$hooks->register(
'request.progress',
function ($data, $responseBytes, $responseByteLimit) use ($progressBar) {
$progressBar->setProgress($responseBytes);
}
);

$response = Requests::get($remoteUrl, [], ['hooks' => $hooks, 'verify' => false]);
$response = Requests::get($remoteUrl, [], ['blocking' => true, 'hooks' => $hooks, 'verify' => false]);

if (!$response->success) {
throw new RuntimeException('Cannot download phar file: ' . $response->status_code);
Expand Down

0 comments on commit 2c1230d

Please sign in to comment.