2015-07-21 15:16:18 +02:00
|
|
|
<?php
|
|
|
|
|
2015-10-20 22:34:04 +02:00
|
|
|
namespace Icinga\Module\Director\Controllers;
|
|
|
|
|
2016-02-18 11:25:51 +01:00
|
|
|
use Icinga\Data\Filter\Filter;
|
2015-07-21 15:16:18 +02:00
|
|
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
2015-07-22 10:12:50 +02:00
|
|
|
use Icinga\Module\Director\Objects\ImportSource;
|
|
|
|
use Icinga\Module\Director\Import\Import;
|
|
|
|
use Icinga\Web\Notification;
|
2015-08-28 23:47:35 +02:00
|
|
|
use Icinga\Web\Url;
|
2015-07-21 15:16:18 +02:00
|
|
|
|
2015-10-20 22:34:04 +02:00
|
|
|
class ImportsourceController extends ActionController
|
2015-07-21 15:16:18 +02:00
|
|
|
{
|
2016-06-26 15:51:05 +02:00
|
|
|
public function indexAction()
|
|
|
|
{
|
2016-10-18 19:34:18 +02:00
|
|
|
$this->setAutoRefreshInterval(10);
|
2016-06-26 15:51:05 +02:00
|
|
|
$id = $this->params->get('id');
|
|
|
|
$this->prepareTabs($id)->activate('show');
|
|
|
|
$source = $this->view->source = ImportSource::load($id, $this->db());
|
|
|
|
$this->view->title = sprintf(
|
|
|
|
$this->translate('Import source: %s'),
|
|
|
|
$source->source_name
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->view->checkForm = $this
|
|
|
|
->loadForm('ImportCheck')
|
|
|
|
->setImportSource($source)
|
|
|
|
->handleRequest();
|
|
|
|
|
|
|
|
$this->view->runForm = $this
|
|
|
|
->loadForm('ImportRun')
|
|
|
|
->setImportSource($source)
|
|
|
|
->handleRequest();
|
|
|
|
}
|
|
|
|
|
2015-07-21 15:16:18 +02:00
|
|
|
public function addAction()
|
|
|
|
{
|
2016-06-26 15:51:05 +02:00
|
|
|
$this->editAction();
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function editAction()
|
|
|
|
{
|
2016-06-26 15:51:05 +02:00
|
|
|
$id = $this->params->get('id');
|
|
|
|
|
|
|
|
$form = $this->view->form = $this->loadForm('importSource')->setDb($this->db());
|
|
|
|
|
|
|
|
if ($id) {
|
|
|
|
$form->loadObject($id)->setListUrl('director/list/importsource');
|
|
|
|
$this->prepareTabs($id)->activate('edit');
|
|
|
|
$this->view->title = $this->translate('Edit import source');
|
|
|
|
} else {
|
|
|
|
$form->setSuccessUrl('director/list/importsource');
|
|
|
|
$this->view->title = $this->translate('Add import source');
|
|
|
|
$this->prepareTabs()->activate('add');
|
|
|
|
}
|
|
|
|
|
|
|
|
$form->handleRequest();
|
|
|
|
$this->setViewScript('object/form');
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|
|
|
|
|
2015-07-26 15:42:21 +02:00
|
|
|
public function previewAction()
|
|
|
|
{
|
2015-11-03 09:57:16 +01:00
|
|
|
$id = $this->params->get('id');
|
|
|
|
|
|
|
|
$source = ImportSource::load($id, $this->db());
|
|
|
|
$this->prepareTabs($id)->activate('preview');
|
|
|
|
|
2015-07-26 15:42:21 +02:00
|
|
|
$this->view->title = sprintf(
|
|
|
|
$this->translate('Import source preview: "%s"'),
|
|
|
|
$source->source_name
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->view->table = $this->applyPaginationLimits(
|
|
|
|
$this->loadTable('importsourceHook')
|
|
|
|
->setConnection($this->db())
|
|
|
|
->setImportSource($source)
|
|
|
|
);
|
2016-06-16 14:47:12 +02:00
|
|
|
$this->setViewScript('list/table');
|
2015-07-26 15:42:21 +02:00
|
|
|
}
|
|
|
|
|
2016-02-18 11:25:51 +01:00
|
|
|
public function modifierAction()
|
|
|
|
{
|
|
|
|
$this->view->stayHere = true;
|
|
|
|
$id = $this->params->get('source_id');
|
|
|
|
$this->prepareTabs($id)->activate('modifier');
|
|
|
|
|
2016-06-13 20:21:33 +02:00
|
|
|
$this->view->addLink = $this->view->qlink(
|
|
|
|
$this->translate('Add property modifier'),
|
|
|
|
'director/importsource/addmodifier',
|
|
|
|
array('source_id' => $id),
|
|
|
|
array('class' => 'icon-plus')
|
|
|
|
);
|
2016-02-18 11:25:51 +01:00
|
|
|
|
|
|
|
$this->view->title = $this->translate('Property modifiers');
|
2016-02-26 12:42:21 +01:00
|
|
|
$this->view->table = $this->loadTable('propertymodifier')
|
|
|
|
->enforceFilter(Filter::where('source_id', $id))
|
|
|
|
->setConnection($this->db());
|
2016-06-16 14:47:12 +02:00
|
|
|
$this->setViewScript('list/table');
|
2016-02-18 11:25:51 +01:00
|
|
|
}
|
|
|
|
|
2016-06-16 14:47:12 +02:00
|
|
|
public function historyAction()
|
|
|
|
{
|
|
|
|
$url = $this->getRequest()->getUrl();
|
|
|
|
$id = $url->shift('id');
|
|
|
|
if ($url->shift('action') === 'remove') {
|
|
|
|
$this->view->form = $this->loadForm('removeImportrun');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->prepareTabs($id)->activate('history');
|
|
|
|
$this->view->title = $this->translate('Import run history');
|
2016-08-23 16:26:06 +02:00
|
|
|
|
|
|
|
// TODO: temporarily disabled, find a better place for stats:
|
|
|
|
// $this->view->stats = $this->db()->fetchImportStatistics();
|
2016-06-16 14:47:12 +02:00
|
|
|
$this->prepareTable('importrun');
|
|
|
|
$this->view->table->enforceFilter(Filter::where('source_id', $id));
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|
2015-11-03 09:57:16 +01:00
|
|
|
|
2016-02-18 23:33:22 +01:00
|
|
|
public function editmodifierAction()
|
|
|
|
{
|
|
|
|
$this->addmodifierAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addmodifierAction()
|
|
|
|
{
|
|
|
|
$this->view->stayHere = true;
|
|
|
|
$edit = false;
|
|
|
|
|
|
|
|
if ($id = $this->params->get('id')) {
|
|
|
|
$edit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = $this->view->form = $this->loadForm('importRowModifier')->setDb($this->db());
|
|
|
|
|
|
|
|
if ($edit) {
|
|
|
|
$form->loadObject($id);
|
|
|
|
$source_id = $form->getObject()->source_id;
|
|
|
|
$form->setSource(ImportSource::load($source_id, $this->db()));
|
|
|
|
} elseif ($source_id = $this->params->get('source_id')) {
|
|
|
|
$form->setSource(ImportSource::load($source_id, $this->db()));
|
|
|
|
}
|
|
|
|
$form->setSuccessUrl('director/importsource/modifier', array('source_id' => $source_id));
|
|
|
|
|
|
|
|
$form->handleRequest();
|
|
|
|
|
2016-02-19 12:56:16 +01:00
|
|
|
$tabs = $this->prepareTabs($source_id)->activate('modifier');
|
2016-02-18 23:33:22 +01:00
|
|
|
|
|
|
|
$this->view->title = $this->translate('Modifier'); // add/edit
|
2016-02-26 12:42:21 +01:00
|
|
|
$this->view->table = $this->loadTable('propertymodifier')
|
|
|
|
->enforceFilter(Filter::where('source_id', $source_id))
|
|
|
|
->setConnection($this->db());
|
|
|
|
|
2016-06-16 14:47:12 +02:00
|
|
|
$this->setViewScript('list/table');
|
2016-02-18 23:33:22 +01:00
|
|
|
}
|
|
|
|
|
2015-11-03 09:57:16 +01:00
|
|
|
protected function prepareTabs($id = null)
|
|
|
|
{
|
|
|
|
$tabs = $this->getTabs();
|
|
|
|
|
|
|
|
if ($id) {
|
2016-06-26 15:51:05 +02:00
|
|
|
$tabs->add('show', array(
|
|
|
|
'url' => 'director/importsource' . '?id=' . $id,
|
2015-11-03 09:57:16 +01:00
|
|
|
'label' => $this->translate('Import source'),
|
2016-06-26 15:51:05 +02:00
|
|
|
))->add('edit', array(
|
|
|
|
'url' => 'director/importsource/edit' . '?id=' . $id,
|
|
|
|
'label' => $this->translate('Modify'),
|
2016-02-18 11:25:51 +01:00
|
|
|
))->add('modifier', array(
|
|
|
|
'url' => 'director/importsource/modifier' . '?source_id=' . $id,
|
|
|
|
'label' => $this->translate('Modifiers'),
|
2016-06-16 14:47:12 +02:00
|
|
|
))->add('history', array(
|
|
|
|
'url' => 'director/importsource/history' . '?id=' . $id,
|
|
|
|
'label' => $this->translate('History'),
|
2015-11-03 09:57:16 +01:00
|
|
|
))->add('preview', array(
|
|
|
|
'url' => 'director/importsource/preview' . '?id=' . $id,
|
|
|
|
'label' => $this->translate('Preview'),
|
|
|
|
));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$tabs->add('add', array(
|
|
|
|
'url' => 'director/importsource/add',
|
|
|
|
'label' => $this->translate('New import source'),
|
|
|
|
))->activate('add');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tabs;
|
|
|
|
}
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|