setName('domain:remove')
->setDescription('Remove a domain')
->addOption('name', null, InputOption::VALUE_REQUIRED, 'Domain name')
->addOption('id', null, InputOption::VALUE_REQUIRED, 'Domain ID')
->addOption('confirm', null, InputOption::VALUE_NONE, 'Confirmation')
->setHelp("%command.name%
You can use --name or --id to identify the domain to remove.
By removing a domain, you will remove all associated records!");
}
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$name = $this->getInput()->getOption('name');
$id = $this->getInput()->getOption('id');
if (null === $name && null === $id) {
$this->getOutput()->writeln('You must give a name or an id.');
return;
}
if ($name) {
$domain = $this->getQuery()->findOneByName($name);
} else {
$domain = $this->getQuery()->findOneById($id);
}
if (null === $domain) {
$this->getOutput()->writeln('Domain not found.');
return;
}
$confirm = $this->getInput()->getOption('confirm');
if (false === $confirm) {
$this->getOutput()->writeln('By removing this domain, you will remove all associated records!');
$confirm = $this->getHelper('dialog')->askConfirmation($this->getOutput(), 'Do you confirm? [no] ', false);
}
if ($confirm) {
$domain->delete();
$this->getOutput()->writeln('Domain removed.');
} else {
$this->getOutput()->writeln('Aborted.');
}
}
protected function getQuery()
{
return DomainQuery::create();
}
}