diff --git a/application/tables/ImportedrowsTable.php b/application/tables/ImportedrowsTable.php index 8e69719b..64d72ff4 100644 --- a/application/tables/ImportedrowsTable.php +++ b/application/tables/ImportedrowsTable.php @@ -10,6 +10,7 @@ class ImportedrowsTable extends QuickTable { protected $columns; + /** @var ImportRun */ protected $importRun; public function setImportRun(ImportRun $run) @@ -28,6 +29,12 @@ class ImportedrowsTable extends QuickTable { if ($this->columns === null) { $cols = $this->importRun->listColumnNames(); + + $keyColumn = $this->importRun->importSource()->get('key_column'); + if ($keyColumn !== null && ($pos = array_search($keyColumn, $cols)) !== false) { + unset($cols[$pos]); + array_unshift($cols, $keyColumn); + } } else { $cols = $this->columns; } diff --git a/application/tables/ImportsourceHookTable.php b/application/tables/ImportsourceHookTable.php index 17828dfa..42964692 100644 --- a/application/tables/ImportsourceHookTable.php +++ b/application/tables/ImportsourceHookTable.php @@ -10,6 +10,7 @@ use Icinga\Module\Director\Web\Table\QuickTable; class ImportsourceHookTable extends QuickTable { + /** @var ImportSource */ protected $source; protected $dataCache; @@ -27,6 +28,13 @@ class ImportsourceHookTable extends QuickTable ); sort($this->columnCache); + + // prioritize key column + $keyColumn = $this->source->get('key_column'); + if ($keyColumn !== null && ($pos = array_search($keyColumn, $this->columnCache)) !== false) { + unset($this->columnCache[$pos]); + array_unshift($this->columnCache, $keyColumn); + } } return $this->columnCache; diff --git a/library/Director/Objects/ImportRun.php b/library/Director/Objects/ImportRun.php index f339c2c5..2bef3257 100644 --- a/library/Director/Objects/ImportRun.php +++ b/library/Director/Objects/ImportRun.php @@ -12,6 +12,9 @@ class ImportRun extends DbObject protected $autoincKeyName = 'id'; + /** @var ImportSource */ + protected $importSource = null; + protected $defaultProperties = array( 'id' => null, 'source_id' => null, @@ -125,4 +128,12 @@ class ImportRun extends DbObject return $result; } + + public function importSource() + { + if ($this->importSource === null) { + $this->importSource = ImportSource::load($this->get('source_id'), $this->connection); + } + return $this->importSource; + } }