/**
  * @Template()
  * @Route("/record/new/{id}")
  */
 public function newAction($id)
 {
     $em = $this->getDoctrine()->getEntityManager();
     $domain = $em->find('HolloBindBundle:Domain', $id);
     $record_a = new \Hollo\BindBundle\Entity\Record();
     $record_cname = new \Hollo\BindBundle\Entity\Record();
     $record_mx = new \Hollo\BindBundle\Entity\Record();
     $record_a->setAddress($domain->getAddress());
     $record_cname->setAddress($domain->getDomain() . '.');
     $record_mx->setAddress('mail');
     $record_mx->setPriority(10);
     $form_a = $this->createForm(new \Hollo\BindBundle\Form\RecordA(), $record_a);
     $form_cname = $this->createForm(new \Hollo\BindBundle\Form\RecordCname(), $record_cname);
     $form_mx = $this->createForm(new \Hollo\BindBundle\Form\RecordMx(), $record_mx);
     if ($this->getRequest()->getMethod() == 'POST') {
         if ($this->getRequest()->get($form_a->getName())) {
             $form_a->bindRequest($this->getRequest());
             if ($form_a->isValid()) {
                 $record_a->setType('A');
                 $record_a->setDomain($domain);
                 $em->persist($record_a);
                 $em->flush();
                 $event = new \Hollo\BindBundle\Event\FilterRecordEvent($record_a);
                 $this->get('event_dispatcher')->dispatch(\Hollo\BindBundle\Event\Events::onRecordAdd, $event);
                 $this->get('session')->setFlash('notice', 'Your data has been saved.');
                 return $this->redirect($this->generateUrl('hollo_bind_domain_index', array('id' => $domain->getId())));
             }
         }
         if ($this->getRequest()->get($form_cname->getName())) {
             $form_cname->bindRequest($this->getRequest());
             if ($form_cname->isValid()) {
                 $record_cname->setType('CNAME');
                 $record_cname->setDomain($domain);
                 $em->persist($record_cname);
                 $em->flush();
                 $event = new \Hollo\BindBundle\Event\FilterRecordEvent($record_cname);
                 $this->get('event_dispatcher')->dispatch(\Hollo\BindBundle\Event\Events::onRecordAdd, $event);
                 $this->get('session')->setFlash('notice', 'Your data has been saved.');
                 return $this->redirect($this->generateUrl('hollo_bind_domain_index', array('id' => $domain->getId())));
             }
         }
         if ($this->getRequest()->get($form_mx->getName())) {
             $form_mx->bindRequest($this->getRequest());
             if ($form_mx->isValid()) {
                 $record_mx->setType('MX');
                 $record_mx->setDomain($domain);
                 $em->persist($record_mx);
                 $em->flush();
                 $event = new \Hollo\BindBundle\Event\FilterRecordEvent($record_mx);
                 $this->get('event_dispatcher')->dispatch(\Hollo\BindBundle\Event\Events::onRecordAdd, $event);
                 $this->get('session')->setFlash('notice', 'Your data has been saved.');
                 return $this->redirect($this->generateUrl('hollo_bind_domain_index', array('id' => $domain->getId())));
             }
         }
     }
     return array('domain' => $domain, 'form_a' => $form_a->createView(), 'form_cname' => $form_cname->createView(), 'form_mx' => $form_mx->createView());
 }
 public function onDomainAdd(\Hollo\BindBundle\Event\FilterDomainEvent $event)
 {
     $domain = $event->getDomain();
     foreach ($this->nameservers as $ns) {
         $record = new \Hollo\BindBundle\Entity\Record();
         $record->setDomain($domain);
         $record->setAddress($ns);
         $record->setType('NS');
         $this->em->persist($record);
     }
     $this->em->flush();
 }
Example #3
0
 private function buildDomain($zone)
 {
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $domain = new \Hollo\BindBundle\Entity\Domain();
     $domain->setDomain($zone['domain']);
     $domain->setDescription('Migrated');
     if (preg_match("/arpa\$/", $zone['domain'])) {
         $domain->setType('ptr');
     } else {
         $domain->setType('domain');
     }
     $em->persist($domain);
     foreach ($zone as $type => $records) {
         if (is_array($records)) {
             foreach ($records as $r) {
                 switch ($type) {
                     case 'A':
                     case 'PTR':
                         $record = new \Hollo\BindBundle\Entity\Record();
                         $record->setName($r['name']);
                         $record->setAddress($r['destination']);
                         $record->setType($type);
                         $record->setDomain($domain);
                         $em->persist($record);
                         break;
                     case 'CNAME':
                         $name = preg_replace("/\\." . $domain->getDomain() . "\\.\$/", "", $r['name']);
                         $record = new \Hollo\BindBundle\Entity\Record();
                         $record->setName($name);
                         $record->setAddress($r['destination']);
                         $record->setType($type);
                         $record->setDomain($domain);
                         $em->persist($record);
                         break;
                     case 'MX':
                         $record = new \Hollo\BindBundle\Entity\Record();
                         $record->setPriority($r['priority']);
                         $record->setAddress($r['destination']);
                         $record->setType($type);
                         $record->setDomain($domain);
                         $em->persist($record);
                         break;
                 }
             }
         }
     }
     return $domain;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $domain = $input->getArgument('domain');
     $address = $input->getArgument('address');
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $domain = $em->getRepository('HolloBindBundle:Domain')->findOneBy(array('domain' => $domain));
     $record = new \Hollo\BindBundle\Entity\Record();
     $record->setDomain($domain);
     $record->setName($name);
     $record->setAddress($address);
     $record->setType('A');
     $em->persist($record);
     $em->flush();
     $event = new \Hollo\BindBundle\Event\FilterRecordEvent($record);
     $this->getContainer()->get('event_dispatcher')->dispatch(\Hollo\BindBundle\Event\Events::onRecordAdd, $event);
     $output->writeln(sprintf('Added record <comment>%s</comment>', $name . '.' . $domain->getDomain()));
 }