Skip to content

Commit

Permalink
fix: santinize records after record splits.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thulin committed May 23, 2024
1 parent fd0863f commit a93e2b1
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions source/php/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,31 @@ public function index($post)

$post = self::utf8ize($post); // UTF-8 Escape

//Index post
if (self::recordToLarge($post)) {
$splitRecord = self::splitRecord($post);
try {

if (is_array($splitRecord) && !empty($splitRecord)) {
Instance::getIndex()->saveObjects(
$splitRecord,
//Catch error here.
json_encode($post, JSON_THROW_ON_ERROR);

//Index post
if (self::recordToLarge($post)) {
$splitRecord = self::splitRecord($post);
$splitRecord = self::utf8ize($splitRecord);

if (is_array($splitRecord) && !empty($splitRecord)) {
Instance::getIndex()->saveObjects(
$splitRecord,
['objectIDKey' => 'uuid']
);
}
} else {
Instance::getIndex()->saveObject(
$post,
['objectIDKey' => 'uuid']
);
}
} else {
Instance::getIndex()->saveObject(
$post,
['objectIDKey' => 'uuid']
);

} catch(\Exception $e) {
error_log("Algolia Index: Could not save post. " . $post['ID']);
}
}

Expand Down Expand Up @@ -485,4 +495,4 @@ public static function utf8ize($data) {
}
return $data;
}
}
}

0 comments on commit a93e2b1

Please sign in to comment.