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/IcingaFlatVar.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/Objects/IcingaFlatVar.php')
-rw-r--r-- | library/Director/Objects/IcingaFlatVar.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/library/Director/Objects/IcingaFlatVar.php b/library/Director/Objects/IcingaFlatVar.php new file mode 100644 index 0000000..3bbf81c --- /dev/null +++ b/library/Director/Objects/IcingaFlatVar.php @@ -0,0 +1,61 @@ +<?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 IcingaFlatVar extends DbObject +{ + protected $table = 'icinga_flat_var'; + + protected $keyName = [ + 'var_checksum', + 'flatname_checksum' + ]; + + protected $defaultProperties = [ + 'var_checksum' => null, + 'flatname_checksum' => null, + 'flatname' => null, + 'flatvalue' => null, + ]; + + protected $binaryProperties = [ + 'var_checksum', + 'flatname_checksum', + ]; + + public static function generateForCustomVar(CustomVariable $var, Db $db) + { + $flatVars = static::forCustomVar($var, $db); + foreach ($flatVars as $flat) { + $flat->store(); + } + + return $flatVars; + } + + public static function forCustomVar(CustomVariable $var, Db $db) + { + $flat = []; + $varSum = $var->checksum(); + $var->flatten($flat, $var->getKey()); + $flatVars = []; + + foreach ($flat as $name => $value) { + $flatVar = static::create([ + 'var_checksum' => $varSum, + 'flatname_checksum' => sha1($name, true), + 'flatname' => $name, + 'flatvalue' => $value, + ], $db); + + $flatVar->store(); + $flatVars[] = $flatVar; + } + + return $flatVars; + } +} |