diff --git a/src/Extensions/AlgoliaObjectExtension.php b/src/Extensions/AlgoliaObjectExtension.php index b35e261..414c347 100644 --- a/src/Extensions/AlgoliaObjectExtension.php +++ b/src/Extensions/AlgoliaObjectExtension.php @@ -234,6 +234,8 @@ public function doImmediateIndexInAlgolia(): bool $this->touchAlgoliaIndexedDate(); return true; + } else { + return false; } } catch (Throwable $e) { Injector::inst()->get(LoggerInterface::class)->error($e); diff --git a/src/Service/AlgoliaIndexer.php b/src/Service/AlgoliaIndexer.php index 6ea2e0a..65aee14 100644 --- a/src/Service/AlgoliaIndexer.php +++ b/src/Service/AlgoliaIndexer.php @@ -82,10 +82,13 @@ public function indexItem($item) if ($searchIndexes) { $output = true; foreach ($searchIndexes as $searchIndex) { - $result = $searchIndex->saveObject($fields); + $result = $searchIndex->saveObject($fields, [ + 'autoGenerateObjectIDIfNotExist' => true + ]); if (!$result->valid()) { $output = false; + } else { } } diff --git a/src/Tasks/AlgoliaReindexItem.php b/src/Tasks/AlgoliaReindexItem.php index 88ded34..3fc37ce 100644 --- a/src/Tasks/AlgoliaReindexItem.php +++ b/src/Tasks/AlgoliaReindexItem.php @@ -42,8 +42,18 @@ public function run($request) exit; } + // Set AlgoliaUUID, in case it wasn't previously set + if (!$obj->AlgoliaUUID) { + $obj->assignAlgoliaUUID(true); + } + $result = $obj->doImmediateIndexInAlgolia(); - echo sprintf('Indexed: %s, UUID: %s, Err: %s', $result, $obj->AlgoliaUUID, $obj->AlgoliaError); + echo sprintf( + 'Indexed: %s, UUID: %s', + $result ? 'true' : 'false', + $obj->AlgoliaUUID, + $obj->AlgoliaError ? 'Error from Algolia: ' . $obj->AlgoliaError : '' + ); } }