Sync: completely refactor table, form, controller
This commit is contained in:
parent
8c83a951f7
commit
098cd0a57a
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
use Icinga\Module\Director\Objects\SyncRule;
|
||||
|
||||
class SyncpropertyController extends ActionController
|
||||
{
|
||||
public function addAction()
|
||||
{
|
||||
$this->indexAction();
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
{
|
||||
$this->indexAction();
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$edit = false;
|
||||
|
||||
if ($id = $this->params->get('id')) {
|
||||
$edit = true;
|
||||
}
|
||||
|
||||
if ($edit) {
|
||||
$this->view->title = $this->translate('Edit sync property rule');
|
||||
$this->getTabs()->add('edit', array(
|
||||
'url' => 'director/syncproperty/edit' . '?id=' . $id,
|
||||
'label' => $this->view->title,
|
||||
))->activate('edit');
|
||||
} else {
|
||||
$this->view->title = $this->translate('Add sync property rule');
|
||||
$this->getTabs()->add('add', array(
|
||||
'url' => 'director/syncproperty/add',
|
||||
'label' => $this->view->title,
|
||||
))->activate('add');
|
||||
}
|
||||
|
||||
$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->render('object/form', null, true);
|
||||
}
|
||||
}
|
|
@ -2,41 +2,117 @@
|
|||
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use Icinga\Module\Director\Forms\SyncCheckForm;
|
||||
use Icinga\Module\Director\Forms\SyncPropertyForm;
|
||||
use Icinga\Module\Director\Forms\SyncRuleForm;
|
||||
use Icinga\Module\Director\Forms\SyncRunForm;
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
use Icinga\Module\Director\Objects\SyncRule;
|
||||
use Icinga\Module\Director\Objects\SyncRun;
|
||||
use Icinga\Module\Director\Import\Sync;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Module\Director\Web\Table\SyncpropertyTable;
|
||||
use Icinga\Module\Director\Web\Table\SyncRunTable;
|
||||
use Icinga\Module\Director\Web\Tabs\SyncRuleTabs;
|
||||
use Icinga\Module\Director\Web\Widget\SyncRunDetails;
|
||||
use ipl\Html\Html;
|
||||
use ipl\Html\Link;
|
||||
|
||||
class SyncruleController extends ActionController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->setAutoRefreshInterval(10);
|
||||
$id = $this->params->get('id');
|
||||
$this->prepareRuleTabs($id)->activate('show');
|
||||
$rule = $this->view->rule = SyncRule::load($id, $this->db());
|
||||
$this->view->title = sprintf(
|
||||
$this->translate('Sync rule: %s'),
|
||||
$rule->rule_name
|
||||
);
|
||||
$rule = $this->requireSyncRule();
|
||||
$this->tabs(new SyncRuleTabs($rule))->activate('show');
|
||||
$ruleName = $rule->get('rule_name');
|
||||
$this->addTitle($this->translate('Sync rule: %s'), $ruleName);
|
||||
|
||||
if ($lastRunId = $rule->getLastSyncRunId()) {
|
||||
$this->loadSyncRun($lastRunId);
|
||||
$run = SyncRun::load($lastRunId, $this->db());
|
||||
} else {
|
||||
$this->view->run = null;
|
||||
$run = null;
|
||||
}
|
||||
$this->view->checkForm = $this
|
||||
->loadForm('syncCheck')
|
||||
->setSyncRule($rule)
|
||||
->handleRequest();
|
||||
|
||||
$this->view->runForm = $this
|
||||
->loadForm('syncRun')
|
||||
->setSyncRule($rule)
|
||||
->handleRequest();
|
||||
$c = $this->content();
|
||||
$c->add(Html::p($rule->get('description')));
|
||||
if (! $rule->hasSyncProperties()) {
|
||||
$this->addPropertyHint($rule);
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $run) {
|
||||
$this->warning($this->translate('This Sync Rule has never been run before.'));
|
||||
}
|
||||
|
||||
switch ($rule->get('sync_state')) {
|
||||
case 'unknown':
|
||||
$c->add(Html::p($this->translate(
|
||||
"It's currently unknown whether we are in sync with this rule."
|
||||
. ' You should either check for changes or trigger a new Sync Run.'
|
||||
)));
|
||||
break;
|
||||
case 'in-sync':
|
||||
$c->add(Html::p(sprintf(
|
||||
$this->translate('This Sync Rule was last found to by in Sync at %s.'),
|
||||
$rule->get('last_attempt')
|
||||
)));
|
||||
/*
|
||||
TODO: check whether...
|
||||
- there have been imports since then, differing from former ones
|
||||
- there have been activities since then
|
||||
*/
|
||||
break;
|
||||
case 'pending-changes':
|
||||
$this->warning($this->translate(
|
||||
'There are pending changes for this Sync Rule. You should trigger a new'
|
||||
. ' Sync Run.'
|
||||
));
|
||||
break;
|
||||
case 'failing':
|
||||
$this->error(sprintf(
|
||||
$this->translate(
|
||||
'This Sync Rule failed when last checked at %s: %s'
|
||||
),
|
||||
$rule->get('last_attempt'),
|
||||
$rule->get('last_error_message')
|
||||
));
|
||||
break;
|
||||
}
|
||||
|
||||
$c->add(SyncCheckForm::load()->setSyncRule($rule)->handleRequest());
|
||||
$c->add(SyncRunForm::load()->setSyncRule($rule)->handleRequest());
|
||||
|
||||
if ($run) {
|
||||
$c->add(Html::h3($this->translate('Last sync run details')));
|
||||
$c->add(new SyncRunDetails($run));
|
||||
if ($run->get('rule_name') !== $ruleName) {
|
||||
$c->add(Html::p(sprintf(
|
||||
$this->translate("It has been renamed since then, its former name was %s"),
|
||||
$run->get('rule_name')
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function addPropertyHint(SyncRule $rule)
|
||||
{
|
||||
$this->warning(Html::sprintf(
|
||||
$this->translate('You must define some %s before you can run this Sync Rule'),
|
||||
new Link(
|
||||
$this->translate('Sync Properties'),
|
||||
'director/syncrule/property',
|
||||
['rule_id' => $rule->get('id')]
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
protected function warning($msg)
|
||||
{
|
||||
$this->content()->add(Html::p(['class' => 'warning'], $msg));
|
||||
}
|
||||
|
||||
protected function error($msg)
|
||||
{
|
||||
$this->content()->add(Html::p(['class' => 'error'], $msg));
|
||||
}
|
||||
|
||||
public function addAction()
|
||||
|
@ -46,75 +122,46 @@ class SyncruleController extends ActionController
|
|||
|
||||
public function editAction()
|
||||
{
|
||||
$form = $this->view->form = $this->loadForm('syncRule')
|
||||
->setSuccessUrl('director/list/syncrule')
|
||||
$form = SyncRuleForm::load()
|
||||
->setListUrl('director/list/syncrule')
|
||||
->setDb($this->db());
|
||||
|
||||
if ($id = $this->params->get('id')) {
|
||||
$this->prepareRuleTabs($id)->activate('edit');
|
||||
$form->loadObject($id);
|
||||
$this->view->title = sprintf(
|
||||
/** @var SyncRule $rule */
|
||||
$rule = $form->getObject();
|
||||
$this->tabs(new SyncRuleTabs($rule))->activate('edit');
|
||||
$this->addTitle(sprintf(
|
||||
$this->translate('Sync rule: %s'),
|
||||
$form->getObject()->rule_name
|
||||
);
|
||||
$rule->rule_name
|
||||
));
|
||||
|
||||
if (! $rule->hasSyncProperties()) {
|
||||
$this->addPropertyHint($rule);
|
||||
}
|
||||
} else {
|
||||
$this->view->title = $this->translate('Add sync rule');
|
||||
$this->prepareRuleTabs()->activate('add');
|
||||
$this->addTitle($this->translate('Add sync rule'));
|
||||
$this->tabs(new SyncRuleTabs())->activate('add');
|
||||
}
|
||||
|
||||
$form->handleRequest();
|
||||
$this->setViewScript('object/form');
|
||||
}
|
||||
|
||||
public function runAction()
|
||||
{
|
||||
$id = $this->params->get('id');
|
||||
$rule = SyncRule::load($id, $this->db());
|
||||
$changed = $rule->applyChanges();
|
||||
|
||||
if ($changed) {
|
||||
$runId = $rule->getCurrentSyncRunId();
|
||||
Notification::success('Source has successfully been synchronized');
|
||||
$this->redirectNow(
|
||||
Url::fromPath(
|
||||
'director/syncrule/history',
|
||||
array(
|
||||
'id' => $id,
|
||||
'run_id' => $runId
|
||||
)
|
||||
)
|
||||
);
|
||||
} elseif ($rule->sync_state === 'in-sync') {
|
||||
Notification::success('Nothing changed, rule is in sync');
|
||||
} else {
|
||||
Notification::error('Synchronization failed');
|
||||
}
|
||||
|
||||
$this->redirectNow('director/syncrule?id=' . $id);
|
||||
$this->content()->add($form);
|
||||
}
|
||||
|
||||
public function propertyAction()
|
||||
{
|
||||
$this->view->stayHere = true;
|
||||
$rule = $this->requireSyncRule('rule_id');
|
||||
$this->tabs(new SyncRuleTabs($rule))->activate('property');
|
||||
|
||||
$db = $this->db();
|
||||
$id = $this->params->get('rule_id');
|
||||
$rule = SyncRule::load($id, $db);
|
||||
|
||||
$this->prepareRuleTabs($id)->activate('property');
|
||||
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
$this->actions()->add(Link::create(
|
||||
$this->translate('Add sync property rule'),
|
||||
'director/syncrule/addproperty',
|
||||
array('rule_id' => $id),
|
||||
array('class' => 'icon-plus')
|
||||
);
|
||||
['rule_id' => $rule->get('id')],
|
||||
['class' => 'icon-plus']
|
||||
));
|
||||
|
||||
$this->view->title = $this->translate('Sync properties') . ': ' . $rule->rule_name;
|
||||
$this->view->table = $this->loadTable('syncproperty')
|
||||
->enforceFilter(Filter::where('rule_id', $id))
|
||||
->setConnection($this->db());
|
||||
$this->setViewScript('list/table');
|
||||
$this->addTitle($this->translate('Sync properties') . ': ' . $rule->get('rule_name'));
|
||||
SyncpropertyTable::create($rule)->renderTo($this);
|
||||
}
|
||||
|
||||
public function editpropertyAction()
|
||||
|
@ -124,121 +171,56 @@ class SyncruleController extends ActionController
|
|||
|
||||
public function addpropertyAction()
|
||||
{
|
||||
$this->view->stayHere = true;
|
||||
$edit = false;
|
||||
|
||||
$db = $this->db();
|
||||
$ruleId = $this->params->get('rule_id');
|
||||
$rule = SyncRule::load($ruleId, $db);
|
||||
$rule = $this->requireSyncRule('rule_id');
|
||||
$ruleId = (int) $rule->get('id');
|
||||
|
||||
$form = SyncPropertyForm::load()->setDb($db);
|
||||
if ($id = $this->params->get('id')) {
|
||||
$edit = true;
|
||||
}
|
||||
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
$this->translate('back'),
|
||||
'director/syncrule/property',
|
||||
array('rule_id' => $ruleId),
|
||||
array('class' => 'icon-left-big')
|
||||
);
|
||||
|
||||
$form = $this->view->form = $this->loadForm('syncProperty')->setDb($db);
|
||||
|
||||
if ($edit) {
|
||||
$form->loadObject($id);
|
||||
$rule_id = $form->getObject()->rule_id;
|
||||
$form->setRule(SyncRule::load($rule_id, $db));
|
||||
} elseif ($rule_id = $this->params->get('rule_id')) {
|
||||
$form->setRule(SyncRule::load($rule_id, $db));
|
||||
}
|
||||
|
||||
$form->setSuccessUrl('director/syncrule/property', array('rule_id' => $rule_id));
|
||||
$form->handleRequest();
|
||||
|
||||
$this->prepareRuleTabs($rule_id)->activate('property');
|
||||
|
||||
if ($edit) {
|
||||
$this->view->title = sprintf(
|
||||
$this->addTitle(
|
||||
$this->translate('Sync "%s": %s'),
|
||||
$form->getObject()->destination_field,
|
||||
$rule->rule_name
|
||||
$form->getObject()->get('destination_field'),
|
||||
$rule->get('rule_name')
|
||||
);
|
||||
} else {
|
||||
$this->view->title = sprintf(
|
||||
$this->addTitle(
|
||||
$this->translate('Add sync property: %s'),
|
||||
$rule->rule_name
|
||||
$rule->get('rule_name')
|
||||
);
|
||||
}
|
||||
$form->setRule($rule);
|
||||
$form->setSuccessUrl('director/syncrule/property', ['rule_id' => $ruleId]);
|
||||
|
||||
$this->view->table = $this->loadTable('syncproperty')
|
||||
->enforceFilter(Filter::where('rule_id', $rule_id))
|
||||
->setConnection($this->db());
|
||||
$this->setViewScript('list/table');
|
||||
$this->actions()->add(new Link(
|
||||
$this->translate('back'),
|
||||
'director/syncrule/property',
|
||||
['rule_id' => $ruleId],
|
||||
['class' => 'icon-left-big']
|
||||
));
|
||||
|
||||
$this->content()->add($form->handleRequest());
|
||||
$this->tabs(new SyncRuleTabs($rule))->activate('property');
|
||||
SyncpropertyTable::create($rule)->renderTo($this);
|
||||
}
|
||||
|
||||
public function historyAction()
|
||||
{
|
||||
$this->view->stayHere = true;
|
||||
|
||||
$db = $this->db();
|
||||
$id = $this->params->get('id');
|
||||
$rule = SyncRule::load($id, $db);
|
||||
|
||||
$this->prepareRuleTabs($id)->activate('history');
|
||||
$this->view->title = $this->translate('Sync history') . ': ' . $rule->rule_name;
|
||||
$this->view->table = $this->loadTable('syncRun')
|
||||
->enforceFilter(Filter::where('rule_id', $id))
|
||||
->setConnection($this->db());
|
||||
$this->setAutoRefreshInterval(30);
|
||||
$rule = $this->requireSyncRule();
|
||||
$this->tabs(new SyncRuleTabs($rule))->activate('history');
|
||||
$this->addTitle($this->translate('Sync history') . ': ' . $rule->rule_name);
|
||||
|
||||
if ($runId = $this->params->get('run_id')) {
|
||||
$this->loadSyncRun($runId);
|
||||
$run = SyncRun::load($runId, $this->db());
|
||||
$this->content()->add(new SyncRunDetails($run));
|
||||
}
|
||||
SyncRunTable::create($rule)->renderTo($this);
|
||||
}
|
||||
|
||||
protected function loadSyncRun($id)
|
||||
protected function requireSyncRule($key = 'id')
|
||||
{
|
||||
$db = $this->db();
|
||||
$this->view->run = SyncRun::load($id, $db);
|
||||
if ($this->view->run->last_former_activity !== null) {
|
||||
$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) {
|
||||
$tabs = $this->getTabs()->add('show', array(
|
||||
'url' => 'director/syncrule',
|
||||
'urlParams' => array('id' => $ruleId),
|
||||
'label' => $this->translate('Sync rule'),
|
||||
))->add('edit', array(
|
||||
'url' => 'director/syncrule/edit',
|
||||
'urlParams' => array('id' => $ruleId),
|
||||
'label' => $this->translate('Modify'),
|
||||
))->add('property', array(
|
||||
'label' => $this->translate('Properties'),
|
||||
'url' => 'director/syncrule/property',
|
||||
'urlParams' => array('rule_id' => $ruleId)
|
||||
));
|
||||
|
||||
$tabs->add('history', array(
|
||||
'label' => $this->translate('History'),
|
||||
'url' => 'director/syncrule/history',
|
||||
'urlParams' => array('id' => $ruleId)
|
||||
));
|
||||
|
||||
return $tabs;
|
||||
} else {
|
||||
return $this->getTabs()->add('add', array(
|
||||
'url' => 'director/syncrule/add',
|
||||
'label' => $this->translate('Sync rule'),
|
||||
));
|
||||
}
|
||||
$id = $this->params->get($key);
|
||||
return SyncRule::load($id, $this->db());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
<?php
|
||||
|
||||
// TODO: Check whether this can be removed
|
||||
namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Icinga\Module\Director\Objects\SyncRule;
|
||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||
use Icinga\Module\Director\Web\Form\DirectorForm;
|
||||
|
||||
class SyncCheckForm extends QuickForm
|
||||
class SyncCheckForm extends DirectorForm
|
||||
{
|
||||
/** @var SyncRule */
|
||||
protected $rule;
|
||||
|
|
|
@ -10,15 +10,15 @@ class SyncRuleForm extends DirectorObjectForm
|
|||
{
|
||||
$availableTypes = array(
|
||||
'host' => $this->translate('Host'),
|
||||
'hostgroup' => $this->translate('Host group'),
|
||||
'hostgroup' => $this->translate('Host Group'),
|
||||
'service' => $this->translate('Service'),
|
||||
'servicegroup' => $this->translate('Service group'),
|
||||
'servicegroup' => $this->translate('Service Group'),
|
||||
'serviceSet' => $this->translate('Service Set'),
|
||||
'user' => $this->translate('User'),
|
||||
'usergroup' => $this->translate('User group'),
|
||||
'datalistEntry' => $this->translate('Datalist entry'),
|
||||
'usergroup' => $this->translate('User Group'),
|
||||
'datalistEntry' => $this->translate('Data List Entry'),
|
||||
'command' => $this->translate('Command'),
|
||||
'timePeriod' => $this->translate('Time period'),
|
||||
'timePeriod' => $this->translate('Time Period'),
|
||||
'endpoint' => $this->translate('Endpoint'),
|
||||
'zone' => $this->translate('Zone'),
|
||||
);
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
<?php
|
||||
|
||||
// TODO: Check whether this can be removed
|
||||
namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Icinga\Module\Director\Objects\SyncRule;
|
||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||
use Icinga\Module\Director\Web\Form\DirectorForm;
|
||||
|
||||
class SyncRunForm extends QuickForm
|
||||
class SyncRunForm extends DirectorForm
|
||||
{
|
||||
/** @var SyncRule */
|
||||
protected $rule;
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
use Exception;
|
||||
|
||||
class SyncRunTable extends QuickTable
|
||||
{
|
||||
protected $revalidate = false;
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 'sr.id',
|
||||
'rule_id' => 'sr.rule_id',
|
||||
'rule_name' => 'sr.rule_name',
|
||||
'start_time' => 'sr.start_time',
|
||||
'duration_ms' => 'sr.duration_ms',
|
||||
'objects_deleted' => 'sr.objects_deleted',
|
||||
'objects_created' => 'sr.objects_created',
|
||||
'objects_modified' => 'sr.objects_modified',
|
||||
'last_former_activity' => 'sr.last_former_activity',
|
||||
'last_related_activity' => 'sr.last_related_activity',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->url(
|
||||
'director/syncrule/history',
|
||||
array(
|
||||
'id' => $row->rule_id,
|
||||
'run_id' => $row->id,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$singleRule = false;
|
||||
|
||||
foreach ($this->enforcedFilters as $filter) {
|
||||
if (in_array('rule_id', $filter->listFilteredColumns())) {
|
||||
$singleRule = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$view = $this->view();
|
||||
|
||||
if ($singleRule) {
|
||||
return array(
|
||||
'start_time' => $view->translate('Start time'),
|
||||
'objects_created' => $view->translate('Created'),
|
||||
'objects_modified' => $view->translate('Modified'),
|
||||
'objects_deleted' => $view->translate('Deleted'),
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
'rule_name' => $view->translate('Rule name'),
|
||||
'start_time' => $view->translate('Start time'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('sr' => 'sync_run'),
|
||||
array()
|
||||
)->order('start_time DESC');
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
|
||||
class SyncpropertyTable extends QuickTable
|
||||
{
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 'p.id',
|
||||
'rule_id' => 'p.rule_id',
|
||||
'rule_name' => 'r.rule_name',
|
||||
'source_id' => 'p.source_id',
|
||||
'source_name' => 's.source_name',
|
||||
'source_expression' => 'p.source_expression',
|
||||
'destination_field' => 'p.destination_field',
|
||||
'priority' => 'p.priority',
|
||||
'filter_expression' => 'p.filter_expression',
|
||||
'merge_policy' => 'p.merge_policy'
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->url(
|
||||
'director/syncrule/editproperty',
|
||||
array(
|
||||
'id' => $row->id,
|
||||
'rule_id' => $row->rule_id,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
//'rule_name' => $view->translate('Rule name'),
|
||||
'source_name' => $view->translate('Source name'),
|
||||
'source_expression' => $view->translate('Source field'),
|
||||
'destination_field' => $view->translate('Destination')
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('r' => 'sync_rule'),
|
||||
array()
|
||||
)->join(
|
||||
array('p' => 'sync_property'),
|
||||
'r.id = p.rule_id',
|
||||
array()
|
||||
)->join(
|
||||
array('s' => 'import_source'),
|
||||
's.id = p.source_id',
|
||||
array()
|
||||
)->order('id');
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
<div class="controls">
|
||||
<?= $this->tabs ?>
|
||||
<h1><?= $this->escape($this->title) ?></h1>
|
||||
<span class="action-links"<?php if (! $this->stayHere): ?> data-base-target="_next"<?php endif ?>>
|
||||
<?= $this->addLink ?>
|
||||
</span>
|
||||
<?= $this->filterEditor ?>
|
||||
<?= $this->table->getPaginator() ?>
|
||||
</div>
|
||||
|
||||
<div class="content"<?php if (! $this->stayHere): ?> data-base-target="_next"<?php endif ?>>
|
||||
<?php if ($this->run): ?>
|
||||
<h3><?= $this->translate('Sync run details') ?></h3>
|
||||
<?= $this->render('syncrule/syncRunDetails.phtml') ?>
|
||||
<?php endif ?>
|
||||
<div data-base-target="_main">
|
||||
<?= $this->table->render() ?>
|
||||
</div>
|
||||
</div>
|
|
@ -1,68 +0,0 @@
|
|||
<div class="controls">
|
||||
<?= $this->tabs ?>
|
||||
<h1><?= $this->escape($this->title) ?></h1>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<p><?= $this->escape($rule->description) ?></p>
|
||||
<?php if (! $rule->hasSyncProperties()): ?>
|
||||
<p class="warning">
|
||||
<?= sprintf(
|
||||
$this->translate('You must define some %s before you can run this Sync Rule'),
|
||||
$this->qlink('Sync Properties', 'director/syncrule/property', array('rule_id' => $rule->id))
|
||||
)
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php return; endif ?>
|
||||
<?php if (! $this->run): ?>
|
||||
<p class="warning">
|
||||
<?= $this->translate('This Sync Rule has never been run before.') ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
<?php if ($rule->sync_state === 'unknown'): ?>
|
||||
<p><?= $this->translate(
|
||||
"It's currently unknown whether we are in sync with this rule."
|
||||
. ' You should either check for changes or trigger a new Sync Run.'
|
||||
) ?></p>
|
||||
<?php elseif ($rule->sync_state === 'in-sync'): ?>
|
||||
<p><?= sprintf(
|
||||
$this->translate(
|
||||
'This Sync Rule was last found to by in Sync at %s.'
|
||||
),
|
||||
$rule->last_attempt
|
||||
) /*
|
||||
TODO: check whether...
|
||||
- there have been imports since then, differing from former ones
|
||||
- there have been activities since then
|
||||
*/ ?></p>
|
||||
<?php elseif ($rule->sync_state === 'pending-changes'): ?>
|
||||
<p class="warning"><?= $this->translate(
|
||||
'There are pending changes for this Sync Rule. You should trigger a new'
|
||||
. ' Sync Run.'
|
||||
) ?></p>
|
||||
<?php elseif ($rule->sync_state === 'failing'): ?>
|
||||
<p class="error"><?= sprintf(
|
||||
$this->translate(
|
||||
'This Sync Rule failed when last checked at %s: %s'
|
||||
),
|
||||
$rule->last_attempt,
|
||||
$rule->last_error_message
|
||||
) /*
|
||||
TODO: check whether...
|
||||
- there have been imports since then, differing from former ones
|
||||
- there have been activities since then
|
||||
*/ ?></p>
|
||||
<?php endif ?>
|
||||
<?= $this->checkForm ?>
|
||||
<?= $this->runForm ?>
|
||||
<?php if ($this->run): ?>
|
||||
<h3><?= $this->translate('Last sync run details') ?></h3>
|
||||
<?= $this->render('syncrule/syncRunDetails.phtml') ?><br />
|
||||
<?php if ($run->rule_name !== $rule->rule_name): ?>
|
||||
<?= $this->escape(sprintf(
|
||||
$this->translate("It has been renamed since then, its former name was %s"),
|
||||
$run->rule_name
|
||||
)) ?>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
$total = $run->objects_deleted + $run->objects_created + $run->objects_modified;
|
||||
if ($total === 0) {
|
||||
echo $this->translate('No changes have been made');
|
||||
} else {
|
||||
if ($total === 1) {
|
||||
echo $this->translate('One object has been modified');
|
||||
} else {
|
||||
printf(
|
||||
$this->translate('%s objects have been modified'),
|
||||
$total
|
||||
);
|
||||
}
|
||||
|
||||
$activityUrl = sprintf(
|
||||
'director/config/activities?id>%d&id<=%d',
|
||||
$formerId,
|
||||
$lastId
|
||||
);
|
||||
|
||||
$links = array();
|
||||
if ($run->objects_created > 0) {
|
||||
$links[] = $this->qlink(
|
||||
sprintf('%d created', $run->objects_created),
|
||||
$activityUrl,
|
||||
array('action' => 'create')
|
||||
);
|
||||
}
|
||||
if ($run->objects_modified > 0) {
|
||||
$links[] = $this->qlink(
|
||||
sprintf('%d modified', $run->objects_modified),
|
||||
$activityUrl,
|
||||
array('action' => 'modify')
|
||||
);
|
||||
}
|
||||
if ($run->objects_deleted > 0) {
|
||||
$links[] = $this->qlink(
|
||||
sprintf('%d deleted', $run->objects_deleted),
|
||||
$activityUrl,
|
||||
array('action' => 'delete')
|
||||
);
|
||||
}
|
||||
|
||||
if (count($links) > 1) {
|
||||
$links[] = $this->qlink(
|
||||
'Show all actions',
|
||||
$activityUrl
|
||||
);
|
||||
}
|
||||
|
||||
if (! empty($links)) {
|
||||
echo ': ' . implode(', ', $links);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,14 +0,0 @@
|
|||
<table class="key-value-table">
|
||||
<tr>
|
||||
<th><?= $this->translate('Start time') ?></th>
|
||||
<td><?= $this->escape($run->start_time) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= $this->translate('Duration') ?></th>
|
||||
<td><?= sprintf('%.2fs', $run->duration_ms / 1000) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= $this->translate('Activity') ?></th>
|
||||
<td data-base-target="_next"><?= $this->render('syncrule/runSummary.phtml') ?></td>
|
||||
</tr>
|
||||
</table>
|
|
@ -575,6 +575,8 @@ abstract class DirectorObjectForm extends DirectorForm
|
|||
'director/' . strtolower($this->getObjectShortClassName()),
|
||||
$object->getUrlParams()
|
||||
);
|
||||
} elseif ($object->hasProperty('id')) {
|
||||
$this->setSuccessUrl($this->getSuccessUrl()->with('id', $object->get('id')));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Module\Director\Objects\SyncRule;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class SyncRunTable extends ZfQueryBasedTable
|
||||
{
|
||||
/** @var SyncRule */
|
||||
protected $rule;
|
||||
|
||||
public static function create(SyncRule $rule)
|
||||
{
|
||||
$table = new static($rule->getConnection());
|
||||
$table->attributes()
|
||||
->set('data-base-target', '_self')
|
||||
->add('class', 'history');
|
||||
$table->rule = $rule;
|
||||
return $table;
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
$time = strtotime($row->start_time);
|
||||
$this->renderDayIfNew($time);
|
||||
return $this::tr([
|
||||
$this::td($this->makeSummary($row)),
|
||||
$this::td(new Link(
|
||||
strftime('%H:%M:%S', $time),
|
||||
'director/syncrule/history',
|
||||
[
|
||||
'id' => $row->rule_id,
|
||||
'run_id' => $row->id,
|
||||
]
|
||||
))
|
||||
]);
|
||||
}
|
||||
|
||||
protected function makeSummary($row)
|
||||
{
|
||||
$parts = [];
|
||||
if ($row->objects_created > 0) {
|
||||
$parts[] = sprintf(
|
||||
$this->translate('%d created'),
|
||||
$row->objects_created
|
||||
);
|
||||
}
|
||||
if ($row->objects_modified > 0) {
|
||||
$parts[] = sprintf(
|
||||
$this->translate('%d modified'),
|
||||
$row->objects_modified
|
||||
);
|
||||
}
|
||||
if ($row->objects_deleted > 0) {
|
||||
$parts[] = sprintf(
|
||||
$this->translate('%d deleted'),
|
||||
$row->objects_deleted
|
||||
);
|
||||
}
|
||||
|
||||
return implode(', ', $parts);
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('sr' => 'sync_run'),
|
||||
[
|
||||
'id' => 'sr.id',
|
||||
'rule_id' => 'sr.rule_id',
|
||||
'rule_name' => 'sr.rule_name',
|
||||
'start_time' => 'sr.start_time',
|
||||
'duration_ms' => 'sr.duration_ms',
|
||||
'objects_deleted' => 'sr.objects_deleted',
|
||||
'objects_created' => 'sr.objects_created',
|
||||
'objects_modified' => 'sr.objects_modified',
|
||||
'last_former_activity' => 'sr.last_former_activity',
|
||||
'last_related_activity' => 'sr.last_related_activity',
|
||||
]
|
||||
)->where(
|
||||
'sr.rule_id = ?',
|
||||
$this->rule->get('id')
|
||||
)->order('start_time DESC');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Module\Director\Objects\SyncRule;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class SyncpropertyTable extends ZfQueryBasedTable
|
||||
{
|
||||
/** @var SyncRule */
|
||||
protected $rule;
|
||||
|
||||
public static function create(SyncRule $rule)
|
||||
{
|
||||
$table = new static($rule->getConnection());
|
||||
$table->attributes()->set('data-base-target', '_self');
|
||||
$table->rule = $rule;
|
||||
return $table;
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
return $this::tr([
|
||||
$this::td($row->source_name),
|
||||
$this::td($row->source_expression),
|
||||
$this::td(new Link(
|
||||
$row->destination_field,
|
||||
'director/syncrule/editproperty',
|
||||
[
|
||||
'id' => $row->id,
|
||||
'rule_id' => $row->rule_id,
|
||||
]
|
||||
)),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return [
|
||||
$this->translate('Source name'),
|
||||
$this->translate('Source field'),
|
||||
$this->translate('Destination')
|
||||
];
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
['r' => 'sync_rule'],
|
||||
[
|
||||
'id' => 'p.id',
|
||||
'rule_id' => 'p.rule_id',
|
||||
'rule_name' => 'r.rule_name',
|
||||
'source_id' => 'p.source_id',
|
||||
'source_name' => 's.source_name',
|
||||
'source_expression' => 'p.source_expression',
|
||||
'destination_field' => 'p.destination_field',
|
||||
'priority' => 'p.priority',
|
||||
'filter_expression' => 'p.filter_expression',
|
||||
'merge_policy' => 'p.merge_policy'
|
||||
]
|
||||
)->join(
|
||||
['p' => 'sync_property'],
|
||||
'r.id = p.rule_id',
|
||||
[]
|
||||
)->join(
|
||||
['s' => 'import_source'],
|
||||
's.id = p.source_id',
|
||||
[]
|
||||
)->where(
|
||||
'r.id = ?',
|
||||
$this->rule->get('id')
|
||||
)->order('p.priority');
|
||||
}
|
||||
}
|
|
@ -71,6 +71,12 @@ table.common-table {
|
|||
}
|
||||
}
|
||||
|
||||
table.history {
|
||||
td:last-of-type {
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
|
||||
span.disabled {
|
||||
cursor: no-drop;
|
||||
color: @gray-light;
|
||||
|
@ -630,7 +636,6 @@ ul.main-actions {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#layout.minimal-layout div.content form {
|
||||
dt, dd {
|
||||
display: block;
|
||||
|
|
Loading…
Reference in New Issue