Sync: implement filter-based properties
This commit is contained in:
parent
4010127bd4
commit
96e6a15655
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Director\Import;
|
namespace Icinga\Module\Director\Import;
|
||||||
|
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Module\Director\Objects\IcingaObject;
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
use Icinga\Module\Director\Objects\ImportSource;
|
use Icinga\Module\Director\Objects\ImportSource;
|
||||||
use Icinga\Module\Director\Objects\IcingaService;
|
use Icinga\Module\Director\Objects\IcingaService;
|
||||||
|
@ -70,6 +71,8 @@ class Sync
|
||||||
|
|
||||||
protected $runStartTime;
|
protected $runStartTime;
|
||||||
|
|
||||||
|
protected $columnFilters = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. No direct initialization allowed right now. Please use one
|
* Constructor. No direct initialization allowed right now. Please use one
|
||||||
* of the available static factory methods
|
* of the available static factory methods
|
||||||
|
@ -266,9 +269,28 @@ class Sync
|
||||||
protected function fetchSyncProperties()
|
protected function fetchSyncProperties()
|
||||||
{
|
{
|
||||||
$this->syncProperties = $this->rule->fetchSyncProperties();
|
$this->syncProperties = $this->rule->fetchSyncProperties();
|
||||||
|
foreach ($this->syncProperties as $key => $prop) {
|
||||||
|
if (! strlen($prop->filter_expression)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->columnFilters[$key] = Filter::fromQueryString(
|
||||||
|
$prop->filter_expression
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function rowMatchesPropertyFilter($row, $key)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($key, $this->columnFilters)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->columnFilters[$key]->matches($row);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates all related ImportSource objects
|
* Instantiates all related ImportSource objects
|
||||||
*
|
*
|
||||||
|
@ -503,12 +525,17 @@ class Sync
|
||||||
$newVars = array();
|
$newVars = array();
|
||||||
$imports = array();
|
$imports = array();
|
||||||
|
|
||||||
foreach ($this->syncProperties as $p) {
|
foreach ($this->syncProperties as $propertyKey => $p) {
|
||||||
if ($p->source_id !== $sourceId) {
|
if ($p->source_id !== $sourceId) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! $this->rowMatchesPropertyFilter($row, $propertyKey)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$prop = $p->destination_field;
|
$prop = $p->destination_field;
|
||||||
|
|
||||||
$val = $this->fillVariables($p->source_expression, $row);
|
$val = $this->fillVariables($p->source_expression, $row);
|
||||||
|
|
||||||
if (substr($prop, 0, 5) === 'vars.') {
|
if (substr($prop, 0, 5) === 'vars.') {
|
||||||
|
|
Loading…
Reference in New Issue