diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
commit | f66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /application/forms/SyncCheckForm.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip |
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | application/forms/SyncCheckForm.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/application/forms/SyncCheckForm.php b/application/forms/SyncCheckForm.php new file mode 100644 index 0000000..8fb3bd0 --- /dev/null +++ b/application/forms/SyncCheckForm.php @@ -0,0 +1,69 @@ +<?php + +namespace Icinga\Module\Director\Forms; + +use Icinga\Module\Director\Objects\DirectorActivityLog; +use Icinga\Module\Director\Objects\SyncRule; +use Icinga\Module\Director\Web\Form\DirectorForm; + +class SyncCheckForm extends DirectorForm +{ + /** @var SyncRule */ + 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('Check for changes'), + 'decorators' => array('ViewHelper') + )); + } + + public function onSuccess() + { + if ($this->rule->checkForChanges()) { + $this->notifySuccess( + $this->translate(('This Sync Rule would apply new changes')) + ); + $sum = [ + DirectorActivityLog::ACTION_CREATE => 0, + DirectorActivityLog::ACTION_MODIFY => 0, + DirectorActivityLog::ACTION_DELETE => 0 + ]; + + // TODO: Preview them? Like "hosta, hostb and 4 more would be... + foreach ($this->rule->getExpectedModifications() as $object) { + if ($object->shouldBeRemoved()) { + $sum[DirectorActivityLog::ACTION_DELETE]++; + } elseif (! $object->hasBeenLoadedFromDb()) { + $sum[DirectorActivityLog::ACTION_CREATE]++; + } elseif ($object->hasBeenModified()) { + $sum[DirectorActivityLog::ACTION_MODIFY]++; + } + } + + /** + if ($sum['modify'] === 1) { + $html .= $this->translate('One object would be modified' + } elseif ($sum['modify'] > 1) { + } + */ + $html = '<pre>' . print_r($sum, 1) . '</pre>'; + + $this->addHtml($html); + } elseif ($this->rule->get('sync_state') === 'in-sync') { + $this->notifySuccess( + $this->translate('Nothing would change, this rule is still in sync') + ); + } else { + $this->addError($this->translate('Checking this sync rule failed')); + } + } +} |