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(); }
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())); }