|
@@ -8,6 +8,7 @@ use HostBundle\Traits\DHCPOptionTrait;
|
|
|
use HostBundle\Utils\HostStatus;
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
+use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|
|
use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
|
|
|
use WorkflowBundle\Entity\Traits\WorkflowTrait;
|
|
|
|
|
@@ -16,7 +17,8 @@ use WorkflowBundle\Entity\Traits\WorkflowTrait;
|
|
|
* @ORM\HasLifecycleCallbacks
|
|
|
*
|
|
|
* @UniqueEntity("mac")
|
|
|
- * @UniqueEntity("options.fixed_address")
|
|
|
+ *
|
|
|
+ * @Assert\Callback("validateFixedAddress")
|
|
|
*/
|
|
|
class Host implements WorkflowInterface
|
|
|
{
|
|
@@ -230,5 +232,26 @@ class Host implements WorkflowInterface
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ExecutionContextInterface $context
|
|
|
+ */
|
|
|
+ public function validateFixedAddress(ExecutionContextInterface $context)
|
|
|
+ {
|
|
|
+ global $kernel;
|
|
|
+
|
|
|
+ $em = $kernel->getContainer()->get('doctrine.orm.entity_manager');
|
|
|
+ $hostRepository = $em->getRepository(self::class);
|
|
|
+ $hosts = $hostRepository->findAll();
|
|
|
+ $options = json_decode($this->getOptions(), true);
|
|
|
+ $fixedAddress = isset($options['fixed_address']) ? $options['fixed_address'] : $this->getFixedAddress();
|
|
|
+ $fixedAddress = $fixedAddress ?: '';
|
|
|
+ foreach ($hosts as $host) {
|
|
|
+ if ($host->getId() != $this->id && $fixedAddress === $host->getFixedAddress()) {
|
|
|
+ $context->addViolation('options.fixed_address.not_unique');
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|