diff --git a/src/Deblan/PowerDNS/Command/ZoneRemoveCommand.php b/src/Deblan/PowerDNS/Command/ZoneRemoveCommand.php new file mode 100644 index 0000000..c240c5d --- /dev/null +++ b/src/Deblan/PowerDNS/Command/ZoneRemoveCommand.php @@ -0,0 +1,59 @@ +setName('zone:remove') + ->setDescription('Remove a zone') + ->addArgument('zone_id', InputArgument::REQUIRED, 'Zone ID') + ->addOption('confirm', null, InputOption::VALUE_NONE, 'Confirmation') + ->setHelp("%command.name% + +By removing a zone, you will remove all associated versions and records!"); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + parent::execute($input, $output); + + $id = $this->getInput()->getArgument('zone_id'); + + $zone = ZoneQuery::create()->findOneById($id); + + if (null === $zone) { + $this->getOutput()->writeln('Zone not found.'); + + return; + } + + $confirm = $this->getInput()->getOption('confirm'); + + if (false === $confirm) { + $this->getOutput()->writeln('By removing this zone, you will remove all associated versions and records!'); + + $confirm = $this->getHelper('dialog')->askConfirmation($this->getOutput(), 'Do you confirm? [no] ', false); + } + + if ($confirm) { + $zone->delete(); + + $this->getOutput()->writeln('Zone removed.'); + } else { + $this->getOutput()->writeln('Aborted.'); + } + } +}