Remove zone record command

This commit is contained in:
Simon Vieille 2015-02-21 17:47:01 +01:00
parent 348c0301bd
commit 27624a9f0e
5 changed files with 72 additions and 2 deletions

View File

@ -30,7 +30,6 @@ class DomainRemoveCommand extends AbstractCommand
$name = $this->getInput()->getOption('name');
$id = $this->getInput()->getOption('id');
$id = $this->getInput()->getOption('id');
if (null === $name && null === $id) {
$this->getOutput()->writeln('<error>You must give a name or an id.</error>');

View File

@ -31,7 +31,7 @@ class ValidatorHelper extends AbstractHelper
{
return in_array($value, ['NATIVE', 'MASTER', 'SLAVE', 'SUPERSLAVE']);
}
public static function getName()
{
return 'validator';

View File

@ -56,6 +56,10 @@ class ZoneHelper extends AbstractHelper
return;
}
if ($this->getInput()->getOption('zversion') && $zoneVersion->getVersion() !== (int) $this->getInput()->getOption('zversion')) {
return;
}
$this->getOutput()->writeln($withIndent ? self::INDENT : '');
$this->getOutput()->writeln(sprintf(
'%s<info>Version</info>: <comment>%d</comment> - <info>Active</info>: %s',

View File

@ -18,6 +18,8 @@ class ZoneListCommand extends AbstractZoneCommand
->setName('zone:list')
->setDescription('List DNS zones')
->addOption('name', null, InputOption::VALUE_REQUIRED, '')
->addOption('id', null, InputOption::VALUE_REQUIRED, '')
->addOption('zversion', null, InputOption::VALUE_REQUIRED, '')
->setHelp("The <info>%command.name%</info> ");
}
@ -41,6 +43,10 @@ class ZoneListCommand extends AbstractZoneCommand
if ($this->getInput()->getOption('name')) {
$query->filterByName(sprintf('%%%s%%', $this->getInput()->getOption('name')));
}
if ($this->getInput()->getOption('id')) {
$query->filterById((int) $this->getInput()->getOption('id'));
}
return $query;
}

View File

@ -0,0 +1,61 @@
<?php
namespace Deblan\PowerDNS\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
use Deblan\Console\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputArgument;
use Deblan\PowerDNS\Model\ZoneRecordQuery;
use Symfony\Component\Console\Input\InputOption;
class ZoneRecordRemoveCommand extends AbstractCommand
{
protected function configure()
{
parent::configure();
$this
->setName('zone:record:remove')
->setDescription('Remove a zone record')
->addArgument('id', InputArgument::REQUIRED, 'ZONE_ID')
->addOption('confirm', null, InputOption::VALUE_NONE, '')
->setHelp("The <info>%command.name%</info> ");
}
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$id = (int) $this->getInput()->getArgument('id');
$zoneRecord = ZoneRecordQuery::create()->findOneById($id);
if (null === $zoneRecord) {
$this->getOutput()->writeln('<error>Zone record not found.</error>');
return;
}
if ($zoneRecord->getZoneVersion()->getIsActive()) {
$this->getOutput()->writeln('<error>You can not remove a zone record of an activated zone version.</error>');
return;
}
$confirm = $this->getInput()->getOption('confirm');
if (false === $confirm) {
$confirm = $this->getHelper('dialog')->askConfirmation($this->getOutput(), '<info>Do you confirm? [<comment>no</comment>] ', false);
}
if ($confirm) {
$zoneRecord->delete();
$this->getOutput()->writeln('<info>Zone record removed.</info>');
} else {
$this->getOutput()->writeln('<info>Aborted.</info>');
}
}
}