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)); } }