changes 0129092025 laptop

This commit is contained in:
2025-09-29 17:35:54 +02:00
parent 30eee6c5b0
commit 1fddf959f0
7 changed files with 277 additions and 4 deletions
+26
View File
@@ -62,4 +62,30 @@ public function detectColumnsFromCsv(string $path, bool $hasHeader): array
return [$bestDelim, $clean];
}
/**
* Parse columns from CSV using a specific delimiter. If $hasHeader is false,
* returns positional indices instead of header names.
*/
public function parseColumnsFromCsv(string $path, string $delimiter, bool $hasHeader): array
{
$firstLine = $this->readFirstLine($path);
if ($firstLine === null) {
return [];
}
$row = str_getcsv($firstLine, $delimiter);
$count = is_array($row) ? count($row) : 0;
if ($hasHeader) {
return array_map(function ($v) {
$v = trim((string) $v);
$v = preg_replace('/\s+/', ' ', $v);
return $v;
}, $row ?: []);
}
$cols = [];
for ($i = 0; $i < $count; $i++) {
$cols[] = (string) $i;
}
return $cols;
}
}
+5 -1
View File
@@ -58,7 +58,11 @@ public function process(Import $import, ?Authenticatable $user = null): array
->get(['source_column', 'target_field', 'transform', 'apply_mode', 'options']);
$header = $import->meta['columns'] ?? null;
$delimiter = $import->meta['detected_delimiter'] ?? ',';
// Prefer explicitly chosen delimiter, then template meta, else detected
$delimiter = $import->meta['forced_delimiter']
?? optional($import->template)->meta['delimiter']
?? $import->meta['detected_delimiter']
?? ',';
$hasHeader = (bool) ($import->meta['has_header'] ?? true);
$path = Storage::disk($import->disk)->path($import->path);