Objects/*, CVs, others: unify setBeingLoadedFromDb
This commit is contained in:
parent
835d01cdec
commit
57c4dda117
|
@ -181,7 +181,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
|
||||||
$vars->vars[$row->varname] = CustomVariable::fromDbRow($row);
|
$vars->vars[$row->varname] = CustomVariable::fromDbRow($row);
|
||||||
}
|
}
|
||||||
$vars->refreshIndex();
|
$vars->refreshIndex();
|
||||||
$vars->setUnmodified();
|
$vars->setBeingLoadedFromDb();
|
||||||
return $vars;
|
return $vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
|
||||||
$vars->vars[$row->varname] = CustomVariable::fromDbRow($row);
|
$vars->vars[$row->varname] = CustomVariable::fromDbRow($row);
|
||||||
}
|
}
|
||||||
$vars->refreshIndex();
|
$vars->refreshIndex();
|
||||||
$vars->setUnmodified();
|
$vars->setBeingLoadedFromDb();
|
||||||
|
|
||||||
return $vars;
|
return $vars;
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setUnmodified();
|
$this->setBeingLoadedFromDb();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($key)
|
public function get($key)
|
||||||
|
@ -264,14 +264,16 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUnmodified()
|
public function setBeingLoadedFromDb()
|
||||||
{
|
{
|
||||||
$this->modified = false;
|
$this->modified = false;
|
||||||
$this->storedVars = array();
|
$this->storedVars = array();
|
||||||
foreach ($this->vars as $key => $var) {
|
foreach ($this->vars as $key => $var) {
|
||||||
$this->storedVars[$key] = clone($var);
|
$this->storedVars[$key] = clone($var);
|
||||||
$var->setUnmodified();
|
$var->setUnmodified();
|
||||||
|
$var->setLoadedFromDb();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -288,8 +288,6 @@ class ExtensibleSet
|
||||||
array_merge($props, array('property' => $value))
|
array_merge($props, array('property' => $value))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fromDb['override'] = $this->ownValues;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($this->plusValues)) {
|
if (! empty($this->plusValues)) {
|
||||||
|
@ -300,8 +298,6 @@ class ExtensibleSet
|
||||||
array_merge($props, array('property' => $value))
|
array_merge($props, array('property' => $value))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fromDb['extend'] = $this->ownValues;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($this->minusValues)) {
|
if (! empty($this->minusValues)) {
|
||||||
|
@ -312,9 +308,18 @@ class ExtensibleSet
|
||||||
array_merge($props, array('property' => $value))
|
array_merge($props, array('property' => $value))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fromDb['blacklist'] = $this->ownValues;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->setBeingLoadedFromDb();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBeingLoadedFromDb()
|
||||||
|
{
|
||||||
|
$this->fromDb = [
|
||||||
|
'override' => $this->ownValues ?: [],
|
||||||
|
'extend' => $this->plusValues ?: [],
|
||||||
|
'blacklist' => $this->minusValues ?: [],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function override($values)
|
public function override($values)
|
||||||
|
|
|
@ -341,6 +341,15 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
|
||||||
return $arguments->loadFromDb();
|
return $arguments->loadFromDb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setBeingLoadedFromDb()
|
||||||
|
{
|
||||||
|
foreach ($this->arguments as $argument) {
|
||||||
|
$argument->setBeingLoadedFromDb();
|
||||||
|
}
|
||||||
|
$this->refreshIndex();
|
||||||
|
$this->cloneStored();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return $this
|
* @return $this
|
||||||
* @throws \Icinga\Module\Director\Exception\DuplicateKeyException
|
* @throws \Icinga\Module\Director\Exception\DuplicateKeyException
|
||||||
|
@ -353,8 +362,14 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
|
||||||
if ($argument->shouldBeRemoved()) {
|
if ($argument->shouldBeRemoved()) {
|
||||||
$deleted[] = $key;
|
$deleted[] = $key;
|
||||||
} else {
|
} else {
|
||||||
$argument->set('command_id', $this->object->get('id'));
|
if ($argument->hasBeenModified()) {
|
||||||
$argument->store($db);
|
if ($argument->hasBeenLoadedFromDb()) {
|
||||||
|
$argument->setLoadedProperty('command_id', $this->object->get('id'));
|
||||||
|
} else {
|
||||||
|
$argument->set('command_id', $this->object->get('id'));
|
||||||
|
}
|
||||||
|
$argument->store($db);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1489,6 +1489,35 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
&& $this->get('object_type') === 'apply';
|
&& $this->get('object_type') === 'apply';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setBeingLoadedFromDb()
|
||||||
|
{
|
||||||
|
if ($this instanceof ObjectWithArguments && $this->gotArguments()) {
|
||||||
|
$this->arguments()->setBeingLoadedFromDb();
|
||||||
|
}
|
||||||
|
if ($this->supportsImports() && $this->gotImports()) {
|
||||||
|
$this->imports()->setBeingLoadedFromDb();
|
||||||
|
}
|
||||||
|
if ($this->supportsCustomVars() && $this->vars !== null) {
|
||||||
|
$this->vars()->setBeingLoadedFromDb();
|
||||||
|
}
|
||||||
|
if ($this->supportsGroups() && $this->groups !== null) {
|
||||||
|
$this->groups()->setBeingLoadedFromDb();
|
||||||
|
}
|
||||||
|
if ($this->supportsRanges() && $this->ranges === null) {
|
||||||
|
$this->ranges()->setBeingLoadedFromDb();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->loadedRelatedSets as $set) {
|
||||||
|
$set->setBeingLoadedFromDb();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->loadedMultiRelations as $multiRelation) {
|
||||||
|
$multiRelation->setBeingLoadedFromDb();
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::setBeingLoadedFromDb();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws NotFoundError
|
* @throws NotFoundError
|
||||||
* @throws \Icinga\Module\Director\Exception\DuplicateKeyException
|
* @throws \Icinga\Module\Director\Exception\DuplicateKeyException
|
||||||
|
|
|
@ -274,7 +274,7 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer
|
||||||
|
|
||||||
$class = $this->getGroupClass();
|
$class = $this->getGroupClass();
|
||||||
$this->groups = $class::loadAll($connection, $query, 'object_name');
|
$this->groups = $class::loadAll($connection, $query, 'object_name');
|
||||||
$this->cloneStored();
|
$this->setBeingLoadedFromDb();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -314,12 +314,12 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->cloneStored();
|
$this->setBeingLoadedFromDb();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function cloneStored()
|
public function setBeingLoadedFromDb()
|
||||||
{
|
{
|
||||||
$this->storedGroups = array();
|
$this->storedGroups = array();
|
||||||
foreach ($this->groups as $k => $v) {
|
foreach ($this->groups as $k => $v) {
|
||||||
|
@ -341,7 +341,7 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer
|
||||||
|
|
||||||
if (PrefetchCache::shouldBeUsed()) {
|
if (PrefetchCache::shouldBeUsed()) {
|
||||||
$groups->groups = PrefetchCache::instance()->groups($object);
|
$groups->groups = PrefetchCache::instance()->groups($object);
|
||||||
$groups->cloneStored();
|
$groups->setBeingLoadedFromDb();
|
||||||
} else {
|
} else {
|
||||||
$groups->loadFromDb();
|
$groups->loadFromDb();
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,7 +308,7 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
|
||||||
$this->imports = array_combine($keys, $keys);
|
$this->imports = array_combine($keys, $keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->cloneStored();
|
$this->setBeingLoadedFromDb();
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,12 +355,12 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->cloneStored();
|
$this->setBeingLoadedFromDb();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function cloneStored()
|
public function setBeingLoadedFromDb()
|
||||||
{
|
{
|
||||||
$this->storedNames = $this->listImportNames();
|
$this->storedNames = $this->listImportNames();
|
||||||
$this->modified = false;
|
$this->modified = false;
|
||||||
|
|
|
@ -323,7 +323,7 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen
|
||||||
|
|
||||||
$class = $this->getRelatedClassName();
|
$class = $this->getRelatedClassName();
|
||||||
$this->relations = $class::loadAll($connection, $query, 'object_name');
|
$this->relations = $class::loadAll($connection, $query, 'object_name');
|
||||||
$this->cloneStored();
|
$this->setBeingLoadedFromDb();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -331,13 +331,10 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen
|
||||||
public function store()
|
public function store()
|
||||||
{
|
{
|
||||||
$db = $this->getDb();
|
$db = $this->getDb();
|
||||||
|
|
||||||
$stored = array_keys($this->stored);
|
$stored = array_keys($this->stored);
|
||||||
$relations = array_keys($this->relations);
|
$relations = array_keys($this->relations);
|
||||||
|
|
||||||
$objectId = $this->object->id;
|
$objectId = $this->object->id;
|
||||||
$type = $this->getType();
|
|
||||||
|
|
||||||
$type = $this->getType();
|
$type = $this->getType();
|
||||||
$objectCol = $type . '_id';
|
$objectCol = $type . '_id';
|
||||||
$relationCol = $this->getRelationIdColumn() . '_id';
|
$relationCol = $this->getRelationIdColumn() . '_id';
|
||||||
|
@ -369,12 +366,12 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->cloneStored();
|
$this->setBeingLoadedFromDb();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function cloneStored()
|
public function setBeingLoadedFromDb()
|
||||||
{
|
{
|
||||||
$this->stored = array();
|
$this->stored = array();
|
||||||
foreach ($this->relations as $k => $v) {
|
foreach ($this->relations as $k => $v) {
|
||||||
|
|
|
@ -211,13 +211,18 @@ class IcingaScheduledDowntimeRanges implements Iterator, Countable, IcingaConfig
|
||||||
->order('o.range_key');
|
->order('o.range_key');
|
||||||
|
|
||||||
$this->ranges = IcingaScheduledDowntimeRange::loadAll($connection, $query, 'range_key');
|
$this->ranges = IcingaScheduledDowntimeRange::loadAll($connection, $query, 'range_key');
|
||||||
$this->storedRanges = array();
|
$this->setBeingLoadedFromDb();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBeingLoadedFromDb()
|
||||||
|
{
|
||||||
|
$this->storedRanges = [];
|
||||||
|
|
||||||
foreach ($this->ranges as $key => $range) {
|
foreach ($this->ranges as $key => $range) {
|
||||||
$this->storedRanges[$key] = clone($range);
|
$this->storedRanges[$key] = clone($range);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store()
|
public function store()
|
||||||
|
|
|
@ -216,13 +216,18 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
|
||||||
/** @var IcingaTimePeriodRange $class */
|
/** @var IcingaTimePeriodRange $class */
|
||||||
$class = $this->getClass();
|
$class = $this->getClass();
|
||||||
$this->ranges = $class::loadAll($connection, $query, 'range_key');
|
$this->ranges = $class::loadAll($connection, $query, 'range_key');
|
||||||
$this->storedRanges = array();
|
$this->setBeingLoadedFromDb();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBeingLoadedFromDb()
|
||||||
|
{
|
||||||
|
$this->storedRanges = [];
|
||||||
|
|
||||||
foreach ($this->ranges as $key => $range) {
|
foreach ($this->ranges as $key => $range) {
|
||||||
$this->storedRanges[$key] = clone($range);
|
$this->storedRanges[$key] = clone($range);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store()
|
public function store()
|
||||||
|
|
Loading…
Reference in New Issue