2015-07-21 15:16:18 +02:00
|
|
|
<?php
|
|
|
|
|
2015-10-20 22:34:04 +02:00
|
|
|
namespace Icinga\Module\Director\Controllers;
|
|
|
|
|
2017-08-16 14:58:23 +02:00
|
|
|
use Icinga\Module\Director\Forms\ImportRowModifierForm;
|
|
|
|
use Icinga\Module\Director\Forms\ImportSourceForm;
|
2018-07-15 16:02:29 +02:00
|
|
|
use Icinga\Module\Director\Web\ActionBar\AutomationObjectActionBar;
|
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;
|
2018-06-12 22:01:34 +02:00
|
|
|
use Icinga\Module\Director\Web\Form\CloneImportSourceForm;
|
2017-08-16 14:58:23 +02:00
|
|
|
use Icinga\Module\Director\Web\Table\ImportrunTable;
|
|
|
|
use Icinga\Module\Director\Web\Table\ImportsourceHookTable;
|
|
|
|
use Icinga\Module\Director\Web\Table\PropertymodifierTable;
|
|
|
|
use Icinga\Module\Director\Web\Tabs\ImportsourceTabs;
|
|
|
|
use Icinga\Module\Director\Web\Widget\ImportSourceDetails;
|
2017-10-09 15:23:27 +02:00
|
|
|
use dipl\Html\Link;
|
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
|
|
|
{
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
2018-06-23 09:05:10 +02:00
|
|
|
* @throws \Icinga\Exception\AuthenticationException
|
2018-06-12 20:23:57 +02:00
|
|
|
* @throws \Icinga\Exception\Http\HttpNotFoundException
|
2018-06-23 09:05:10 +02:00
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
* @throws \Icinga\Security\SecurityException
|
2018-06-12 20:23:57 +02:00
|
|
|
*/
|
2017-08-16 14:58:23 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
|
|
|
|
$id = $this->params->get('source_id', $this->params->get('id'));
|
|
|
|
$tabs = $this->tabs(new ImportsourceTabs($id));
|
|
|
|
$action = $this->getRequest()->getActionName();
|
|
|
|
if ($tabs->has($action)) {
|
|
|
|
$tabs->activate($action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-15 16:02:29 +02:00
|
|
|
protected function addMainActions()
|
|
|
|
{
|
|
|
|
$this->actions(new AutomationObjectActionBar(
|
|
|
|
$this->getRequest()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
2018-06-23 09:05:10 +02:00
|
|
|
* @throws \Icinga\Exception\IcingaException
|
2018-06-12 20:23:57 +02:00
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
2016-06-26 15:51:05 +02:00
|
|
|
public function indexAction()
|
|
|
|
{
|
2018-07-15 16:02:29 +02:00
|
|
|
$this->addMainActions();
|
2017-08-16 14:58:23 +02:00
|
|
|
$source = ImportSource::load($this->params->getRequired('id'), $this->db());
|
2018-05-29 12:34:18 +02:00
|
|
|
if ($this->params->get('format') === 'json') {
|
2018-06-23 09:05:10 +02:00
|
|
|
$this->sendJson($this->getResponse(), $source->export());
|
2018-05-29 12:34:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-08-16 14:58:23 +02:00
|
|
|
$this->addTitle(
|
2016-06-26 15:51:05 +02:00
|
|
|
$this->translate('Import source: %s'),
|
2017-08-16 14:58:23 +02:00
|
|
|
$source->get('source_name')
|
|
|
|
)->setAutorefreshInterval(10);
|
|
|
|
$this->content()->add(new ImportSourceDetails($source));
|
2016-06-26 15:51:05 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
|
|
|
*/
|
2015-07-21 15:16:18 +02:00
|
|
|
public function addAction()
|
|
|
|
{
|
2017-08-16 14:58:23 +02:00
|
|
|
$this->addTitle($this->translate('Add import source'))
|
|
|
|
->content()->add(
|
|
|
|
ImportSourceForm::load()->setDb($this->db())
|
|
|
|
->setSuccessUrl('director/importsources')
|
|
|
|
->handleRequest()
|
|
|
|
);
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
*/
|
2015-07-21 15:16:18 +02:00
|
|
|
public function editAction()
|
|
|
|
{
|
2018-07-15 16:02:29 +02:00
|
|
|
$this->addMainActions();
|
|
|
|
$this->tabs()->activateMainWithPostfix($this->translate('Modify'));
|
2018-06-12 22:01:34 +02:00
|
|
|
$id = $this->params->getRequired('id');
|
2017-08-16 14:58:23 +02:00
|
|
|
$form = ImportSourceForm::load()->setDb($this->db())
|
2018-06-12 22:01:34 +02:00
|
|
|
->loadObject($id)
|
2017-08-16 14:58:23 +02:00
|
|
|
->setListUrl('director/importsources')
|
|
|
|
->handleRequest();
|
2018-06-12 20:23:57 +02:00
|
|
|
$this->addTitle(
|
|
|
|
$this->translate('Import source: %s'),
|
|
|
|
$form->getObject()->get('source_name')
|
|
|
|
)->setAutorefreshInterval(10);
|
2016-06-26 15:51:05 +02:00
|
|
|
|
2017-08-16 14:58:23 +02:00
|
|
|
$this->content()->add($form);
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 22:01:34 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
|
|
|
public function cloneAction()
|
|
|
|
{
|
2018-07-15 16:02:29 +02:00
|
|
|
$this->addMainActions();
|
|
|
|
$this->tabs()->activateMainWithPostfix($this->translate('Clone'));
|
2018-06-12 22:01:34 +02:00
|
|
|
$id = $this->params->getRequired('id');
|
|
|
|
$source = ImportSource::load($id, $this->db());
|
|
|
|
$this->addTitle('Clone: %s', $source->get('source_name'));
|
|
|
|
$form = new CloneImportSourceForm($source);
|
|
|
|
$this->content()->add($form);
|
|
|
|
$form->handleRequest($this->getRequest());
|
|
|
|
}
|
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
2015-07-26 15:42:21 +02:00
|
|
|
public function previewAction()
|
|
|
|
{
|
2017-08-16 14:58:23 +02:00
|
|
|
$source = ImportSource::load($this->params->getRequired('id'), $this->db());
|
2015-11-03 09:57:16 +01:00
|
|
|
|
2017-08-16 14:58:23 +02:00
|
|
|
$this->addTitle(
|
2018-06-12 20:23:57 +02:00
|
|
|
$this->translate('Import source preview: %s'),
|
2017-08-16 14:58:23 +02:00
|
|
|
$source->get('source_name')
|
2015-07-26 15:42:21 +02:00
|
|
|
);
|
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
$this->actions()->add(Link::create('[..]', '#', null, [
|
|
|
|
'onclick' => 'javascript:$("table.raw-data-table").toggleClass("collapsed");'
|
|
|
|
]));
|
2017-08-16 14:58:23 +02:00
|
|
|
(new ImportsourceHookTable())->setImportSource($source)->renderTo($this);
|
2015-07-26 15:42:21 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
|
|
|
* @return ImportSource
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
2017-08-16 14:58:23 +02:00
|
|
|
protected function requireImportSourceAndAddModifierTable()
|
2016-02-18 11:25:51 +01:00
|
|
|
{
|
2017-08-16 14:58:23 +02:00
|
|
|
$source = ImportSource::load($this->params->getRequired('source_id'), $this->db());
|
2017-08-20 16:03:49 +02:00
|
|
|
PropertymodifierTable::load($source, $this->url())
|
|
|
|
->handleSortPriorityActions($this->getRequest(), $this->getResponse())
|
|
|
|
->renderTo($this);
|
2018-06-12 20:23:57 +02:00
|
|
|
|
2017-08-16 14:58:23 +02:00
|
|
|
return $source;
|
|
|
|
}
|
2016-02-18 11:25:51 +01:00
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
2017-08-16 14:58:23 +02:00
|
|
|
public function modifierAction()
|
|
|
|
{
|
|
|
|
$source = $this->requireImportSourceAndAddModifierTable();
|
2018-06-12 20:23:57 +02:00
|
|
|
$this->addTitle($this->translate('Property modifiers: %s'), $source->get('source_name'));
|
2017-08-16 14:58:23 +02:00
|
|
|
$this->addAddLink(
|
2016-06-13 20:21:33 +02:00
|
|
|
$this->translate('Add property modifier'),
|
|
|
|
'director/importsource/addmodifier',
|
2017-08-16 14:58:23 +02:00
|
|
|
['source_id' => $source->getId()],
|
|
|
|
'_self'
|
2017-08-20 15:15:31 +02:00
|
|
|
);
|
2016-02-18 11:25:51 +01:00
|
|
|
}
|
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
2016-06-16 14:47:12 +02:00
|
|
|
public function historyAction()
|
|
|
|
{
|
2017-08-16 14:58:23 +02:00
|
|
|
$source = ImportSource::load($this->params->getRequired('id'), $this->db());
|
2018-06-12 20:23:57 +02:00
|
|
|
$this->addTitle($this->translate('Import run history: %s'), $source->get('source_name'));
|
2016-08-23 16:26:06 +02:00
|
|
|
|
|
|
|
// TODO: temporarily disabled, find a better place for stats:
|
|
|
|
// $this->view->stats = $this->db()->fetchImportStatistics();
|
2017-08-16 14:58:23 +02:00
|
|
|
ImportrunTable::load($source)->renderTo($this);
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|
2015-11-03 09:57:16 +01:00
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
|
|
|
* @throws \Icinga\Exception\Http\HttpNotFoundException
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
2017-08-16 14:58:23 +02:00
|
|
|
public function addmodifierAction()
|
2016-02-18 23:33:22 +01:00
|
|
|
{
|
2017-08-16 14:58:23 +02:00
|
|
|
$source = $this->requireImportSourceAndAddModifierTable();
|
|
|
|
$this->addTitle(
|
|
|
|
$this->translate('%s: add Property Modifier'),
|
|
|
|
$source->get('source_name')
|
|
|
|
)->addBackToModifiersLink($source);
|
|
|
|
$this->tabs()->activate('modifier');
|
|
|
|
|
|
|
|
$this->content()->prepend(
|
|
|
|
ImportRowModifierForm::load()->setDb($this->db())
|
|
|
|
->setSource($source)
|
|
|
|
->setSuccessUrl(
|
|
|
|
'director/importsource/modifier',
|
|
|
|
['source_id' => $source->getId()]
|
|
|
|
)->handleRequest()
|
|
|
|
);
|
2016-02-18 23:33:22 +01:00
|
|
|
}
|
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
|
|
|
* @throws \Icinga\Exception\Http\HttpNotFoundException
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
2017-08-16 14:58:23 +02:00
|
|
|
public function editmodifierAction()
|
2016-02-18 23:33:22 +01:00
|
|
|
{
|
2018-01-25 10:11:48 +01:00
|
|
|
// We need to load the table AFTER adding the title, otherwise search
|
|
|
|
// will not be placed next to the title
|
|
|
|
$source = ImportSource::load($this->params->getRequired('source_id'), $this->db());
|
|
|
|
|
2017-08-16 14:58:23 +02:00
|
|
|
$this->addTitle(
|
|
|
|
$this->translate('%s: Property Modifier'),
|
|
|
|
$source->get('source_name')
|
|
|
|
)->addBackToModifiersLink($source);
|
2018-01-25 10:11:48 +01:00
|
|
|
$source = $this->requireImportSourceAndAddModifierTable();
|
2017-08-16 14:58:23 +02:00
|
|
|
$this->tabs()->activate('modifier');
|
|
|
|
|
2017-08-21 11:11:53 +02:00
|
|
|
$listUrl = 'director/importsource/modifier?source_id='
|
|
|
|
. (int) $source->get('id');
|
2017-08-16 14:58:23 +02:00
|
|
|
$this->content()->prepend(
|
|
|
|
ImportRowModifierForm::load()->setDb($this->db())
|
|
|
|
->loadObject($this->params->getRequired('id'))
|
2017-08-21 11:11:53 +02:00
|
|
|
->setListUrl($listUrl)
|
2017-08-16 14:58:23 +02:00
|
|
|
->setSource($source)
|
|
|
|
->handleRequest()
|
|
|
|
);
|
2016-02-18 23:33:22 +01:00
|
|
|
}
|
|
|
|
|
2018-06-12 20:23:57 +02:00
|
|
|
/**
|
|
|
|
* @param ImportSource $source
|
|
|
|
* @return $this
|
|
|
|
*/
|
2017-08-16 14:58:23 +02:00
|
|
|
protected function addBackToModifiersLink(ImportSource $source)
|
2015-11-03 09:57:16 +01:00
|
|
|
{
|
2017-08-16 14:58:23 +02:00
|
|
|
$this->actions()->add(
|
|
|
|
Link::create(
|
|
|
|
$this->translate('back'),
|
|
|
|
'director/importsource/modifier',
|
|
|
|
['source_id' => $source->getId()],
|
|
|
|
['class' => 'icon-left-big']
|
|
|
|
)
|
|
|
|
);
|
2015-11-03 09:57:16 +01:00
|
|
|
|
2017-08-16 14:58:23 +02:00
|
|
|
return $this;
|
2015-11-03 09:57:16 +01:00
|
|
|
}
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|