Overview
Comment: | Make sure ODS/XLS files are converted in chart import, fix [50eab17e0bf2e2b240e523e738037e9e0650148f] |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | stable |
Files: | files | file ages | folders |
SHA3-256: |
5fb714d7631bd310bd2d206ac2a78433 |
User & Date: | bohwaz on 2022-07-25 23:21:51 |
Other Links: | manifest | tags |
Context
2022-07-25
| ||
23:23 | Fix encoding of search content in next release check-in: 5cfb4b0306 user: bohwaz tags: trunk | |
23:21 | Make sure ODS/XLS files are converted in chart import, fix [50eab17e0bf2e2b240e523e738037e9e0650148f] check-in: 5fb714d763 user: bohwaz tags: trunk, stable | |
23:13 | Fix error message [62a138c40e1b1e12579986c7b62287110d15ae92] check-in: 76959dfc4a user: bohwaz tags: trunk, stable | |
Changes
Modified src/include/lib/Garradin/CSV.php from [1819d97da7] to [fc7dca36ae].
︙ | ︙ | |||
339 340 341 342 343 344 345 | } return self::import($file['tmp_name'], $expected_columns); } static public function import(string $file, array $expected_columns): \Generator { | > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > | 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | } return self::import($file['tmp_name'], $expected_columns); } static public function import(string $file, array $expected_columns): \Generator { $file = self::convertUploadIfRequired($file); try { $fp = fopen($file, 'r'); if (!$fp) { throw new UserException('Le fichier ne peut être ouvert'); } // Find the delimiter $delim = self::findDelimiter($fp); self::skipBOM($fp); $line = 0; $columns = fgetcsv($fp, 4096, $delim); // Make sure the data is UTF-8 encoded $columns = array_map(fn ($a) => Utils::utf8_encode(trim($a)), $columns); // Check for required columns foreach ($expected_columns as $column) { if (!in_array($column, $columns, true)) { throw new UserException(sprintf('La colonne "%s" est absente du fichier importé', $column)); } } while (!feof($fp)) { $row = fgetcsv($fp, 4096, $delim); $line++; // Empty line, skip if (empty($row)) { continue; } if (count($row) != count($columns)) { throw new UserException('Erreur sur la ligne ' . $line . ' : le nombre de colonnes est incorrect.'); } // Make sure the data is UTF-8 encoded $row = array_map(fn ($a) => Utils::utf8_encode(trim($a)), $row); $row = array_combine($columns, $row); yield $line => $row; } fclose($fp); } finally { @unlink($file); } } } |