Sync: implement filter-based properties

This commit is contained in:
Thomas Gelf 2016-03-15 17:28:49 +01:00
parent 4010127bd4
commit 96e6a15655
1 changed files with 28 additions and 1 deletions

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Import;
use Icinga\Data\Filter\Filter;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Objects\ImportSource;
use Icinga\Module\Director\Objects\IcingaService;
@ -70,6 +71,8 @@ class Sync
protected $runStartTime;
protected $columnFilters = array();
/**
* Constructor. No direct initialization allowed right now. Please use one
* of the available static factory methods
@ -266,9 +269,28 @@ class Sync
protected function 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;
}
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
*
@ -503,12 +525,17 @@ class Sync
$newVars = array();
$imports = array();
foreach ($this->syncProperties as $p) {
foreach ($this->syncProperties as $propertyKey => $p) {
if ($p->source_id !== $sourceId) {
continue;
}
if (! $this->rowMatchesPropertyFilter($row, $propertyKey)) {
continue;
}
$prop = $p->destination_field;
$val = $this->fillVariables($p->source_expression, $row);
if (substr($prop, 0, 5) === 'vars.') {