feat: generate image thumbnails after deployment
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Teamer;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
|
||||
use Liip\ImagineBundle\Service\FilterService;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:generate-thumbnails',
|
||||
description: 'Generates thumbnails of profile images',
|
||||
)]
|
||||
class GenerateThumbnailsCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly CacheManager $cacheManager,
|
||||
private readonly FilterService $filterService,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$images = $this
|
||||
->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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user