Skip to content

Commit

Permalink
refs #159 fix splitwise import, make it work if the 'column names' li…
Browse files Browse the repository at this point in the history
…ne is not the first one

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
  • Loading branch information
Julien Veyssier committed Aug 2, 2022
1 parent ea7b9ac commit d3d98cd
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/Service/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5665,13 +5665,13 @@ public function importSWProject(string $path, string $userId): array {
$categoryNames = [];
$row = 0;
$nbCol = 0;

$columnNamesLineFound = false;
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
$owersList = [];
$payer_name = '';
// first line : get column order
if ($row === 0) {
// look for column order line
if (!$columnNamesLineFound) {
$nbCol = count($data);
for ($c=0; $c < $nbCol; $c++) {
for ($c = 0; $c < $nbCol; $c++) {
$columns[$data[$c]] = $c;
}
if (!array_key_exists('Date', $columns)
Expand All @@ -5680,9 +5680,11 @@ public function importSWProject(string $path, string $userId): array {
|| !array_key_exists('Cost', $columns)
|| !array_key_exists('Currency', $columns)
) {
fclose($handle);
return ['message' => $this->trans->t('Malformed CSV, bad column names')];
$columns = [];
$row++;
continue;
}
$columnNamesLineFound = true;
// manage members
$m = 0;
for ($c = 5; $c < $nbCol; $c++) {
Expand Down Expand Up @@ -5773,6 +5775,10 @@ public function importSWProject(string $path, string $userId): array {
}
fclose($handle);

if (!$columnNamesLineFound) {
return ['message' => $this->trans->t('Malformed CSV, impossible to find the column names')];
}

$memberNameToId = [];

// add project
Expand Down

0 comments on commit d3d98cd

Please sign in to comment.