icingaweb2-module-director/application/forms/SyncRunForm.php

46 lines
1.1 KiB
PHP
Raw Normal View History

2016-06-25 23:01:30 +02:00
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Objects\SyncRule;
use Icinga\Module\Director\Web\Form\DirectorForm;
2016-06-25 23:01:30 +02:00
class SyncRunForm extends DirectorForm
2016-06-25 23:01:30 +02:00
{
2016-11-01 18:28:36 +01:00
/** @var SyncRule */
2016-06-25 23:01:30 +02:00
protected $rule;
public function setSyncRule(SyncRule $rule)
{
$this->rule = $rule;
return $this;
}
public function setup()
{
$this->submitLabel = false;
$this->addElement('submit', 'submit', array(
'label' => $this->translate('Trigger this Sync'),
'decorators' => array('ViewHelper')
));
2016-06-25 23:01:30 +02:00
}
public function onSuccess()
{
$rule = $this->rule;
$changed = $rule->applyChanges();
if ($changed) {
$this->setSuccessMessage(
$this->translate(('Source has successfully been synchronized'))
);
2016-11-01 18:28:36 +01:00
} elseif ($rule->get('sync_state') === 'in-sync') {
$this->notifySuccess(
2016-06-25 23:01:30 +02:00
$this->translate('Nothing changed, rule is in sync')
);
} else {
$this->addError($this->translate('Synchronization failed'));
}
}
}