2016-11-10 20:03:29 +01:00
|
|
|
<?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 = array(
|
|
|
|
'checksum',
|
|
|
|
'flatname_checksum'
|
|
|
|
);
|
|
|
|
|
2018-10-30 16:40:17 +01:00
|
|
|
protected $defaultProperties = [
|
2016-11-10 20:03:29 +01:00
|
|
|
'var_checksum' => null,
|
|
|
|
'flatname_checksum' => null,
|
|
|
|
'flatname' => null,
|
|
|
|
'flatvalue' => null,
|
2018-10-30 16:40:17 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
protected $binaryProperties = [
|
|
|
|
'var_checksum',
|
|
|
|
'flatname_checksum',
|
|
|
|
];
|
2016-11-10 20:03:29 +01:00
|
|
|
|
|
|
|
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 = array();
|
|
|
|
$varSum = $var->checksum();
|
|
|
|
$var->flatten($flat, $var->getKey());
|
|
|
|
$flatVars = array();
|
|
|
|
|
|
|
|
foreach ($flat as $name => $value) {
|
|
|
|
$flatVar = static::create(array(
|
|
|
|
'var_checksum' => $varSum,
|
|
|
|
'flatname_checksum' => sha1($name, true),
|
|
|
|
'flatname' => $name,
|
|
|
|
'flatvalue' => $value,
|
|
|
|
), $db);
|
|
|
|
|
|
|
|
$flatVar->store();
|
|
|
|
$flatVars[] = $flatVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $flatVars;
|
|
|
|
}
|
|
|
|
}
|