mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-17 08:51:30 +00:00
Fix 500 error when field mapping has null field or no search results
- Skip field mappings with null/empty field values in convertFieldMappingsToDto - Return empty DTO instead of throwing when no search results found - Remove unnecessary try/catch workaround in researchPart
This commit is contained in:
parent
11c2780383
commit
0b6fc7bfa0
2 changed files with 5 additions and 16 deletions
|
|
@ -68,6 +68,10 @@ class BulkInfoProviderImportController extends AbstractController
|
||||||
{
|
{
|
||||||
$dtos = [];
|
$dtos = [];
|
||||||
foreach ($fieldMappings as $mapping) {
|
foreach ($fieldMappings as $mapping) {
|
||||||
|
// Skip entries where field is null/empty (e.g. user added a row but didn't select a field)
|
||||||
|
if (empty($mapping['field'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$dtos[] = new BulkSearchFieldMappingDTO(field: $mapping['field'], providers: $mapping['providers'], priority: $mapping['priority'] ?? 1);
|
$dtos[] = new BulkSearchFieldMappingDTO(field: $mapping['field'], providers: $mapping['providers'], priority: $mapping['priority'] ?? 1);
|
||||||
}
|
}
|
||||||
return $dtos;
|
return $dtos;
|
||||||
|
|
@ -472,16 +476,7 @@ class BulkInfoProviderImportController extends AbstractController
|
||||||
$fieldMappingDtos = $job->getFieldMappings();
|
$fieldMappingDtos = $job->getFieldMappings();
|
||||||
$prefetchDetails = $job->isPrefetchDetails();
|
$prefetchDetails = $job->isPrefetchDetails();
|
||||||
|
|
||||||
try {
|
$searchResultsDto = $this->bulkService->performBulkSearch([$part], $fieldMappingDtos, $prefetchDetails);
|
||||||
$searchResultsDto = $this->bulkService->performBulkSearch([$part], $fieldMappingDtos, $prefetchDetails);
|
|
||||||
} catch (\Exception $searchException) {
|
|
||||||
// Handle "no search results found" as a normal case, not an error
|
|
||||||
if (str_contains($searchException->getMessage(), 'No search results found')) {
|
|
||||||
$searchResultsDto = null;
|
|
||||||
} else {
|
|
||||||
throw $searchException;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the job's search results for this specific part efficiently
|
// Update the job's search results for this specific part efficiently
|
||||||
$this->updatePartSearchResults($job, $searchResultsDto[0] ?? null);
|
$this->updatePartSearchResults($job, $searchResultsDto[0] ?? null);
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ final class BulkInfoProviderService
|
||||||
}
|
}
|
||||||
|
|
||||||
$partResults = [];
|
$partResults = [];
|
||||||
$hasAnyResults = false;
|
|
||||||
|
|
||||||
// Group providers by batch capability
|
// Group providers by batch capability
|
||||||
$batchProviders = [];
|
$batchProviders = [];
|
||||||
|
|
@ -88,7 +87,6 @@ final class BulkInfoProviderService
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($allResults)) {
|
if (!empty($allResults)) {
|
||||||
$hasAnyResults = true;
|
|
||||||
$searchResults = $this->formatSearchResults($allResults);
|
$searchResults = $this->formatSearchResults($allResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,10 +97,6 @@ final class BulkInfoProviderService
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$hasAnyResults) {
|
|
||||||
throw new \RuntimeException('No search results found for any of the selected parts');
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = new BulkSearchResponseDTO($partResults);
|
$response = new BulkSearchResponseDTO($partResults);
|
||||||
|
|
||||||
// Prefetch details if requested
|
// Prefetch details if requested
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue