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/Objects/IcingaVar.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-- | library/Director/Objects/IcingaVar.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/library/Director/Objects/IcingaVar.php b/library/Director/Objects/IcingaVar.php new file mode 100644 index 0000000..10addf2 --- /dev/null +++ b/library/Director/Objects/IcingaVar.php @@ -0,0 +1,72 @@ +<?php + +namespace Icinga\Module\Director\Objects; + +use Icinga\Module\Director\CustomVariable\CustomVariable; +use Icinga\Module\Director\Data\Db\DbObject; +use Icinga\Module\Director\Db; + +class IcingaVar extends DbObject +{ + protected $table = 'icinga_var'; + + protected $keyName = 'checksum'; + + /** @var CustomVariable */ + protected $var; + + protected $defaultProperties = [ + 'checksum' => null, + 'rendered_checksum' => null, + 'varname' => null, + 'varvalue' => null, + 'rendered' => null + ]; + + protected $binaryProperties = [ + 'checksum', + 'rendered_checksum', + ]; + + /** + * @param CustomVariable $customVar + * @param Db $db + * + * @return static + */ + public static function forCustomVar(CustomVariable $customVar, Db $db) + { + $rendered = $customVar->render(); + + $var = static::create(array( + 'checksum' => $customVar->checksum(), + 'rendered_checksum' => sha1($rendered, true), + 'varname' => $customVar->getKey(), + 'varvalue' => $customVar->toJson(), + 'rendered' => $rendered, + ), $db); + + $var->var = $customVar; + + return $var; + } + + /** + * @param CustomVariable $customVar + * @param Db $db + * + * @return static + * @throws \Icinga\Module\Director\Exception\DuplicateKeyException + */ + public static function generateForCustomVar(CustomVariable $customVar, Db $db) + { + $var = static::forCustomVar($customVar, $db); + $var->store(); + return $var; + } + + protected function onInsert() + { + IcingaFlatVar::generateForCustomVar($this->var, $this->getConnection()); + } +} |