DirectorDatafield: cleanup, types
This commit is contained in:
parent
915f57db99
commit
b55df21c21
|
@ -2,12 +2,9 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Director\Objects;
|
namespace Icinga\Module\Director\Objects;
|
||||||
|
|
||||||
use gipfl\Json\JsonString;
|
|
||||||
use Icinga\Module\Director\Core\Json;
|
|
||||||
use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
|
use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
use Icinga\Module\Director\DirectorObject\Automation\CompareBasketObject;
|
use Icinga\Module\Director\DirectorObject\Automation\CompareBasketObject;
|
||||||
use Icinga\Module\Director\Exception\JsonEncodeException;
|
|
||||||
use Icinga\Module\Director\Forms\IcingaServiceForm;
|
use Icinga\Module\Director\Forms\IcingaServiceForm;
|
||||||
use Icinga\Module\Director\Hook\DataTypeHook;
|
use Icinga\Module\Director\Hook\DataTypeHook;
|
||||||
use Icinga\Module\Director\Resolver\OverriddenVarsResolver;
|
use Icinga\Module\Director\Resolver\OverriddenVarsResolver;
|
||||||
|
@ -22,6 +19,8 @@ class DirectorDatafield extends DbObjectWithSettings
|
||||||
protected $keyName = 'id';
|
protected $keyName = 'id';
|
||||||
protected $autoincKeyName = 'id';
|
protected $autoincKeyName = 'id';
|
||||||
protected $uuidColumn = 'uuid';
|
protected $uuidColumn = 'uuid';
|
||||||
|
protected $settingsTable = 'director_datafield_setting';
|
||||||
|
protected $settingsRemoteId = 'datafield_id';
|
||||||
|
|
||||||
protected $defaultProperties = [
|
protected $defaultProperties = [
|
||||||
'id' => null,
|
'id' => null,
|
||||||
|
@ -38,13 +37,8 @@ class DirectorDatafield extends DbObjectWithSettings
|
||||||
'category' => 'DirectorDatafieldCategory'
|
'category' => 'DirectorDatafieldCategory'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $settingsTable = 'director_datafield_setting';
|
/** @var ?DirectorDatafieldCategory */
|
||||||
|
|
||||||
protected $settingsRemoteId = 'datafield_id';
|
|
||||||
|
|
||||||
/** @var DirectorDatafieldCategory|null */
|
|
||||||
private $category;
|
private $category;
|
||||||
|
|
||||||
private $object;
|
private $object;
|
||||||
|
|
||||||
public static function fromDbRow($row, Db $connection)
|
public static function fromDbRow($row, Db $connection)
|
||||||
|
@ -72,10 +66,9 @@ class DirectorDatafield extends DbObjectWithSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return DirectorDatafieldCategory|null
|
|
||||||
* @throws \Icinga\Exception\NotFoundError
|
* @throws \Icinga\Exception\NotFoundError
|
||||||
*/
|
*/
|
||||||
public function getCategory()
|
public function getCategory(): ?DirectorDatafieldCategory
|
||||||
{
|
{
|
||||||
if ($this->category) {
|
if ($this->category) {
|
||||||
return $this->category;
|
return $this->category;
|
||||||
|
@ -86,7 +79,7 @@ class DirectorDatafield extends DbObjectWithSettings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCategoryName()
|
public function getCategoryName(): ?string
|
||||||
{
|
{
|
||||||
$category = $this->getCategory();
|
$category = $this->getCategory();
|
||||||
if ($category === null) {
|
if ($category === null) {
|
||||||
|
@ -107,23 +100,20 @@ class DirectorDatafield extends DbObjectWithSettings
|
||||||
}
|
}
|
||||||
$this->category = $category;
|
$this->category = $category;
|
||||||
} else {
|
} else {
|
||||||
if (DirectorDatafieldCategory::exists($category, $this->getConnection())) {
|
if ($category = DirectorDatafieldCategory::loadOptional($category, $this->getConnection())) {
|
||||||
$this->setCategory(DirectorDatafieldCategory::load($category, $this->getConnection()));
|
$this->setCategory($category);
|
||||||
} else {
|
} else {
|
||||||
$this->setCategory(DirectorDatafieldCategory::create([
|
$this->setCategory(DirectorDatafieldCategory::create([
|
||||||
'category_name' => $category
|
'category_name' => $category
|
||||||
], $this->getConnection()));
|
], $this->getConnection()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return object
|
|
||||||
* @throws \Icinga\Exception\NotFoundError
|
* @throws \Icinga\Exception\NotFoundError
|
||||||
*/
|
*/
|
||||||
public function export()
|
public function export(): stdClass
|
||||||
{
|
{
|
||||||
$plain = (object) $this->getProperties();
|
$plain = (object) $this->getProperties();
|
||||||
unset($plain->id);
|
unset($plain->id);
|
||||||
|
@ -149,7 +139,6 @@ class DirectorDatafield extends DbObjectWithSettings
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \Icinga\Exception\NotFoundError
|
* @throws \Icinga\Exception\NotFoundError
|
||||||
* @throws JsonEncodeException
|
|
||||||
*/
|
*/
|
||||||
public static function import(stdClass $plain, Db $db): DirectorDatafield
|
public static function import(stdClass $plain, Db $db): DirectorDatafield
|
||||||
{
|
{
|
||||||
|
@ -210,7 +199,7 @@ class DirectorDatafield extends DbObjectWithSettings
|
||||||
return $this->object;
|
return $this->object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormElement(DirectorObjectForm $form, $name = null)
|
public function getFormElement(DirectorObjectForm $form, $name = null): ?ZfElement
|
||||||
{
|
{
|
||||||
$className = $this->get('datatype');
|
$className = $this->get('datatype');
|
||||||
|
|
||||||
|
@ -292,7 +281,7 @@ class DirectorDatafield extends DbObjectWithSettings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function eventuallyGetResolvedCommandVar(IcingaObject $object, $varName)
|
protected function eventuallyGetResolvedCommandVar(IcingaObject $object, $varName): ?array
|
||||||
{
|
{
|
||||||
if (! $object->hasRelation('check_command')) {
|
if (! $object->hasRelation('check_command')) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue