Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Command/DownloadModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<error>Failed to download models</error>');
$output->writeln($ex->getMessage());
Expand Down
9 changes: 8 additions & 1 deletion lib/Service/DownloadModelsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
};
Comment on lines 27 to +32

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be nice indeed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @marcelklehr! Added the @PARAM annotation for $log to the docblock.

$targetPath = __DIR__ . '/../../models';
Comment thread
marcelklehr marked this conversation as resolved.
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,
Expand All @@ -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);
Comment thread
marcelklehr marked this conversation as resolved.
$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];
Expand Down