mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix #1262
This commit is contained in:
parent
e06361d5d7
commit
082b5ba895
@ -28,8 +28,8 @@ use FireflyIII\Import\Specifics\SpecificInterface;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Iterator;
|
||||
use League\Csv\Reader;
|
||||
use League\Csv\Statement;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@ -200,29 +200,35 @@ class CsvProcessor implements FileProcessorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator
|
||||
* @return array
|
||||
*
|
||||
* @throws \League\Csv\Exception
|
||||
* @throws \League\Csv\Exception
|
||||
*/
|
||||
private function getImportArray(): Iterator
|
||||
private function getImportArray(): array
|
||||
{
|
||||
$content = $this->repository->uploadFileContents($this->job);
|
||||
$config = $this->getConfig();
|
||||
$reader = Reader::createFromString($content);
|
||||
$delimiter = $config['delimiter'] ?? ',';
|
||||
$hasHeaders = isset($config['has-headers']) ? $config['has-headers'] : false;
|
||||
$offset = 0;
|
||||
if ('tab' === $delimiter) {
|
||||
$delimiter = "\t"; // @codeCoverageIgnore
|
||||
}
|
||||
$reader->setDelimiter($delimiter);
|
||||
if ($hasHeaders) {
|
||||
$reader->setHeaderOffset(0); // @codeCoverageIgnore
|
||||
$offset = 1;
|
||||
}
|
||||
$stmt = (new Statement)->offset($offset);
|
||||
$records = $stmt->process($reader);
|
||||
$return = [];
|
||||
foreach ($records as $record) {
|
||||
$return[] = $record;
|
||||
}
|
||||
$results = $reader->getRecords();
|
||||
Log::debug('Created a CSV reader.');
|
||||
|
||||
return $results;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,19 +58,22 @@ class Roles implements ConfigurationInterface
|
||||
$content = $this->repository->uploadFileContents($this->job);
|
||||
$config = $this->getConfig();
|
||||
$headers = [];
|
||||
$offset = 0;
|
||||
|
||||
// create CSV reader.
|
||||
$reader = Reader::createFromString($content);
|
||||
$reader->setDelimiter($config['delimiter']);
|
||||
|
||||
// CSV headers. Ignore reader. Simply get the first row.
|
||||
if ($config['has-headers']) {
|
||||
// get headers:
|
||||
$reader->setHeaderOffset(0);
|
||||
$headers = $reader->getHeader();
|
||||
$offset = 1;
|
||||
$stmt = (new Statement)->limit(1)->offset(0);
|
||||
$records = $stmt->process($reader);
|
||||
$headers = $records->fetchOne(0);
|
||||
}
|
||||
|
||||
// example rows:
|
||||
$stmt = (new Statement)->limit(intval(config('csv.example_rows', 5)))->offset(0);
|
||||
$stmt = (new Statement)->limit(intval(config('csv.example_rows', 5)))->offset($offset);
|
||||
// set data:
|
||||
$roles = $this->getRoles();
|
||||
asort($roles);
|
||||
|
Loading…
Reference in New Issue
Block a user