diff --git a/core/collector.class.inc.php b/core/collector.class.inc.php index 5f6ae88..a1e7e99 100644 --- a/core/collector.class.inc.php +++ b/core/collector.class.inc.php @@ -108,7 +108,8 @@ public function Init(): void throw new Exception('Cannot create Collector (invalid JSON definition)'); } foreach ($aSourceDefinition['attribute_list'] as $aAttr) { - $this->aFields[$aAttr['attcode']] = ['class' => $aAttr['finalclass'], 'update' => ($aAttr['update'] != 0), 'reconcile' => ($aAttr['reconcile'] != 0)]; + $aColumns = isset($aAttr['import_columns']) ? explode(',', $aAttr['import_columns']) : [$aAttr['attcode']]; + $this->aFields[$aAttr['attcode']] = ['class' => $aAttr['finalclass'], 'update' => ($aAttr['update'] != 0), 'reconcile' => ($aAttr['reconcile'] != 0), 'columns' => $aColumns]; } $this->ReadCollectorConfig(); @@ -576,18 +577,33 @@ protected function AddHeader($aHeaders) { $this->aCSVHeaders = array(); foreach ($aHeaders as $sHeader) { - if (($sHeader != 'primary_key') && !array_key_exists($sHeader, $this->aFields)) { + if (($sHeader != 'primary_key') && !$this->HeaderIsAllowed($sHeader)) { if (!$this->AttributeIsOptional($sHeader)) { Utils::Log(LOG_WARNING, "Invalid column '$sHeader', will be ignored."); } } else { - $this->aCSVHeaders[] = $sHeader; } } - //fwrite($this->aCSVFile[$this->iFileIndex], implode($this->sSeparator, $this->aCSVHeaders)."\n"); fputcsv($this->aCSVFile[$this->iFileIndex], $this->aCSVHeaders, $this->sSeparator); } + + /** + * Added to add multi-column field support or situations + * where column name is different than attribute code. + * + * @param string $sHeader + * @return bool + */ + protected function HeaderIsAllowed($sHeader) + { + foreach ($this->aFields as $aField) { + if (in_array($sHeader, $aField['columns'])) return true; + } + + // fallback old behaviour + return array_key_exists($sHeader, $this->aFields); + } protected function AddRow($aRow) {