refs #2120. Remove pxe template when removed client

develop
Manuel Aranda Rosales 2025-05-30 12:14:36 +02:00
parent b86e51e1bb
commit de33d665de
1 changed files with 38 additions and 5 deletions

View File

@ -9,18 +9,32 @@ use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\Validator\ValidatorInterface;
use App\Controller\OgBoot\PxeBootFile\DeleteAction;
use App\Controller\OgDhcp\Subnet\DeleteHostAction;
use App\Dto\Input\ClientInput;
use App\Dto\Output\ClientOutput;
use App\Dto\Output\UserGroupOutput;
use App\Entity\OgLive;
use App\Entity\PxeTemplate;
use App\Repository\ClientRepository;
use App\Repository\MenuRepository;
use App\Repository\OgLiveRepository;
use App\Repository\PxeTemplateRepository;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
readonly class ClientProcessor implements ProcessorInterface
{
public function __construct(
private ClientRepository $clientRepository,
private MenuRepository $menuRepository,
private ValidatorInterface $validator
private ClientRepository $clientRepository,
private MenuRepository $menuRepository,
private PxeTemplateRepository $pxeTemplateRepository,
private OgLiveRepository $ogLiveRepository,
private ValidatorInterface $validator,
private DeleteHostAction $deleteHostAction,
private DeleteAction $deletePxeAction,
)
{
}
@ -55,6 +69,8 @@ readonly class ClientProcessor implements ProcessorInterface
}
$defaultMenu = $this->menuRepository->findOneBy(['isDefault' => true]);
$defaultPxe = $this->pxeTemplateRepository->findOneBy(['isDefault' => true]);
$defaultPxeOgLive = $this->ogLiveRepository->findOneBy(['isDefault' => true]);
$client = $data->createOrUpdateEntity($entity);
@ -62,16 +78,33 @@ readonly class ClientProcessor implements ProcessorInterface
$client->setMenu($defaultMenu);
}
if ($defaultPxe) {
$client->setTemplate($defaultPxe);
}
if ($defaultPxeOgLive) {
$client->setOgLive($defaultPxeOgLive);
}
$this->validator->validate($client);
$this->clientRepository->save($client);
return new ClientOutput($client);
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
{
$user = $this->clientRepository->findOneByUuid($uriVariables['uuid']);
$this->clientRepository->delete($user);
$client = $this->clientRepository->findOneByUuid($uriVariables['uuid']);
$this->clientRepository->delete($client);
$this->deleteHostAction->__invoke($client->getSubnet(), $client->getUuid());
$this->deletePxeAction->__invoke($client->getUuid());
return null;
}