|
@@ -19,6 +19,7 @@ use WorkflowBundle\Entity\Traits\WorkflowTrait;
|
|
|
* @UniqueEntity("mac")
|
|
|
*
|
|
|
* @Assert\Callback("validateFixedAddress")
|
|
|
+ * @Assert\Callback("validateHostType")
|
|
|
*/
|
|
|
class Host implements WorkflowInterface
|
|
|
{
|
|
@@ -106,7 +107,7 @@ class Host implements WorkflowInterface
|
|
|
/**
|
|
|
* @var integer $ipv4Address
|
|
|
*
|
|
|
- * @ORM\Column(name="ipv4_address", type="integer", nullable=true)
|
|
|
+ * @ORM\Column(name="ipv4_address", type="integer", nullable=true, options={"unsigned":true})
|
|
|
*/
|
|
|
protected $ipv4Address;
|
|
|
|
|
@@ -267,31 +268,6 @@ class Host implements WorkflowInterface
|
|
|
return $this->associatedHosts;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param ExecutionContextInterface $context
|
|
|
- */
|
|
|
- public function validateFixedAddress(ExecutionContextInterface $context)
|
|
|
- {
|
|
|
- global $kernel;
|
|
|
-
|
|
|
- if (!$kernel->getContainer()) {
|
|
|
- // fix para los tests
|
|
|
- return;
|
|
|
- }
|
|
|
- $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;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @return integer
|
|
|
*/
|
|
@@ -343,5 +319,45 @@ class Host implements WorkflowInterface
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ExecutionContextInterface $context
|
|
|
+ */
|
|
|
+ public function validateFixedAddress(ExecutionContextInterface $context)
|
|
|
+ {
|
|
|
+ global $kernel;
|
|
|
+
|
|
|
+ if (!$kernel->getContainer()) {
|
|
|
+ // fix para los tests
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Si el host type es distinto de cablemodem tiene que tener host asociado
|
|
|
+ * @param ExecutionContextInterface $context
|
|
|
+ */
|
|
|
+ public function validateHostType(ExecutionContextInterface $context)
|
|
|
+ {
|
|
|
+ $hostType = $this->hostType;
|
|
|
+ if (!$hostType) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ($hostType->getName() !== 'Cablemodem' && is_null($this->host)) {
|
|
|
+ $context->addViolation('host.host_null');
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|