Skip to content

Commit

Permalink
fix: make sure uuid is set when running AlgoliaReindexItem
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Aug 30, 2024
1 parent a4807fc commit 07a8ff9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Extensions/AlgoliaObjectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/Service/AlgoliaIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/Tasks/AlgoliaReindexItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ''
);
}
}

0 comments on commit 07a8ff9

Please sign in to comment.