43 lines
990 B
PHP
43 lines
990 B
PHP
<?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()
|
|
{
|
|
$id = $this->params->shift();
|
|
$import = new Import(ImportSource::load($id, $this->db()));
|
|
if ($runId = $import->run()) {
|
|
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 configured correctly');
|
|
}
|
|
}
|
|
|
|
return $this->db;
|
|
}
|
|
|
|
}
|
|
|