icingaweb2-module-director/application/controllers/SyncruleController.php

161 lines
5.2 KiB
PHP
Raw Normal View History

2015-07-23 16:40:32 +02:00
<?php
2015-10-20 22:34:04 +02:00
namespace Icinga\Module\Director\Controllers;
2015-07-23 16:40:32 +02:00
use Icinga\Module\Director\Web\Controller\ActionController;
use Icinga\Module\Director\Objects\SyncRule;
use Icinga\Module\Director\Objects\SyncRun;
2015-07-24 10:55:05 +02:00
use Icinga\Module\Director\Import\Sync;
use Icinga\Data\Filter\Filter;
2015-07-23 16:40:32 +02:00
use Icinga\Web\Notification;
2015-10-20 22:34:04 +02:00
class SyncruleController extends ActionController
2015-07-23 16:40:32 +02:00
{
public function addAction()
{
$this->indexAction();
2015-07-23 16:40:32 +02:00
}
public function editAction()
{
$this->indexAction();
2015-07-23 16:40:32 +02:00
}
public function runAction()
{
$sync = new Sync(SyncRule::load($this->params->get('id'), $this->db()));
if ($runId = $sync->apply()) {
Notification::success('Source has successfully been synchronized');
$this->redirectNow('director/list/syncrule');
2015-07-23 16:40:32 +02:00
} else {
}
}
public function indexAction()
{
$form = $this->view->form = $this->loadForm('syncRule')
->setSuccessUrl('director/list/syncrule')
2015-07-23 16:40:32 +02:00
->setDb($this->db());
if ($id = $this->params->get('id')) {
$this->prepareRuleTabs($id)->activate('edit');
2015-07-23 16:40:32 +02:00
$form->loadObject($id);
$this->view->title = sprintf(
$this->translate('Sync rule: %s'),
$form->getObject()->rule_name
);
} else {
$this->view->title = $this->translate('Add sync rule');
$this->prepareRuleTabs()->activate('add');
2015-07-23 16:40:32 +02:00
}
$form->handleRequest();
$this->setViewScript('object/form');
2015-07-23 16:40:32 +02:00
}
public function propertyAction()
{
$this->view->stayHere = true;
$id = $this->params->get('rule_id');
$this->prepareRuleTabs($id)->activate('property');
2016-02-26 12:42:21 +01:00
$this->view->addLink = $this->view->icon('plus')
. ' '
2016-02-19 12:53:47 +01:00
. $this->view->qlink(
2016-02-26 12:42:21 +01:00
$this->translate('Add sync property rule'),
'director/syncrule/addproperty',
array('rule_id' => $id)
);
$this->view->title = $this->translate('Sync properties');
2016-02-26 12:42:21 +01:00
$this->view->table = $this->loadTable('syncproperty')
->enforceFilter(Filter::where('rule_id', $id))
->setConnection($this->db());
$this->setViewScript('list/table');
}
public function editpropertyAction()
{
$this->addpropertyAction();
}
public function addpropertyAction()
{
$this->view->stayHere = true;
$edit = false;
if ($id = $this->params->get('id')) {
$edit = true;
}
$form = $this->view->form = $this->loadForm('syncProperty')->setDb($this->db());
if ($edit) {
$form->loadObject($id);
$rule_id = $form->getObject()->rule_id;
$form->setRule(SyncRule::load($rule_id, $this->db()));
} elseif ($rule_id = $this->params->get('rule_id')) {
$form->setRule(SyncRule::load($rule_id, $this->db()));
}
$form->setSuccessUrl('director/syncrule/property', array('rule_id' => $rule_id));
$form->handleRequest();
$this->prepareRuleTabs($rule_id)->activate('property');
$this->view->title = $this->translate('Sync property'); // add/edit
$this->view->table = $this->loadTable('syncproperty')
->enforceFilter(Filter::where('rule_id', $rule_id))
->setConnection($this->db());
$this->setViewScript('list/table');
}
public function historyAction()
{
$this->view->stayHere = true;
$id = $this->params->get('id');
$this->prepareRuleTabs($id)->activate('history');
$this->view->title = $this->translate('Sync history');
$this->view->table = $this->loadTable('syncRun')
->enforceFilter(Filter::where('rule_id', $id))
->setConnection($this->db());
if ($runId = $this->params->get('run_id')) {
$db = $this->db();
$this->view->run = SyncRun::load($runId, $db);
$this->view->formerId = $db->fetchActivityLogIdByChecksum(
$this->view->run->last_former_activity
);
$this->view->lastId = $db->fetchActivityLogIdByChecksum(
$this->view->run->last_related_activity
);
}
}
protected function prepareRuleTabs($ruleId = null)
{
if ($ruleId) {
return $this->getTabs()->add('edit', array(
'url' => 'director/syncrule/edit',
'urlParams' => array('id' => $ruleId),
'label' => $this->translate('Sync rule'),
))->add('property', array(
'label' => $this->translate('Properties'),
'url' => 'director/syncrule/property',
'urlParams' => array('rule_id' => $ruleId)
))->add('history', array(
'label' => $this->translate('History'),
'url' => 'director/syncrule/history',
'urlParams' => array('id' => $ruleId)
));
} else {
return $this->getTabs()->add('add', array(
'url' => 'director/syncrule/add',
'label' => $this->translate('Sync rule'),
));
}
}
2015-07-23 16:40:32 +02:00
}