Sync: use row filters

This commit is contained in:
Thomas Gelf 2015-12-04 10:59:25 +01:00
parent 2164c1e2b9
commit 7f2e9ddc52
2 changed files with 24 additions and 0 deletions

View File

@ -142,6 +142,9 @@ class Sync
json_encode($row)
);
}
if (! $rule->matches($row)) {
continue;
}
$imported[$sourceId][$row->$key] = $row;
}
}

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Objects;
use Icinga\Data\Filter\Filter;
use Icinga\Module\Director\Data\Db\DbObject;
class SyncRule extends DbObject
@ -21,6 +22,8 @@ class SyncRule extends DbObject
'filter_expression' => null,
);
private $filter;
public function listInvolvedSourceIds()
{
if (! $this->hasBeenLoadedFromDb()) {
@ -55,6 +58,24 @@ class SyncRule extends DbObject
);
}
public function matches($row)
{
if ($this->filter_expression === null) {
return true;
}
return $this->filter()->matches($row);
}
protected function filter()
{
if ($this->filter === null) {
$this->filter = Filter::fromQueryString($this->filter_expression);
}
return $this->filter;
}
public function fetchSyncProperties()
{
$db = $this->getDb();