shortUrlService = $shortUrlService; $this->previewGenerator = $previewGenerator; $this->translator = $translator; parent::__construct(null); } protected function configure(): void { $this ->setName(self::NAME) ->setAliases(self::ALIASES) ->setDescription( $this->translator->translate( 'Processes and generates the previews for every URL, improving performance for later web requests.' ) ); } protected function execute(InputInterface $input, OutputInterface $output): void { $page = 1; do { $shortUrls = $this->shortUrlService->listShortUrls($page); $page += 1; foreach ($shortUrls as $shortUrl) { $this->processUrl($shortUrl->getLongUrl(), $output); } } while ($page <= $shortUrls->count()); (new SymfonyStyle($input, $output))->success($this->translator->translate('Finished processing all URLs')); } private function processUrl($url, OutputInterface $output): void { try { $output->write(sprintf($this->translator->translate('Processing URL %s...'), $url)); $this->previewGenerator->generatePreview($url); $output->writeln($this->translator->translate(' Success!')); } catch (PreviewGenerationException $e) { $output->writeln(' ' . $this->translator->translate('Error') . ''); if ($output->isVerbose()) { $this->getApplication()->renderException($e, $output); } } } }