refs #2133. CHanged PXE template
parent
7d59467acc
commit
64eeb5c88e
|
@ -4,8 +4,11 @@ namespace App\EventSubscriber;
|
|||
|
||||
use ApiPlatform\Symfony\EventListener\EventPriorities;
|
||||
use App\Controller\OgBoot\PxeBootFile\PostAction;
|
||||
use App\Controller\OgDhcp\Subnet\PutHostAction;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\PxeTemplate;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\ViewEvent;
|
||||
|
@ -18,7 +21,9 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|||
final readonly class ClientSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private PostAction $postAction,
|
||||
private PutHostAction $putHostAction,
|
||||
)
|
||||
{
|
||||
|
||||
|
@ -49,14 +54,19 @@ final readonly class ClientSubscriber implements EventSubscriberInterface
|
|||
/** @var Client $client */
|
||||
$client = $clientOutput->getEntity();
|
||||
|
||||
$template = !$client->getTemplate() ?
|
||||
$template = $client->getTemplate() ?
|
||||
$client->getTemplate() :
|
||||
$client->getOrganizationalUnit()?->getNetworkSettings()?->getPxeTemplate();
|
||||
|
||||
if ($template === null) {
|
||||
return;
|
||||
$template = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['isDefault' => true]);
|
||||
|
||||
if ($template === null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->postAction->__invoke($client, $template);
|
||||
$this->putHostAction->__invoke($client->getMac(), $client);
|
||||
}
|
||||
}
|
|
@ -9,8 +9,8 @@ use Symfony\Component\Validator\ConstraintValidator;
|
|||
|
||||
class OrganizationalUnitMulticastPortValidator extends ConstraintValidator
|
||||
{
|
||||
CONST int minPort = 9000;
|
||||
CONST int maxPort = 9050;
|
||||
public const int minPort = 9000;
|
||||
public const int maxPort = 9098;
|
||||
|
||||
public function validate($value, Constraint $constraint): void
|
||||
{
|
||||
|
@ -18,9 +18,14 @@ class OrganizationalUnitMulticastPortValidator extends ConstraintValidator
|
|||
return;
|
||||
}
|
||||
|
||||
if (!(self::minPort <= $value) && ($value <= self::maxPort)) {
|
||||
if ($value % 2 !== 0) {
|
||||
$this->context->buildViolation('El puerto debe ser un número par y encontrarse entre el 9000 y el 9098.')->addViolation();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value < self::minPort || $value > self::maxPort) {
|
||||
$this->context->buildViolation($constraint->message)->addViolation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue