data-import
data-import copied to clipboard
When changing Duplicate Headers the order is mixed up
When using the CSVReader with the option
$this->setHeaderRowNumber ( 0, CsvReader::DUPLICATE_HEADERS_INCREMENT );
then the column-name does not fit to the result anymore...
Here is my suggestion to solve the problem:
/**
* Overriding default function
*
* @param array $headers
*
* @return array
*/
protected function incrementHeaders(array $headers) {
$incrementedHeaders = array();
// Get all headlines that are duplicate or more
foreach ( array_count_values ( $headers ) as $header => $count ) {
if ($count > 1) {
$incrementedHeaders [$header] = 0;
}
}
// Replace the headers with the new header name but keep the position ($key) in the array
foreach ( $headers as $key => $headerName ) {
if (isset ( $incrementedHeaders [$headerName] )) {
$prefix = empty ( $headerName ) ? 'UNKNOWN' : '';
$headers [$key] = $prefix . $headerName . $incrementedHeaders [$headerName] ++;
}
}
return $headers;
}
@stevenbuehner - why not create a pull request with your changes? Might be better