Fix problem when omitting column names
This commit is contained in:
parent
647e2ac007
commit
a0f4f0546f
|
@ -101,7 +101,7 @@ class CsvImportCommand extends Console
|
||||||
'noValidation',
|
'noValidation',
|
||||||
null,
|
null,
|
||||||
InputOption::VALUE_NONE,
|
InputOption::VALUE_NONE,
|
||||||
'Omit content validation (improves performance for large record sets).'
|
'Skip content validation (improves performance for large record sets).'
|
||||||
);
|
);
|
||||||
parent::configure();
|
parent::configure();
|
||||||
}
|
}
|
||||||
|
@ -140,21 +140,21 @@ class CsvImportCommand extends Console
|
||||||
$progressIndicator->start('Importing...');
|
$progressIndicator->start('Importing...');
|
||||||
|
|
||||||
while ($row = fgetcsv($file)) {
|
while ($row = fgetcsv($file)) {
|
||||||
$record = new Record(
|
$record = new Record($row[$columns['idColumn']], $format);
|
||||||
$row[$columns['idColumn']],
|
|
||||||
$format,
|
|
||||||
null,
|
|
||||||
new DateTime($row[$columns['dateColumn']] ?? 'now')
|
|
||||||
);
|
|
||||||
if (strlen(trim($row[$columns['contentColumn']])) > 0) {
|
if (strlen(trim($row[$columns['contentColumn']])) > 0) {
|
||||||
$record->setContent($row[$columns['contentColumn']], !$noValidation);
|
$record->setContent($row[$columns['contentColumn']], !$noValidation);
|
||||||
}
|
}
|
||||||
$sets = $row[$columns['setColumn']] ?? '';
|
if (isset($columns['dateColumn'])) {
|
||||||
|
$record->setLastChanged(new DateTime($row[$columns['dateColumn']]));
|
||||||
|
}
|
||||||
|
if (isset($columns['setColumn'])) {
|
||||||
|
$sets = $row[$columns['setColumn']];
|
||||||
foreach (explode(',', trim($sets)) as $set) {
|
foreach (explode(',', trim($sets)) as $set) {
|
||||||
/** @var Set */
|
/** @var Set */
|
||||||
$setSpec = Database::getInstance()->getEntityManager()->getReference(Set::class, $set);
|
$setSpec = Database::getInstance()->getEntityManager()->getReference(Set::class, $set);
|
||||||
$record->addSet($setSpec);
|
$record->addSet($setSpec);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Database::getInstance()->addOrUpdateRecord($record, true);
|
Database::getInstance()->addOrUpdateRecord($record, true);
|
||||||
|
|
||||||
++$count;
|
++$count;
|
||||||
|
@ -194,7 +194,7 @@ class CsvImportCommand extends Console
|
||||||
* @param OutputInterface $output The output interface
|
* @param OutputInterface $output The output interface
|
||||||
* @param resource $file The handle for the CSV file
|
* @param resource $file The handle for the CSV file
|
||||||
*
|
*
|
||||||
* @return array<string, int|string> The mapped column names
|
* @return array<string, int|string|null> The mapped column names
|
||||||
*/
|
*/
|
||||||
protected function getColumnNames(InputInterface $input, OutputInterface $output, $file): array
|
protected function getColumnNames(InputInterface $input, OutputInterface $output, $file): array
|
||||||
{
|
{
|
||||||
|
@ -218,9 +218,7 @@ class CsvImportCommand extends Console
|
||||||
$headers = array_flip($headers);
|
$headers = array_flip($headers);
|
||||||
}
|
}
|
||||||
foreach ($options as $option => $value) {
|
foreach ($options as $option => $value) {
|
||||||
if (isset($headers[$value])) {
|
$columns[$option] = $headers[$value] ?? null;
|
||||||
$columns[$option] = $headers[$value];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($columns['idColumn']) || !isset($columns['contentColumn'])) {
|
if (!isset($columns['idColumn']) || !isset($columns['contentColumn'])) {
|
||||||
|
|
Loading…
Reference in New Issue