Skip to content

Commit 32260df

Browse files
Fix issue where missing key might break import (#113)
* Fix issue where missing key might break import * refactor --------- Co-authored-by: Duncan McClean <duncan@duncanmcclean.com>
1 parent 4f4ab83 commit 32260df

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/Jobs/ImportItemJob.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ public function handle(): void
5858

5959
protected function findOrCreateEntry(array $data): void
6060
{
61+
$entry = null;
6162
$collection = Collection::find($this->import->get('destination.collection'));
6263
$site = Site::get($this->import->get('destination.site') ?? Site::default()->handle());
6364

64-
$entry = Entry::query()
65-
->where('site', $site->handle())
66-
->where('collection', $collection->handle())
67-
->where($this->import->get('unique_field'), $data[$this->import->get('unique_field')])
68-
->first();
65+
if ($uniqueFieldValue = Arr::get($data, $this->import->get('unique_field'))) {
66+
$entry = Entry::query()
67+
->where('site', $site->handle())
68+
->where('collection', $collection->handle())
69+
->where($this->import->get('unique_field'), $uniqueFieldValue)
70+
->first();
71+
}
6972

7073
if (! $entry) {
7174
if (! in_array('create', $this->import->get('strategy'))) {

0 commit comments

Comments
 (0)