mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-26 03:09:11 +02:00
Sync: TODO has been done
This commit is contained in:
parent
fc45de5f31
commit
5c202b57ff
@ -21,6 +21,13 @@ class Sync
|
|||||||
*/
|
*/
|
||||||
protected $sources;
|
protected $sources;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source columns we want to fetch from our sources
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $sourceColumns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imported data
|
* Imported data
|
||||||
*/
|
*/
|
||||||
@ -245,26 +252,36 @@ class Sync
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the source columns we want to fetch
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
protected function prepareSourceColumns()
|
protected function prepareSourceColumns()
|
||||||
{
|
{
|
||||||
// $fieldMap = array();
|
// $fieldMap = array();
|
||||||
$columns = array();
|
$this->sourceColumns = array();
|
||||||
|
|
||||||
foreach ($this->syncProperties as $p) {
|
foreach ($this->syncProperties as $p) {
|
||||||
$sourceId = $p->source_id;
|
$sourceId = $p->source_id;
|
||||||
if (! array_key_exists($sourceId, $columns)) {
|
if (! array_key_exists($sourceId, $this->sourceColumns)) {
|
||||||
$columns[$sourceId] = array();
|
$this->sourceColumns[$sourceId] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->extractVariableNames($p->source_expression) as $varname) {
|
foreach ($this->extractVariableNames($p->source_expression) as $varname) {
|
||||||
$columns[$sourceId][$varname] = $varname;
|
$this->sourceColumns[$sourceId][$varname] = $varname;
|
||||||
// -> ? $fieldMap[
|
// -> ? $fieldMap[
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $columns;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether we have a combined key (e.g. services on hosts)
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function hasCombinedKey()
|
protected function hasCombinedKey()
|
||||||
{
|
{
|
||||||
if ($this->hasCombinedKey === null) {
|
if ($this->hasCombinedKey === null) {
|
||||||
@ -302,15 +319,17 @@ class Sync
|
|||||||
protected function fetchImportedData()
|
protected function fetchImportedData()
|
||||||
{
|
{
|
||||||
$this->imported = array();
|
$this->imported = array();
|
||||||
$rule = $this->rule;
|
|
||||||
|
|
||||||
$sourceColumns = $this->prepareSourceColumns();
|
|
||||||
|
|
||||||
foreach ($this->sources as $source) {
|
foreach ($this->sources as $source) {
|
||||||
$sourceId = $source->id;
|
$sourceId = $source->id;
|
||||||
|
|
||||||
|
// Provide an alias column for our key. TODO: double-check this!
|
||||||
$key = $source->key_column;
|
$key = $source->key_column;
|
||||||
$sourceColumns[$sourceId][$key] = $key;
|
$this->sourceColumns[$sourceId][$key] = $key;
|
||||||
$rows = $this->db->fetchLatestImportedRows($sourceId, $sourceColumns[$sourceId]);
|
$rows = $this->db->fetchLatestImportedRows(
|
||||||
|
$sourceId,
|
||||||
|
$this->sourceColumns[$sourceId]
|
||||||
|
);
|
||||||
|
|
||||||
$this->imported[$sourceId] = array();
|
$this->imported[$sourceId] = array();
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
@ -339,7 +358,7 @@ class Sync
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $rule->matches($row)) {
|
if (! $this->rule->matches($row)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,6 +506,7 @@ class Sync
|
|||||||
{
|
{
|
||||||
$rule = $this->rule;
|
$rule = $this->rule;
|
||||||
$this->prepareRelatedImportSources()
|
$this->prepareRelatedImportSources()
|
||||||
|
->prepareSourceColumns()
|
||||||
->fetchImportedData()
|
->fetchImportedData()
|
||||||
->loadExistingObjects();
|
->loadExistingObjects();
|
||||||
|
|
||||||
@ -549,7 +569,6 @@ class Sync
|
|||||||
*/
|
*/
|
||||||
protected function apply()
|
protected function apply()
|
||||||
{
|
{
|
||||||
$rule = $this->rule;
|
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
|
|
||||||
// TODO: Evaluate whether fetching data should happen within the same transaction
|
// TODO: Evaluate whether fetching data should happen within the same transaction
|
||||||
@ -568,7 +587,6 @@ class Sync
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: introduce DirectorObject with shouldBeRemoved
|
|
||||||
if ($object instanceof IcingaObject && $object->shouldBeRemoved()) {
|
if ($object instanceof IcingaObject && $object->shouldBeRemoved()) {
|
||||||
$object->delete($db);
|
$object->delete($db);
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user