From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- application/forms/DeployConfigForm.php | 121 +++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 application/forms/DeployConfigForm.php (limited to 'application/forms/DeployConfigForm.php') 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 @@ +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') + ) . '' + ); + + $el = $this->createElement('submit', 'btn_deploy', array( + 'label' => $label, + 'escape' => false, + 'decorators' => array('ViewHelper'), + 'class' => 'link-button ' . $deployIcon, + )); + + $this->addHtml(''); + $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; + } +} -- cgit v1.2.3