1
0
Fork 0

app/Jobs/ImportProfession.php: fix for broken format from exporter addon.

This commit is contained in:
Henrik Hautakoski 2021-07-01 14:45:37 +02:00
parent 9da87b2b95
commit 8e441ccc92

View file

@ -100,6 +100,13 @@ class ImportProfession implements ShouldQueue
$items = $items->except('items')
->merge($nested)
->map(function ($item, $key) {
// 2021-07-01: Profession Exporter v1.1.0 is abit buggy and dont return
// names for reagents. so we skip those.
if (!isset($item->name)) {
return [];
}
return [
'name' => $item->name,
'slug' => Str::slug($item->name),
@ -108,6 +115,7 @@ class ImportProfession implements ShouldQueue
'color' => isset($item->color) ? (string) Str::of($item->color)->replace('#', '')->limit(8) : null,
];
})
->filter()
->sortBy('name')
->toArray();
@ -135,11 +143,21 @@ class ImportProfession implements ShouldQueue
$reagents = [];
foreach($data->items as $reagent) {
$item = Item::where('name', $reagent->name)->first();
// 2021-07-01: Profession Exporter v1.1.0 is abit buggy and dont return
// names for reagents. So we try to find item by id in that case.
if (isset($reagent->name)) {
$item = Item::where('name', $reagent->name)->first();
} else {
$item = Item::where('external_id', $reagent->id)->first();
}
if (!$item) {
throw new Exception("Could not find item '{$reagent->name}'");
if (isset($reagent->name)) {
throw new Exception("Could not find item '{$reagent->name}'");
}
throw new Exception("Could not find item with id '{$reagent->id}'");
}
$reagents[$item->id] = [ 'quantity' => $reagent->num ];
}