ImportCommand: add first CLI command

icingacli director import run

Triggers import run if source provides any changes
This commit is contained in:
Thomas Gelf 2015-09-14 16:59:43 +02:00
parent 23f555e428
commit d1160fd0c3
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace Icinga\Module\Director\Clicommands;
use Icinga\Cli\Command;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\ImportSource;
use Icinga\Module\Director\Import\Import;
class ImportCommand extends Command
{
protected $db;
public function runAction()
{
if ($runId = Import::run($id = ImportSource::load($this->params->shift(), $this->db()))) {
echo "Triggered new import\n";
} else {
echo "Nothing changed\n";
}
}
protected function db()
{
if ($this->db === null) {
$this->app->setupZendAutoloader();
$resourceName = $this->Config()->get('db', 'resource');
if ($resourceName) {
$this->db = Db::fromResourceName($resourceName);
} else {
$this->fail('Director is not confiured correctly');
}
}
return $this->db;
}
}