Skip to content
Merged

Dev #3268

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions app/Imports/GenericEventsImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ protected function validateCoordinates(array $row): ?string
return null;
}
if ($lat === null || $lon === null) {
return 'Invalid latitude/longitude (must be numeric)';
return 'value must be numeric';
}
if ($lat < -90 || $lat > 90 || $lon < -180 || $lon > 180) {
return 'Bad coordinates (latitude -90 to 90, longitude -180 to 180)';
return 'latitude must be -90 to 90, longitude -180 to 180';
}
return null;
}
Expand Down Expand Up @@ -177,7 +177,7 @@ public function model(array $row): ?Model
// 1) coordinate validation
$coordError = $this->validateCoordinates($row);
if ($coordError !== null) {
$this->recordFailure($rowIndex, $coordError);
$this->recordFailure($rowIndex, 'Row ' . $rowIndex . ' — columns latitude, longitude: ' . $coordError);
Log::warning($coordError, $row);
return null;
}
Expand All @@ -200,23 +200,30 @@ public function model(array $row): ?Model
}
}
if ($missing !== []) {
$reason = 'Missing required field(s): '.implode(', ', $missing);
$this->recordFailure($rowIndex, $reason);
$this->recordFailure($rowIndex, 'Row ' . $rowIndex . ' — missing required columns: ' . implode(', ', $missing));
Log::error('Missing required fields, skipping row.', $row);
return null;
}

$startDate = $this->parseDate($row['start_date']);
$endDate = $this->parseDate($row['end_date']);
if ($startDate === null || $endDate === null) {
$this->recordFailure($rowIndex, 'Invalid date format for start_date or end_date');
$badDates = [];
if ($startDate === null && trim((string) ($row['start_date'] ?? '')) !== '') {
$badDates[] = 'start_date';
}
if ($endDate === null && trim((string) ($row['end_date'] ?? '')) !== '') {
$badDates[] = 'end_date';
}
$colList = $badDates !== [] ? implode(', ', $badDates) : 'start_date, end_date';
$this->recordFailure($rowIndex, 'Row ' . $rowIndex . ' — invalid date format in column(s): ' . $colList);
return null;
}

// 3) resolve creator_id
$creatorId = $this->resolveCreatorId($row);
if ($creatorId === null && ! empty(trim($row['contact_email'] ?? ''))) {
$this->recordFailure($rowIndex, 'Could not resolve or create user for contact_email');
$this->recordFailure($rowIndex, 'Row ' . $rowIndex . ' — could not resolve or create user (column: contact_email)');
return null;
}

Expand Down Expand Up @@ -355,7 +362,7 @@ public function model(array $row): ?Model
$this->recordCreated($event);
return $event;
} catch (\Exception $e) {
$this->recordFailure($rowIndex, 'Event import failed: '.$e->getMessage());
$this->recordFailure($rowIndex, 'Row ' . $rowIndex . ' — save failed: ' . $e->getMessage());
Log::error('Event import failed: '.$e->getMessage(), $attrs);
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions resources/views/admin/bulk-upload/report.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@

@if (count($failures) > 0)
<h2 class="text-xl font-semibold mt-6 mb-2">Failures ({{ count($failures) }})</h2>
<p class="text-sm text-gray-600 mb-2">Row number refers to the row in the Excel file (header = row 1).</p>
<p class="text-sm text-gray-600 mb-2">Row is the Excel row number (header = row 1). Reason shows which columns have issues so you can fix the file and re-upload.</p>
<table class="w-full border-collapse border border-gray-300">
<thead>
<tr class="bg-gray-100">
<th class="border border-gray-300 px-3 py-2 text-left">Row</th>
<th class="border border-gray-300 px-3 py-2 text-left">Reason</th>
<th class="border border-gray-300 px-3 py-2 text-left">Reason (row and columns)</th>
</tr>
</thead>
<tbody>
@foreach ($failures as $rowIndex => $reason)
<tr>
<td class="border border-gray-300 px-3 py-2">{{ $rowIndex }}</td>
<td class="border border-gray-300 px-3 py-2">{{ $reason }}</td>
<td class="border border-gray-300 px-3 py-2 font-medium">{{ $rowIndex }}</td>
<td class="border border-gray-300 px-3 py-2 text-left">{{ $reason }}</td>
</tr>
@endforeach
</tbody>
Expand Down
Loading