[icinga-checkins] icinga.org: icingaweb2-module-director/master: SyncRun/CheckForm: add new forms
git at icinga.org
git at icinga.org
Mon Jun 27 09:17:09 CEST 2016
Module: icingaweb2-module-director
Branch: master
Commit: e71dcea9d65ccc4acfb8764496dd7ba2fc54245c
URL: https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=e71dcea9d65ccc4acfb8764496dd7ba2fc54245c
Author: Thomas Gelf <thomas at gelf.net>
Date: Sat Jun 25 23:01:30 2016 +0200
SyncRun/CheckForm: add new forms
---
application/forms/SyncCheckForm.php | 65 +++++++++++++++++++++++++++++++++++
application/forms/SyncRunForm.php | 46 +++++++++++++++++++++++++
2 files changed, 111 insertions(+)
diff --git a/application/forms/SyncCheckForm.php b/application/forms/SyncCheckForm.php
new file mode 100644
index 0000000..1f2550e
--- /dev/null
+++ b/application/forms/SyncCheckForm.php
@@ -0,0 +1,65 @@
+<?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 SyncCheckForm extends QuickForm
+{
+ protected $rule;
+
+ public function setSyncRule(SyncRule $rule)
+ {
+ $this->rule = $rule;
+ return $this;
+ }
+
+ public function setup()
+ {
+ $this->submitLabel = $this->translate(
+ 'Check for changes'
+ );
+ }
+
+ public function onSuccess()
+ {
+ if ($this->rule->checkForChanges()) {
+ $this->setSuccessMessage(
+ $this->translate(('This Sync Rule would apply new changes'))
+ );
+ $html = '';
+ $sum = array('create' => 0, 'modify' => 0, 'delete' => 0);
+
+ // TODO: Preview them? Like "hosta, hostb and 4 more would be...
+ foreach ($this->rule->getExpectedModifications() as $object) {
+ if ($object->shouldBeRemoved()) {
+ $sum['delete']++;
+ } elseif (! $object->hasBeenLoadedFromDb()) {
+ $sum['create']++;
+ } elseif ($object->hasBeenModified()) {
+ $sum['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->sync_state === 'in-sync') {
+ $this->setSuccessMessage(
+ $this->translate('Nothing would change, this rule is still in sync')
+ );
+ parent::onSuccess();
+ } else {
+ $this->addError($this->translate('Checking this sync rule failed'));
+ }
+
+ }
+}
diff --git a/application/forms/SyncRunForm.php b/application/forms/SyncRunForm.php
new file mode 100644
index 0000000..9c30830
--- /dev/null
+++ b/application/forms/SyncRunForm.php
@@ -0,0 +1,46 @@
+<?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();
+ }
+}
More information about the icinga-checkins
mailing list