From 17cf110cf0d2b431e854ae10c6ada92e29177389 Mon Sep 17 00:00:00 2001 From: Serreau Jovann Date: Wed, 28 Jan 2026 14:24:41 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(ansible):=20Ajoute=20la=20t?= =?UTF-8?q?=C3=A2che=20pour=20ex=C3=A9cuter=20app:images:warmup=20et=20la?= =?UTF-8?q?=20commande=20associ=C3=A9e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible/playbook.yml | 5 ++ src/Command/AppWarmupImagesCommand.php | 111 +++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 src/Command/AppWarmupImagesCommand.php diff --git a/ansible/playbook.yml b/ansible/playbook.yml index ace6da1..c853343 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -224,6 +224,11 @@ become: false args: chdir: "{{ path }}" + - name: Exécuter app:images:warmup dans le répertoire de l application + ansible.builtin.command: php bin/console app:images:warmup + become: false + args: + chdir: "{{ path }}" when: ansible_os_family == "Debian" # Added a when condition here, often missed - name: Exécuter pwa:compile dans le répertoire de l application ansible.builtin.command: php -d memory_limit=-1 bin/console pwa:compile diff --git a/src/Command/AppWarmupImagesCommand.php b/src/Command/AppWarmupImagesCommand.php new file mode 100644 index 0000000..b7196e0 --- /dev/null +++ b/src/Command/AppWarmupImagesCommand.php @@ -0,0 +1,111 @@ +productRepository = $productRepository; + $this->optionsRepository = $optionsRepository; + $this->cacheManager = $cacheManager; + $this->dataManager = $dataManager; + $this->filterManager = $filterManager; + $this->uploaderHelper = $uploaderHelper; + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $products = $this->productRepository->findAll(); + $options = $this->optionsRepository->findAll(); + + $io->title('Régénération FORCÉE du cache LiipImagine'); + $io->note('Le cache existant sera supprimé avant chaque génération.'); + + $io->section('Produits'); + $this->processCollection($products, 'imageFile', $io); + + $io->section('Options'); + $this->processCollection($options, 'imageFile', $io); + + $io->success('Toutes les images ont été régénérées avec succès.'); + + return Command::SUCCESS; + } + + private function processCollection(array $entities, string $fieldName, SymfonyStyle $io): void + { + $progressBar = $io->createProgressBar(count($entities) * count(self::FILTERS)); + $progressBar->start(); + + foreach ($entities as $entity) { + $assetPath = $this->uploaderHelper->asset($entity, $fieldName); + + if (!$assetPath) { + $progressBar->advance(count(self::FILTERS)); + continue; + } + + // Nettoyage du path (on retire le / initial) + $path = ltrim(parse_url($assetPath, PHP_URL_PATH), '/'); + + foreach (self::FILTERS as $filter) { + try { + // 1. On supprime le cache existant pour ce filtre spécifique + $this->cacheManager->remove($path, $filter); + + // 2. On récupère la source originale + $binary = $this->dataManager->find($filter, $path); + // 3. On applique les filtres et on stocke le nouveau résultat + $this->cacheManager->store( + $this->filterManager->applyFilter($binary, $filter), + $path, + $filter + ); + } catch (\Exception $e) { + dd($e); + // Erreur ignorée (souvent fichier source manquant sur le disque) + } + $progressBar->advance(); + } + } + + $progressBar->finish(); + $io->newLine(2); + } +}