From b3c76e4bec7629b1b08852099f714baf9a7ecf3c Mon Sep 17 00:00:00 2001 From: Serreau Jovann Date: Thu, 22 Jan 2026 21:47:07 +0100 Subject: [PATCH] =?UTF-8?q?```=20=E2=9C=A8=20feat(cloudflare):=20Ajoute=20?= =?UTF-8?q?la=20commande=20pour=20purger=20le=20cache=20Cloudflare.=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(maintenance):=20D=C3=A9commente=20le=20liste?= =?UTF-8?q?ner=20de=20maintenance.=20=E2=9A=99=EF=B8=8F=20chore(workflows)?= =?UTF-8?q?:=20Ajoute=20la=20purge=20de=20cache=20Cloudflare=20au=20workfl?= =?UTF-8?q?ow.=20```?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/install-deps.yml | 2 +- src/Command/PurgeCommand.php | 60 ++++++++++++++++++++++++++++ src/Security/MaintenanceListener.php | 4 +- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/Command/PurgeCommand.php diff --git a/.gitea/workflows/install-deps.yml b/.gitea/workflows/install-deps.yml index 775823c..3b12e6c 100644 --- a/.gitea/workflows/install-deps.yml +++ b/.gitea/workflows/install-deps.yml @@ -32,4 +32,4 @@ jobs: key: ${{ secrets.SSH_PRIVATE_KEY }} port: 22 script: | - cd /var/www/ludikevent-intranet && php bin/console app:maintenance on && git pull && sh ./update.sh && php bin/console app:maintenance off + cd /var/www/ludikevent-intranet && php bin/console app:maintenance on && git pull && sh ./update.sh && php bin/console app:maintenance off && php bin/console app:purge-cloudflare diff --git a/src/Command/PurgeCommand.php b/src/Command/PurgeCommand.php new file mode 100644 index 0000000..1ec4e42 --- /dev/null +++ b/src/Command/PurgeCommand.php @@ -0,0 +1,60 @@ +httpClient = $httpClient; + $this->cloudflareZoneId = $cloudflareZoneId; + $this->cloudflareApiToken = $cloudflareApiToken; + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $response = $this->httpClient->request('POST', "https://api.cloudflare.com/client/v4/zones/{$this->cloudflareZoneId}/purge_cache", [ + 'headers' => [ + 'Authorization' => 'Bearer ' . $this->cloudflareApiToken, + 'Content-Type' => 'application/json', + ], + 'json' => [ + 'purge_everything' => true, // C'est ici que l'on vide le domaine entier + ], + ]); + + $result = $response->toArray(); + + if ($result['success']) { + $io->success('Le cache de reservation.ludikevent.fr a été entièrement vidé.'); + return Command::SUCCESS; + } + + $io->error('Erreur Cloudflare : ' . $result['errors'][0]['message']); + return Command::FAILURE; + } +} diff --git a/src/Security/MaintenanceListener.php b/src/Security/MaintenanceListener.php index 0a87ed1..0a4ff40 100644 --- a/src/Security/MaintenanceListener.php +++ b/src/Security/MaintenanceListener.php @@ -19,7 +19,7 @@ class MaintenanceListener } public function onKernelRequest(RequestEvent $event) - {/* + { if (!$event->isMainRequest()) { return; } @@ -32,6 +32,6 @@ class MaintenanceListener } $content = $this->twig->render('security/maintenance.twig'); - $event->setResponse(new Response($content, 503));*/ + $event->setResponse(new Response($content, 503)); } }