diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index 27512a61..f680e2b8 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -142,6 +142,9 @@ class Sync json_encode($row) ); } + if (! $rule->matches($row)) { + continue; + } $imported[$sourceId][$row->$key] = $row; } } diff --git a/library/Director/Objects/SyncRule.php b/library/Director/Objects/SyncRule.php index 2bb3d5d6..f8031f9d 100644 --- a/library/Director/Objects/SyncRule.php +++ b/library/Director/Objects/SyncRule.php @@ -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();