From bf62ccf9e9537cd2fd371e10c37417b743aa1183 Mon Sep 17 00:00:00 2001 From: tristan Date: Mon, 6 Apr 2026 13:31:33 +0200 Subject: [PATCH] refactor : rewrite MaintenanceToggleProcessor for Environment entity Co-Authored-By: Claude Sonnet 4.6 --- src/State/MaintenanceToggleProcessor.php | 43 ++++++------------------ 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/src/State/MaintenanceToggleProcessor.php b/src/State/MaintenanceToggleProcessor.php index 3bf4b16..a694651 100644 --- a/src/State/MaintenanceToggleProcessor.php +++ b/src/State/MaintenanceToggleProcessor.php @@ -6,42 +6,26 @@ namespace App\State; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProcessorInterface; -use App\ApiResource\ManagedApplication; -use Symfony\Component\DependencyInjection\Attribute\Autowire; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use App\Entity\Environment; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; final readonly class MaintenanceToggleProcessor implements ProcessorInterface { /** - * @param list $managedApplications + * @param Environment $data */ - public function __construct( - #[Autowire('%app.managed_applications%')] - private array $managedApplications, - ) {} - - /** - * @param ManagedApplication $data - */ - public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ManagedApplication + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): Environment { - $slug = $uriVariables['slug'] ?? ''; - $appConfig = null; + $maintenancePath = $data->getMaintenanceFilePath(); - foreach ($this->managedApplications as $app) { - if ($app['slug'] === $slug) { - $appConfig = $app; - break; - } + if (null === $maintenancePath) { + throw new BadRequestHttpException('Maintenance file path is not configured for this environment.'); } - if (null === $appConfig) { - throw new NotFoundHttpException(sprintf('Application "%s" not found.', $slug)); - } + $requestData = $context['request']?->toArray() ?? []; + $enableMaintenance = $requestData['maintenance'] ?? false; - $maintenancePath = $appConfig['maintenance_path']; - - if ($data->maintenance) { + if ($enableMaintenance) { $directory = dirname($maintenancePath); if (!is_dir($directory) && !mkdir($directory, 0755, true)) { @@ -57,11 +41,6 @@ final readonly class MaintenanceToggleProcessor implements ProcessorInterface } } - $dto = new ManagedApplication(); - $dto->slug = $appConfig['slug']; - $dto->name = $appConfig['name']; - $dto->maintenance = file_exists($maintenancePath); - - return $dto; + return $data; } }