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 --- library/Director/Objects/IcingaFlatVar.php | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 library/Director/Objects/IcingaFlatVar.php (limited to 'library/Director/Objects/IcingaFlatVar.php') 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 @@ + 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; + } +} -- cgit v1.2.3