diff --git a/app/console b/app/console
index 76c06d1..a6f36a0 100755
--- a/app/console
+++ b/app/console
@@ -4,6 +4,7 @@
require_once __DIR__ . '/../vendor/autoload.php';
use Deblan\Console\Application;
+use Deblan\Console\Command\Input\Input;
$app = new Application();
@@ -12,4 +13,4 @@ $app->chdir(__DIR__.'/../');
$app->addCommandsPath('src/Deblan/PowerDNS/Command/', 'Deblan\\PowerDNS\\Command');
$app->initPropel();
$app->loadCommands();
-$app->run();;
+$app->run(new Input());
diff --git a/src/Deblan/Console/Command/AbstractCommand.php b/src/Deblan/Console/Command/AbstractCommand.php
index 6c2cd51..d849d38 100644
--- a/src/Deblan/Console/Command/AbstractCommand.php
+++ b/src/Deblan/Console/Command/AbstractCommand.php
@@ -5,6 +5,8 @@ namespace Deblan\Console\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
+use Deblan\PowerDNS\Command\Helper\ZoneHelper;
+use Deblan\PowerDNS\Command\Helper\DomainHelper;
abstract class AbstractCommand extends Command
{
@@ -12,6 +14,19 @@ abstract class AbstractCommand extends Command
protected $output;
+ public function getHelper($helper)
+ {
+ if ($helper === 'zone') {
+ return ZoneHelper::getInstance($this->getInput(), $this->getOutput());
+ }
+
+ if ($helper === 'domain') {
+ return DomainHelper::getInstance($this->getInput(), $this->getOutput());
+ }
+
+ throw new \InvalidArgumentException(sprintf('Invalid helper "%s"', $helper));
+ }
+
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setInput($input);
diff --git a/src/Deblan/Console/Command/Helper/AbstractHelper.php b/src/Deblan/Console/Command/Helper/AbstractHelper.php
new file mode 100644
index 0000000..1d16f39
--- /dev/null
+++ b/src/Deblan/Console/Command/Helper/AbstractHelper.php
@@ -0,0 +1,53 @@
+setInput($input)
+ ->setOutput($output);
+
+ self::$instances[$name] = $instance;
+ }
+
+ return self::$instances[$name];
+ }
+
+ public function setInput(InputInterface $input)
+ {
+ $this->input = $input;
+
+ return $this;
+ }
+
+ public function getInput()
+ {
+ return $this->input;
+ }
+
+ public function setOutput(OutputInterface $output)
+ {
+ $this->output = $output;
+
+ return $this;
+ }
+
+ public function getOutput()
+ {
+ return $this->output;
+ }
+
+ abstract public static function getName();
+}
diff --git a/src/Deblan/Console/Command/Input/Input.php b/src/Deblan/Console/Command/Input/Input.php
new file mode 100644
index 0000000..5ae10f3
--- /dev/null
+++ b/src/Deblan/Console/Command/Input/Input.php
@@ -0,0 +1,26 @@
+addOption('active', null, InputOption::VALUE_NONE, '')
->addOption('no-active', null, InputOption::VALUE_NONE, '');
}
-
- protected function showZone(Zone $zone, $key)
- {
- $this->getOutput()->writeln(sprintf('%s.', $zone->getName()));
-
- if ($zone->getDescription()) {
- $this->getOutput()->writeln($zone->getDescription());
- }
-
- foreach ($zone->getZoneVersions() as $key => $zoneVersion) {
- $this->showZoneVersion($zoneVersion, $key);
- }
- }
-
- protected function showZoneVersion(ZoneVersion $zoneVersion, $key)
- {
- if ($this->getInput()->getOption('active') && false === $zoneVersion->getIsActive()) {
- return;
- }
-
- if ($this->getInput()->getOption('no-active') && true === $zoneVersion->getIsActive()) {
- return;
- }
-
- $this->getOutput()->writeln('');
- $this->getOutput()->writeln(sprintf(
- 'Version: %d - Active: %s',
- $zoneVersion->getVersion(),
- $zoneVersion->getIsActive() ? 'Yes' : 'No'
- ));
-
- $this->showZoneVersionRecords($zoneVersion);
- }
-
- protected function showZoneVersionRecords(ZoneVersion $zoneVersion)
- {
- $this->getOutput()->writeln('');
- $this->getOutput()->writeln(' ID | NAME | TYPE | TTL | PRIO | CONTENT');
- $this->getOutput()->writeln('----------------------------------------------------------------------');
-
- foreach ($zoneVersion->getZoneRecords() as $zoneRecord) {
- $this->getOutput()->writeln(sprintf(
- '%5d | %s | %s | %s | %s | %s',
- $zoneRecord->getId(),
- str_pad($zoneRecord->getName(), 21),
- str_pad($zoneRecord->getType(), 9),
- str_pad($zoneRecord->getTtl(), 6),
- str_pad($zoneRecord->getPrio(), 7),
- $zoneRecord->getContent()
- ));
- }
- }
}
diff --git a/src/Deblan/PowerDNS/Command/DomainListCommand.php b/src/Deblan/PowerDNS/Command/DomainListCommand.php
new file mode 100644
index 0000000..7c0783b
--- /dev/null
+++ b/src/Deblan/PowerDNS/Command/DomainListCommand.php
@@ -0,0 +1,59 @@
+setName('domain:list')
+ ->setDescription('List domains')
+ ->addOption('short', null, InputOption::VALUE_NONE, '')
+ ->addOption('zone', null, InputOption::VALUE_NONE, '')
+ ->addOption('active', null, InputOption::VALUE_NONE, '')
+ ->setHelp("The %command.name% ");
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ parent::execute($input, $output);
+
+ $query = $this->getDomainQuery();
+
+ $domains = $query->find();
+
+ foreach ($domains as $key => $domain) {
+ if ($this->getInput()->getOption('short')) {
+ $this->getHelper('domain')->showShortDomain($domain, $key);
+
+ continue;
+ }
+
+ $this->getHelper('domain')->showDomain($domain, $key);
+
+ if ($this->getInput()->getOption('zone') && $domain->getZone()) {
+ $this->getOutput()->writeln('');
+ $this->getHelper('zone')->showZone($domain->getZone());
+ $this->getOutput()->writeln('');
+ $this->getOutput()->writeln('');
+ }
+ }
+ }
+
+ protected function getDomainQuery()
+ {
+ $query = DomainQuery::create()->orderByName();
+
+ return $query;
+ }
+}
diff --git a/src/Deblan/PowerDNS/Command/Helper/DomainHelper.php b/src/Deblan/PowerDNS/Command/Helper/DomainHelper.php
new file mode 100644
index 0000000..bd41e0c
--- /dev/null
+++ b/src/Deblan/PowerDNS/Command/Helper/DomainHelper.php
@@ -0,0 +1,27 @@
+getOutput()->writeln(sprintf('DOMAIN: %s', $domain->getName()));
+ $this->getOutput()->writeln(sprintf('ID : %d', $domain->getId()));
+ $this->getOutput()->writeln(sprintf('TYPE : %s', $domain->getType()));
+ $this->getOutput()->writeln(sprintf('MASTER: %s', $domain->getMaster()));
+ }
+
+ public function showShortDomain(Domain $domain, $key = 0)
+ {
+ $this->getOutput()->writeln(sprintf('%s', $domain->getName()));
+ }
+
+ public static function getName()
+ {
+ return 'domain';
+ }
+}
diff --git a/src/Deblan/PowerDNS/Command/Helper/ZoneHelper.php b/src/Deblan/PowerDNS/Command/Helper/ZoneHelper.php
new file mode 100644
index 0000000..2451cbb
--- /dev/null
+++ b/src/Deblan/PowerDNS/Command/Helper/ZoneHelper.php
@@ -0,0 +1,67 @@
+getOutput()->writeln(sprintf('%s.', $zone->getName()));
+
+ if ($zone->getDescription()) {
+ $this->getOutput()->writeln($zone->getDescription());
+ }
+
+ foreach ($zone->getZoneVersions() as $key => $zoneVersion) {
+ $this->showZoneVersion($zoneVersion, $key);
+ }
+ }
+
+ public function showZoneVersion(ZoneVersion $zoneVersion, $key = 0)
+ {
+ if ($this->getInput()->getOption('active') && false === $zoneVersion->getIsActive()) {
+ return;
+ }
+
+ if ($this->getInput()->getOption('no-active') && true === $zoneVersion->getIsActive()) {
+ return;
+ }
+
+ $this->getOutput()->writeln('');
+ $this->getOutput()->writeln(sprintf(
+ 'Version: %d - Active: %s',
+ $zoneVersion->getVersion(),
+ $zoneVersion->getIsActive() ? 'Yes' : 'No'
+ ));
+
+ $this->showZoneVersionRecords($zoneVersion);
+ }
+
+ public function showZoneVersionRecords(ZoneVersion $zoneVersion)
+ {
+ $this->getOutput()->writeln('');
+ $this->getOutput()->writeln(' ID | NAME | TYPE | TTL | PRIO | CONTENT');
+ $this->getOutput()->writeln('----------------------------------------------------------------------');
+
+ foreach ($zoneVersion->getZoneRecords() as $zoneRecord) {
+ $this->getOutput()->writeln(sprintf(
+ '%5d | %s | %s | %s | %s | %s',
+ $zoneRecord->getId(),
+ str_pad($zoneRecord->getName(), 21),
+ str_pad($zoneRecord->getType(), 9),
+ str_pad($zoneRecord->getTtl(), 6),
+ str_pad($zoneRecord->getPrio(), 7),
+ $zoneRecord->getContent()
+ ));
+ }
+ }
+
+ public static function getName()
+ {
+ return 'zone';
+ }
+}
diff --git a/src/Deblan/PowerDNS/Command/ZoneListCommand.php b/src/Deblan/PowerDNS/Command/ZoneListCommand.php
index 4c6d60d..17d2884 100644
--- a/src/Deblan/PowerDNS/Command/ZoneListCommand.php
+++ b/src/Deblan/PowerDNS/Command/ZoneListCommand.php
@@ -30,7 +30,7 @@ class ZoneListCommand extends AbstractZoneCommand
$zones = $query->find();
foreach ($zones as $key => $zone) {
- $this->showZone($zone, $key);
+ $this->getHelper('zone')->showZone($zone, $key);
}
}
diff --git a/src/Deblan/PowerDNS/Resources/config/propel/schema.xml b/src/Deblan/PowerDNS/Resources/config/propel/schema.xml
index 3a38768..de0d98b 100644
--- a/src/Deblan/PowerDNS/Resources/config/propel/schema.xml
+++ b/src/Deblan/PowerDNS/Resources/config/propel/schema.xml
@@ -58,6 +58,10 @@
+
+
+
+