mirror of
https://github.com/Codappix/typo3-php-datasets.git
synced 2024-12-05 02:36:10 +01:00
Support empty extra columns in CSV conversion (#12)
This commit is contained in:
parent
8a83c508a2
commit
77a7d13c70
5 changed files with 30 additions and 3 deletions
|
@ -1,5 +1,11 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.4.1 - 2023-11-09
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Support empty columns in CSV conversion.
|
||||||
|
|
||||||
## v1.4.0 - 2023-11-07
|
## v1.4.0 - 2023-11-07
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Csv implements Converter
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($line) && count($line) === 1 && is_string($line[0])) {
|
if (is_array($line) && count(array_filter($line)) === 1 && is_string($line[0])) {
|
||||||
// Line is a new table, introducing also new columns o next row
|
// Line is a new table, introducing also new columns o next row
|
||||||
$tableName = $line[0];
|
$tableName = $line[0];
|
||||||
$columns = [];
|
$columns = [];
|
||||||
|
@ -79,12 +79,12 @@ class Csv implements Converter
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($columns === [] && is_array($line)) {
|
if ($columns === [] && is_array($line)) {
|
||||||
$columns = array_slice($line, 1);
|
$columns = array_filter($line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($line)) {
|
if (is_array($line)) {
|
||||||
$values = array_slice($line, 1);
|
$values = array_slice($line, 1, count($columns));
|
||||||
$phpArray[$tableName][] = array_combine($columns, $values);
|
$phpArray[$tableName][] = array_combine($columns, $values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,10 @@ class CsvTest extends TestCase
|
||||||
'incomingCsvFile' => __DIR__ . '/Fixtures/Csv/RecordsInDifferentTablesIncoming.csv',
|
'incomingCsvFile' => __DIR__ . '/Fixtures/Csv/RecordsInDifferentTablesIncoming.csv',
|
||||||
'expectedResultFile' => __DIR__ . '/Fixtures/Csv/RecordsInDifferentTablesAssert.php',
|
'expectedResultFile' => __DIR__ . '/Fixtures/Csv/RecordsInDifferentTablesAssert.php',
|
||||||
],
|
],
|
||||||
|
'Extra columns' => [
|
||||||
|
'incomingCsvFile' => __DIR__ . '/Fixtures/Csv/ExtraColumnsIncoming.csv',
|
||||||
|
'expectedResultFile' => __DIR__ . '/Fixtures/Csv/ExtraColumnsAssert.php',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return array (
|
||||||
|
'pages' =>
|
||||||
|
array (
|
||||||
|
0 =>
|
||||||
|
array (
|
||||||
|
'uid' => '1',
|
||||||
|
'pid' => '0',
|
||||||
|
'title' => 'Page with uid 1 below 0',
|
||||||
|
'deleted' => '0',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
|
@ -0,0 +1,3 @@
|
||||||
|
pages,,,,,,,,
|
||||||
|
,uid,pid,title,deleted,,,,
|
||||||
|
,1,0,Page with uid 1 below 0,0,,,,
|
|
Loading…
Reference in a new issue