diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
commit | cd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /application/forms/DeployConfigForm.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-upstream.tar.xz icingaweb2-module-director-upstream.zip |
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/forms/DeployConfigForm.php')
-rw-r--r-- | application/forms/DeployConfigForm.php | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/application/forms/DeployConfigForm.php b/application/forms/DeployConfigForm.php new file mode 100644 index 0000000..0b817fa --- /dev/null +++ b/application/forms/DeployConfigForm.php @@ -0,0 +1,121 @@ +<?php + +namespace Icinga\Module\Director\Forms; + +use Icinga\Exception\IcingaException; +use Icinga\Module\Director\Core\DeploymentApiInterface; +use Icinga\Module\Director\IcingaConfig\IcingaConfig; +use Icinga\Module\Director\Web\Form\DirectorForm; + +class DeployConfigForm extends DirectorForm +{ + use DeployFormsBug7530; + + /** @var DeploymentApiInterface */ + private $api; + + /** @var string */ + private $checksum; + + /** @var int */ + private $deploymentId; + + public function init() + { + $this->setAttrib('class', 'inline'); + } + + public function setup() + { + $activities = $this->db->countActivitiesSinceLastDeployedConfig(); + if ($this->deploymentId) { + $label = $this->translate('Re-deploy now'); + } elseif ($activities === 0) { + $label = $this->translate('There are no pending changes. Deploy anyway'); + } else { + $label = sprintf( + $this->translate('Deploy %d pending changes'), + $activities + ); + } + + if ($this->deploymentId) { + $deployIcon = 'reply-all'; + } else { + $deployIcon = 'forward'; + } + + $this->addHtml( + $this->getView()->icon( + $deployIcon, + $label, + array('class' => 'link-color') + ) . '<nobr>' + ); + + $el = $this->createElement('submit', 'btn_deploy', array( + 'label' => $label, + 'escape' => false, + 'decorators' => array('ViewHelper'), + 'class' => 'link-button ' . $deployIcon, + )); + + $this->addHtml('</nobr>'); + $this->submitButtonName = $el->getName(); + $this->setSubmitLabel($label); + $this->addElement($el); + } + + public function onSuccess() + { + if ($this->skipBecauseOfBug7530()) { + return; + } + + $db = $this->db; + $msg = $this->translate('Config has been submitted, validation is going on'); + $this->setSuccessMessage($msg); + + $isApiRequest = $this->getRequest()->isApiRequest(); + if ($this->checksum) { + $config = IcingaConfig::load(hex2bin($this->checksum), $db); + } else { + $config = IcingaConfig::generate($db); + } + + $this->api->wipeInactiveStages($db); + + if ($this->api->dumpConfig($config, $db)) { + if ($isApiRequest) { + die('Api not ready'); + // return $this->sendJson((object) array('checksum' => $checksum)); + } else { + $this->setSuccessUrl('director/config/deployments'); + $this->setSuccessMessage( + $this->translate('Config has been submitted, validation is going on') + ); + } + parent::onSuccess(); + } else { + throw new IcingaException($this->translate('Config deployment failed')); + } + } + + public function setChecksum($checksum) + { + $this->checksum = $checksum; + return $this; + } + + public function setDeploymentId($id) + { + $this->deploymentId = $id; + return $this; + } + + public function setApi(DeploymentApiInterface $api) + { + $this->api = $api; + return $this; + } +} |