refs #2120. Remove pxe template when removed client
parent
b86e51e1bb
commit
de33d665de
|
@ -9,18 +9,32 @@ use ApiPlatform\Metadata\Post;
|
||||||
use ApiPlatform\Metadata\Put;
|
use ApiPlatform\Metadata\Put;
|
||||||
use ApiPlatform\State\ProcessorInterface;
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
use ApiPlatform\Validator\ValidatorInterface;
|
use ApiPlatform\Validator\ValidatorInterface;
|
||||||
|
use App\Controller\OgBoot\PxeBootFile\DeleteAction;
|
||||||
|
use App\Controller\OgDhcp\Subnet\DeleteHostAction;
|
||||||
use App\Dto\Input\ClientInput;
|
use App\Dto\Input\ClientInput;
|
||||||
use App\Dto\Output\ClientOutput;
|
use App\Dto\Output\ClientOutput;
|
||||||
use App\Dto\Output\UserGroupOutput;
|
use App\Dto\Output\UserGroupOutput;
|
||||||
|
use App\Entity\OgLive;
|
||||||
|
use App\Entity\PxeTemplate;
|
||||||
use App\Repository\ClientRepository;
|
use App\Repository\ClientRepository;
|
||||||
use App\Repository\MenuRepository;
|
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
|
readonly class ClientProcessor implements ProcessorInterface
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private ClientRepository $clientRepository,
|
private ClientRepository $clientRepository,
|
||||||
private MenuRepository $menuRepository,
|
private MenuRepository $menuRepository,
|
||||||
private ValidatorInterface $validator
|
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]);
|
$defaultMenu = $this->menuRepository->findOneBy(['isDefault' => true]);
|
||||||
|
$defaultPxe = $this->pxeTemplateRepository->findOneBy(['isDefault' => true]);
|
||||||
|
$defaultPxeOgLive = $this->ogLiveRepository->findOneBy(['isDefault' => true]);
|
||||||
|
|
||||||
$client = $data->createOrUpdateEntity($entity);
|
$client = $data->createOrUpdateEntity($entity);
|
||||||
|
|
||||||
|
@ -62,16 +78,33 @@ readonly class ClientProcessor implements ProcessorInterface
|
||||||
$client->setMenu($defaultMenu);
|
$client->setMenu($defaultMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($defaultPxe) {
|
||||||
|
$client->setTemplate($defaultPxe);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($defaultPxeOgLive) {
|
||||||
|
$client->setOgLive($defaultPxeOgLive);
|
||||||
|
}
|
||||||
|
|
||||||
$this->validator->validate($client);
|
$this->validator->validate($client);
|
||||||
$this->clientRepository->save($client);
|
$this->clientRepository->save($client);
|
||||||
|
|
||||||
return new ClientOutput($client);
|
return new ClientOutput($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
* @throws ServerExceptionInterface
|
||||||
|
* @throws RedirectionExceptionInterface
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
*/
|
||||||
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
|
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||||
{
|
{
|
||||||
$user = $this->clientRepository->findOneByUuid($uriVariables['uuid']);
|
$client = $this->clientRepository->findOneByUuid($uriVariables['uuid']);
|
||||||
$this->clientRepository->delete($user);
|
$this->clientRepository->delete($client);
|
||||||
|
|
||||||
|
$this->deleteHostAction->__invoke($client->getSubnet(), $client->getUuid());
|
||||||
|
$this->deletePxeAction->__invoke($client->getUuid());
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue