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

47 lines
1.1 KiB
PHP
Raw Normal View History

2016-06-25 23:01:30 +02:00
<?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;
class SyncRunForm extends QuickForm
{
protected $rule;
public function setSyncRule(SyncRule $rule)
{
$this->rule = $rule;
return $this;
}
public function setup()
{
$this->submitLabel = $this->translate(
'Trigger this Sync'
);
}
public function onSuccess()
{
$rule = $this->rule;
$changed = $rule->applyChanges();
if ($changed) {
$runId = $rule->getCurrentSyncRunId();
$this->setSuccessMessage(
$this->translate(('Source has successfully been synchronized'))
);
} elseif ($rule->sync_state === 'in-sync') {
$this->setSuccessMessage(
$this->translate('Nothing changed, rule is in sync')
);
} else {
$this->addError($this->translate('Synchronization failed'));
}
parent::onSuccess();
}
}