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 /library/Director/Deployment/ConditionalConfigRenderer.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 'library/Director/Deployment/ConditionalConfigRenderer.php')
-rw-r--r-- | library/Director/Deployment/ConditionalConfigRenderer.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/library/Director/Deployment/ConditionalConfigRenderer.php b/library/Director/Deployment/ConditionalConfigRenderer.php new file mode 100644 index 0000000..0b24418 --- /dev/null +++ b/library/Director/Deployment/ConditionalConfigRenderer.php @@ -0,0 +1,64 @@ +<?php + +namespace Icinga\Module\Director\Deployment; + +use Icinga\Exception\NotFoundError; +use Icinga\Module\Director\Db; +use Icinga\Module\Director\IcingaConfig\IcingaConfig; +use Icinga\Module\Director\Objects\DirectorActivityLog; + +class ConditionalConfigRenderer +{ + /** @var Db */ + protected $db; + + protected $forceRendering = false; + + public function __construct(Db $connection) + { + $this->db = $connection; + } + + public function forceRendering($force = true) + { + $this->forceRendering = $force; + + return $this; + } + + public function getConfig() + { + if ($this->shouldGenerate()) { + return IcingaConfig::generate($this->db); + } + + return $this->loadLatestActivityConfig(); + } + + protected function loadLatestActivityConfig() + { + $db = $this->db; + + return IcingaConfig::loadByActivityChecksum($db->getLastActivityChecksum(), $db); + } + + protected function shouldGenerate() + { + return $this->forceRendering || !$this->configForLatestActivityExists(); + } + + protected function configForLatestActivityExists() + { + $db = $this->db; + try { + $latestActivity = DirectorActivityLog::loadLatest($db); + } catch (NotFoundError $e) { + return false; + } + + return IcingaConfig::existsForActivityChecksum( + bin2hex($latestActivity->get('checksum')), + $db + ); + } +} |