/**
  * sets the modification date
  */
 public function preUpdate(Domains $domain, PreUpdateEventArgs $event)
 {
     $domain->setModified(new \DateTime());
     if ($event->hasChangedField('name')) {
         $domain->setNeedsSoaUpdate(true);
     }
     return true;
 }
Esempio n. 2
0
 /**
  * @return array
  */
 public function toArray()
 {
     $map = array('name', 'type', 'content', 'ttl', 'prio', 'domain');
     $r = array();
     foreach ($map as $k) {
         if ($k == 'domain') {
             $r[$k] = $this->domain->getId();
         }
         $r[$k] = $this->{$k};
     }
     return $r;
 }
 /**
  * @covers SysEleven\PowerDnsBundle\Validator\Constraints\RecordValidator::_validatePtr
  * @covers SysEleven\PowerDnsBundle\Validator\Constraints\RecordValidator::_checkHostname
  * @covers SysEleven\PowerDnsBundle\Validator\Constraints\RecordValidator::_checkPtr
  */
 public function testValidatePtr()
 {
     /**
      * @type DomainWorkflow $workflow
      */
     $workflow = $this->container->get('syseleven.pdns.workflow.domains');
     /**
      * @type Domains $domainObj
      */
     $domainObj = $workflow->getRepository()->findOneBy(array());
     $recordObj = new Records();
     $recordObj->setDomain($domainObj);
     $recordObj->setName('bogus___.');
     $recordObj->setType('PTR');
     $recordObj->setContent('1_');
     $recordObj->setPrio(-1);
     $validator = $this->container->get('validator');
     $errors = $validator->validate($recordObj);
     $this->assertCount(3, $errors);
     $domainObj = new Domains();
     $domainObj->setName('1.1.1.in-addr.arpa');
     $domainObj->setType('NATIVE');
     $domainObj = $workflow->create($domainObj);
     $recordObj = new Records();
     $recordObj->setName('1.1.1.1.in-addr.arpa');
     $recordObj->setType('PTR');
     $recordObj->setContent('www.example.com');
     $recordObj->setDomain($domainObj);
     $errors = $validator->validate($recordObj);
     $this->assertCount(0, $errors);
 }
 public function loadMaster_de(ObjectManager $manager)
 {
     $domainObj = new Domains();
     $domainObj->setName('master.de');
     $domainObj->setType('MASTER');
     $manager->persist($domainObj);
     $manager->flush();
 }
 /**
  * Updates the soa record for the given domain
  * @param Domains $domainObj
  * @param null $serial
  * @return Records
  */
 public function updateSoa(Domains $domainObj, $serial = null)
 {
     if (!($soa = $domainObj->getSoa())) {
         $this->createSoa($domainObj);
     }
     /**
      * @type Soa $soaObj
      */
     $soaObj = $soa->getContent();
     if (is_null($serial) || !filter_var($serial, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)))) {
         $serial = strtotime('now');
     }
     $soaObj->setSerial($serial);
     $soa->setName($domainObj->getName());
     $soa->setContent($soaObj);
     $this->getDatabase()->persist($soa);
     $this->getDatabase()->flush();
     $this->getDatabase()->refresh($soa);
     return $soa;
 }
 public function testCreateForceIsDisabled()
 {
     try {
         $domainObj = new Domains();
         $domainObj->setName('foo.de');
         $this->workflow->create($domainObj, array(), true);
     } catch (\Exception $e) {
         $this->assertInstanceOf('SysEleven\\PowerDnsBundle\\Lib\\Exceptions\\ValidationException', $e);
         /**
          * @type ValidationException $e
          */
         $this->assertCount(2, $e->getErrors());
         $p = array();
         /**
          * @type \Symfony\Component\Validator\ConstraintViolation $error
          */
         foreach ($e->getErrors() as $error) {
             $p[] = $error->getPropertyPath();
         }
         $this->assertContains('name', $p);
         $this->assertContains('type', $p);
     }
 }