diff --git a/lib/Command/DownloadModels.php b/lib/Command/DownloadModels.php index 7dcafabe..96d1ff50 100644 --- a/lib/Command/DownloadModels.php +++ b/lib/Command/DownloadModels.php @@ -41,7 +41,9 @@ protected function configure() { */ protected function execute(InputInterface $input, OutputInterface $output): int { try { - $this->downloader->download(); + $this->downloader->download(function (string $message) use ($output): void { + $output->writeln($message); + }); } catch (\Exception $ex) { $output->writeln('Failed to download models'); $output->writeln($ex->getMessage()); diff --git a/lib/Service/DownloadModelsService.php b/lib/Service/DownloadModelsService.php index 64e42238..17dd8a81 100644 --- a/lib/Service/DownloadModelsService.php +++ b/lib/Service/DownloadModelsService.php @@ -23,12 +23,16 @@ public function __construct(IClientService $clientService, bool $isCLI) { } /** + * @param callable(string): void|null $log * @return void * @throws \Exception */ - public function download() : void { + public function download(?callable $log = null) : void { + $log ??= static function (string $message): void { + }; $targetPath = __DIR__ . '/../../models'; if (file_exists($targetPath)) { + $log('Removing existing models directory at ' . $targetPath); // remove models directory $it = new RecursiveDirectoryIterator($targetPath, FilesystemIterator::SKIP_DOTS); $files = new RecursiveIteratorIterator($it, @@ -45,8 +49,11 @@ public function download() : void { $archiveUrl = $this->getArchiveUrl($this->getNeededArchiveRef()); $archivePath = __DIR__ . '/../../models.tar.gz'; + $log('Downloading models archive from ' . $archiveUrl); + $log('Saving archive to ' . $archivePath); $timeout = $this->isCLI ? 0 : 480; $this->clientService->newClient()->get($archiveUrl, ['sink' => $archivePath, 'timeout' => $timeout]); + $log('Extracting models to ' . $targetPath); $tarManager = new TAR($archivePath); $tarFiles = $tarManager->getFiles(); $mainFolder = $tarFiles[0];