From 0a16292a0a03a755d889c55f7657f40a97621111 Mon Sep 17 00:00:00 2001 From: hi019 <65871571+hi019@users.noreply.github.com> Date: Fri, 3 Dec 2021 10:53:20 -0500 Subject: [PATCH 1/2] Fix soft delete check, null check --- src/Engines/TypesenseEngine.php | 11 ++++++----- src/Typesense.php | 16 +++------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/Engines/TypesenseEngine.php b/src/Engines/TypesenseEngine.php index 741924c..a81d1fe 100644 --- a/src/Engines/TypesenseEngine.php +++ b/src/Engines/TypesenseEngine.php @@ -11,9 +11,10 @@ use Illuminate\Support\Str; use Laravel\Scout\Builder; use Laravel\Scout\Engines\Engine; +use Illuminate\Support\Facades\Config; /** - * Class TypesenseSearchEngine. + * Class TypesenseEngine. * * @date 4/5/20 * @@ -22,7 +23,7 @@ class TypesenseEngine extends Engine { /** - * @var \Typesense\LaravelTypesense\Typesense + * @var Typesense */ private Typesense $typesense; @@ -57,9 +58,9 @@ class TypesenseEngine extends Engine private array $locationOrderBy = []; /** - * TypesenseSearchEngine constructor. + * TypesenseEngine constructor. * - * @param \Typesense\LaravelTypesense\Typesense $typesense + * @param Typesense $typesense */ public function __construct(Typesense $typesense) { @@ -78,7 +79,7 @@ public function update($models): void { $collection = $this->typesense->getCollectionIndex($models->first()); - if ($this->usesSoftDelete($models->first()) && $models->first()->softDelete) { + if ($this->usesSoftDelete($models->first()) && Config::get('scout.soft_delete', false)) { $models->each->pushSoftDeleteMetadata(); } diff --git a/src/Typesense.php b/src/Typesense.php index ea4740b..88f59f8 100644 --- a/src/Typesense.php +++ b/src/Typesense.php @@ -94,10 +94,7 @@ public function upsertDocument(Collection $collectionIndex, $array): TypesenseDo /** * @var $document Document */ - $document = $collectionIndex->getDocuments()[$array['id']] ?? null; - if ($document === null) { - throw new ObjectNotFound(); - } + $document = $collectionIndex->getDocuments()[$array['id']]; try { $document->retrieve(); @@ -126,10 +123,7 @@ public function deleteDocument(Collection $collectionIndex, $modelId): array /** * @var $document Document */ - $document = $collectionIndex->getDocuments()[(string) $modelId] ?? null; - if ($document === null) { - throw new ObjectNotFound(); - } + $document = $collectionIndex->getDocuments()[(string) $modelId]; return $document->delete(); } @@ -188,11 +182,7 @@ public function importDocuments(Collection $collectionIndex, $documents, string */ public function deleteCollection(string $collectionName): array { - $index = $this->client->getCollections()->{$collectionName} ?? null; - if ($index === null) { - throw new ObjectNotFound(); - } - + $index = $this->client->getCollections()->{$collectionName}; return $index->delete(); } } From 02227e0353edbf4365800c018628d2ca2bbdc2da Mon Sep 17 00:00:00 2001 From: hi019 <65871571+hi019@users.noreply.github.com> Date: Fri, 3 Dec 2021 11:08:09 -0500 Subject: [PATCH 2/2] Use config helper instead of facade --- src/Engines/TypesenseEngine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Engines/TypesenseEngine.php b/src/Engines/TypesenseEngine.php index a81d1fe..58924a6 100644 --- a/src/Engines/TypesenseEngine.php +++ b/src/Engines/TypesenseEngine.php @@ -79,7 +79,7 @@ public function update($models): void { $collection = $this->typesense->getCollectionIndex($models->first()); - if ($this->usesSoftDelete($models->first()) && Config::get('scout.soft_delete', false)) { + if ($this->usesSoftDelete($models->first()) && config('scout.soft_delete', false)) { $models->each->pushSoftDeleteMetadata(); }