From 0df5e70099d38e2dbcc7cd9bccf8e0fd5b343abb Mon Sep 17 00:00:00 2001 From: Fred Condo Date: Wed, 1 Mar 2023 13:55:03 -0800 Subject: [PATCH] Use ShowInSearch rather than getField() getField(), unlike hasField(), does not check for the corresponding getter method. This is because getField is itself meant to be called from getter methods. In other words, hasField and getField are not exactly parallel, by design. This causes any DataObject whose ShowInSearch exists only as a getter to be unconditionally deleted from the index whenever it is saved. This fix works by replacing the getField call with a reference to ShowInSearch, which will automatically call getShowInSearch. --- src/Searchable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Searchable.php b/src/Searchable.php index fba0d58..b8bf262 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -419,7 +419,7 @@ public function reIndex($stage = Versioned::LIVE) return; } - if (!$versionToIndex->hasField('ShowInSearch') || $versionToIndex->getField('ShowInSearch')) { + if (!$versionToIndex->hasField('ShowInSearch') || $versionToIndex->ShowInSearch) { $this->service->index($versionToIndex); } else { $this->service->remove($versionToIndex); @@ -505,7 +505,7 @@ protected function updateDependentClasses() foreach ($list as $object) { if ($object instanceof DataObject && $object->hasExtension(Searchable::class)) { - if (!$object->hasField('ShowInSearch') || $object->getField('ShowInSearch')) { + if (!$object->hasField('ShowInSearch') || $object->ShowInSearch) { $this->service->index($object); } else { $this->service->remove($object);