Skip to content

Commit 2c1230d

Browse files
committed
Fix download progress bar max value
1 parent a862c88 commit 2c1230d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/N98/Magento/Command/SelfUpdateCommand.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,32 @@ protected function _exit($statusCode = 0)
155155
private function downloadNewPhar(OutputInterface $output, string $remoteUrl, string $tempFilename)
156156
{
157157
$progressBar = new ProgressBar($output);
158-
$progressBar->setFormat('[%bar%] %current% downloaded');
158+
$progressBar->setFormat('[%bar%] %current% of %max% bytes downloaded');
159159

160160
$hooks = new Hooks();
161+
162+
$response = Requests::head($remoteUrl, [], ['verify' => false]);
163+
164+
if (!$response->success) {
165+
throw new RuntimeException('Cannot download phar file: ' . $response->status_code);
166+
}
167+
168+
$filesize = $response->headers['content-length'];
169+
170+
$hooks->register('curl.after_request', function (&$headers, &$info) use (&$filesize) {
171+
$filesize = $info['size_download'];
172+
});
173+
174+
$progressBar->setMaxSteps($filesize);
175+
161176
$hooks->register(
162177
'request.progress',
163178
function ($data, $responseBytes, $responseByteLimit) use ($progressBar) {
164179
$progressBar->setProgress($responseBytes);
165180
}
166181
);
167182

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

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

0 commit comments

Comments
 (0)