diff --git a/config/services.yaml b/config/services.yaml index 28fcf25..d396b6f 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -53,6 +53,11 @@ services: $connection: '@doctrine.dbal.default_connection' $xmlFilesPath: '%kernel.project_dir%/xmlexport' + App\Command\GenerateThumbnailsCommand: + arguments: + $cacheManager: '@liip_imagine.cache.manager' + $filterService: '@liip_imagine.service.filter' + App\BusProNet\ApiClient: arguments: $logger: '@monolog.logger.bpn' diff --git a/deploy.php b/deploy.php index 47bd5a1..ba5509d 100644 --- a/deploy.php +++ b/deploy.php @@ -92,6 +92,7 @@ task('deploy', [ 'database:migrate', 'deploy:publish', 'cachetool:clear:opcache', + 'deploy:thumbnails', // 'deploy:stop-workers', ]); @@ -103,4 +104,8 @@ task('deploy:assets', function () { runLocally('npm i && npm run build'); }); +task('deploy:thumbnails', function () { + run('{{bin/console}} app:generate-thumbnails'); +}); + after('deploy:failed', 'deploy:unlock'); diff --git a/src/Command/GenerateThumbnailsCommand.php b/src/Command/GenerateThumbnailsCommand.php new file mode 100644 index 0000000..b1ac599 --- /dev/null +++ b/src/Command/GenerateThumbnailsCommand.php @@ -0,0 +1,66 @@ +entityManager + ->getRepository(Teamer::class) + ->createQueryBuilder('t') + ->select('t.id', 'p.filename') + ->innerJoin('t.photo', 'p') + ->getQuery() + ->getArrayResult() + ; + + $imagesCount = count($images); + + $io->info('Generating thumbnails for '.$imagesCount.' profile images...'); + + $progressbar = $io->createProgressBar($imagesCount); + $progressbar->start(); + + foreach ($images as $image) { + try { + $this->filterService->warmUpCache($image['filename'], 'thumbnail'); + $this->filterService->warmUpCache($image['filename'], 'profile'); + $this->cacheManager->getBrowserPath($image['filename'], 'thumbnail'); + $this->cacheManager->getBrowserPath($image['filename'], 'profile'); + } catch (\Exception $e) { + } + + $progressbar->advance(); + } + + $progressbar->finish(); + + return Command::SUCCESS; + } +} \ No newline at end of file