diff --git a/app/Jobs/ImportProfession.php b/app/Jobs/ImportProfession.php index 07a9250..5f05e48 100644 --- a/app/Jobs/ImportProfession.php +++ b/app/Jobs/ImportProfession.php @@ -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 ]; }