diff --git a/src/Deblan/PowerDNS/Command/AboutCommand.php b/src/Deblan/PowerDNS/Command/AboutCommand.php index 7868f3a..86fdb69 100644 --- a/src/Deblan/PowerDNS/Command/AboutCommand.php +++ b/src/Deblan/PowerDNS/Command/AboutCommand.php @@ -4,8 +4,6 @@ namespace Deblan\PowerDNS\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Command\Command; class AboutCommand extends Command @@ -20,11 +18,11 @@ class AboutCommand extends Command protected function execute(InputInterface $input, OutputInterface $output) { - $output->writeln(<<writeln(<<PDNS-CONSOLE PDNS-Console provided a CLI to manage PowerDNS application and improved it by -adding a powerfull DNS zone versionning. +adding a powerfull DNS zone versionning. AUTHOR diff --git a/src/Deblan/PowerDNS/Command/DomainAddCommand.php b/src/Deblan/PowerDNS/Command/DomainAddCommand.php index 6c274d1..42f882d 100644 --- a/src/Deblan/PowerDNS/Command/DomainAddCommand.php +++ b/src/Deblan/PowerDNS/Command/DomainAddCommand.php @@ -30,13 +30,13 @@ class DomainAddCommand extends AbstractCommand parent::execute($input, $output); $name = $this->getInput()->getOption('name'); + $master = $this->getInput()->getOption('master'); + $type = $this->getInput()->getOption('type'); while (null === $name || trim($name) === '') { $name = $this->getHelper('dialog')->ask($this->getOutput(), 'Name: ', null); } - $master = $this->getInput()->getOption('master'); - if ($master === 'null') { $master = null; } elseif (null === $master || trim($master) === '') { @@ -44,8 +44,6 @@ class DomainAddCommand extends AbstractCommand $master = empty($response) ? null : $response; } - $type = $this->getInput()->getOption('type'); - if ($type === 'null') { $type = null; } elseif (null === $type) { diff --git a/src/Deblan/PowerDNS/Command/DomainRemoveCommand.php b/src/Deblan/PowerDNS/Command/DomainRemoveCommand.php index 75ceb19..f19a5a8 100644 --- a/src/Deblan/PowerDNS/Command/DomainRemoveCommand.php +++ b/src/Deblan/PowerDNS/Command/DomainRemoveCommand.php @@ -45,7 +45,7 @@ class DomainRemoveCommand extends AbstractCommand } if (null === $domain) { - $this->getOutput()->writeln('No domain found.'); + $this->getOutput()->writeln('Domain not found.'); return; } diff --git a/src/Deblan/PowerDNS/Command/ZoneAssignCommand.php b/src/Deblan/PowerDNS/Command/ZoneAssignCommand.php new file mode 100644 index 0000000..e93616f --- /dev/null +++ b/src/Deblan/PowerDNS/Command/ZoneAssignCommand.php @@ -0,0 +1,52 @@ +setName('zone:assign') + ->setDescription('Add a domain') + ->addArgument('zone_id', InputArgument::REQUIRED, 'ZONE_ID') + ->addArgument('domain_id', InputArgument::REQUIRED, 'ZONE_ID') + ->setHelp("The %command.name% "); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + parent::execute($input, $output); + + $zoneId = (int) $this->getInput()->getArgument('zone_id'); + $zone = ZoneQuery::create()->findOneById($zoneId); + $domain = DomainQuery::create()->findOneById((int) $this->getInput()->getArgument('domain_id')); + + if ($zoneId !== 0 && null === $zone) { + $this->getOutput()->writeln('Zone not found.'); + + return; + } + + if (null === $domain) { + $this->getOutput()->writeln('Domain not found.'); + + return; + } + + $domain->setZone($zone)->save(); + + $this->getOutput()->writeln('Domain zone updated.'); + } +} diff --git a/src/Deblan/PowerDNS/Command/ZoneVersionActiveCommand.php b/src/Deblan/PowerDNS/Command/ZoneVersionActiveCommand.php new file mode 100644 index 0000000..90a748f --- /dev/null +++ b/src/Deblan/PowerDNS/Command/ZoneVersionActiveCommand.php @@ -0,0 +1,56 @@ +setName('zone:version:active') + ->setDescription('Active a zone version') + ->addArgument('zone_id', InputArgument::REQUIRED, 'ZONE_ID') + ->addArgument('version', InputArgument::REQUIRED, 'VERSION') + ->setHelp("The %command.name% "); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + parent::execute($input, $output); + + $zoneId = (int) $this->getInput()->getArgument('zone_id'); + $version = (int) $this->getInput()->getArgument('version'); + + $zoneVersionCount = ZoneVersionQuery::create() + ->filterByZoneId($zoneId) + ->filterByVersion($version) + ->count(); + + if (0 === $zoneVersionCount) { + $this->getOutput()->writeln('Zone version not found.'); + + return; + } + + foreach (ZoneVersionQuery::create()->findByZoneId($zoneId) as $zoneVersion) { + if ($zoneVersion->getVersion() === $version) { + $zoneVersion->setIsActive(true); + } else { + $zoneVersion->setIsActive(false); + } + + $zoneVersion->save(); + } + + $this->getOutput()->writeln('Zone version activated.'); + } +} diff --git a/src/Deblan/PowerDNS/Command/ZoneVersionUnactiveCommand.php b/src/Deblan/PowerDNS/Command/ZoneVersionUnactiveCommand.php new file mode 100644 index 0000000..284bccf --- /dev/null +++ b/src/Deblan/PowerDNS/Command/ZoneVersionUnactiveCommand.php @@ -0,0 +1,48 @@ +setName('zone:version:unactive') + ->setDescription('Unactive a zone version') + ->addArgument('zone_id', InputArgument::REQUIRED, 'ZONE_ID') + ->addArgument('version', InputArgument::REQUIRED, 'VERSION') + ->setHelp("The %command.name% "); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + parent::execute($input, $output); + + $zoneId = (int) $this->getInput()->getArgument('zone_id'); + $version = (int) $this->getInput()->getArgument('version'); + + $zoneVersion = ZoneVersionQuery::create() + ->filterByZoneId($zoneId) + ->filterByVersion($version) + ->findOne(); + + if (null === $zoneVersion) { + $this->getOutput()->writeln('Zone version not found.'); + + return; + } + + $zoneVersion->setIsActive(false)->save(); + + $this->getOutput()->writeln('Zone version unactivated.'); + } +}