app/Jobs/ImportProfession.php: fix a bug resulting in duplicate records instead of update existing.
We search for recipes by spell, but if a record existed before spell relationship was added. it's null and we wont find it, so we create a duplicated one. This patch will also search for craft->name and update existing records.
This commit is contained in:
parent
3085de6334
commit
f105890494
2 changed files with 55 additions and 3 deletions
|
|
@ -161,8 +161,12 @@ class ImportProfession implements ShouldQueue
|
|||
|
||||
protected function getRecipe(Spell $spell, ?Item $crafted, Profession $profession, $data)
|
||||
{
|
||||
// Find by spell_id or fallback to craft->name if null.
|
||||
$recipe = $profession->recipes()
|
||||
->where('spell_id', $spell->id)
|
||||
->orWhereHas('craft', function($q) use ($data) {
|
||||
$q->where('name', $data->name);
|
||||
})
|
||||
->first();
|
||||
|
||||
// Create if not found.
|
||||
|
|
@ -176,9 +180,17 @@ class ImportProfession implements ShouldQueue
|
|||
'category_id' => $category->id
|
||||
]);
|
||||
}
|
||||
// Update with crafted item :)
|
||||
else if ($crafted) {
|
||||
$recipe->craft()->associate($crafted);
|
||||
// Existing record.
|
||||
else {
|
||||
// Update with crafted item :)
|
||||
if (!$recipe->craft && $crafted) {
|
||||
$recipe->craft()->associate($crafted);
|
||||
}
|
||||
|
||||
// Update spell if it dont exist.
|
||||
if (!$recipe->spell) {
|
||||
$recipe->spell()->associate($spell);
|
||||
}
|
||||
}
|
||||
|
||||
// Insert/Update Reagents
|
||||
|
|
|
|||
Reference in a new issue