Skip to content

Commit 07a8ff9

Browse files
committed
fix: make sure uuid is set when running AlgoliaReindexItem
1 parent a4807fc commit 07a8ff9

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/Extensions/AlgoliaObjectExtension.php

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ public function doImmediateIndexInAlgolia(): bool
234234
$this->touchAlgoliaIndexedDate();
235235

236236
return true;
237+
} else {
238+
return false;
237239
}
238240
} catch (Throwable $e) {
239241
Injector::inst()->get(LoggerInterface::class)->error($e);

src/Service/AlgoliaIndexer.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,13 @@ public function indexItem($item)
8282
if ($searchIndexes) {
8383
$output = true;
8484
foreach ($searchIndexes as $searchIndex) {
85-
$result = $searchIndex->saveObject($fields);
85+
$result = $searchIndex->saveObject($fields, [
86+
'autoGenerateObjectIDIfNotExist' => true
87+
]);
8688

8789
if (!$result->valid()) {
8890
$output = false;
91+
} else {
8992
}
9093
}
9194

src/Tasks/AlgoliaReindexItem.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@ public function run($request)
4242
exit;
4343
}
4444

45+
// Set AlgoliaUUID, in case it wasn't previously set
46+
if (!$obj->AlgoliaUUID) {
47+
$obj->assignAlgoliaUUID(true);
48+
}
49+
4550
$result = $obj->doImmediateIndexInAlgolia();
4651

47-
echo sprintf('Indexed: %s, UUID: %s, Err: %s', $result, $obj->AlgoliaUUID, $obj->AlgoliaError);
52+
echo sprintf(
53+
'Indexed: %s, UUID: %s',
54+
$result ? 'true' : 'false',
55+
$obj->AlgoliaUUID,
56+
$obj->AlgoliaError ? 'Error from Algolia: ' . $obj->AlgoliaError : ''
57+
);
4858
}
4959
}

0 commit comments

Comments
 (0)