Skip to content
Snippets Groups Projects
Commit a252d170 authored by Andrew Chappell's avatar Andrew Chappell
Browse files

Update code based on feedback

parent 2cb433bf
No related branches found
No related tags found
No related merge requests found
Pipeline #198549 failed
......@@ -379,38 +379,38 @@ class BackendClient implements BackendClientInterface {
// For example the putMappings method on the OS client expects an empty
// object but getMapping returns an empty array. Ensure float values are
// preserved as json_encode doesn't preserve them by default.
$result = $this->arrayDiffAssocRecursive(
return $this->mappingsHaveDifferences(
$openSearchMapping[$this->getIndexId($index)]['mappings']['properties'],
json_decode(
json_encode($drupalMapping['body']['properties'], JSON_PRESERVE_ZERO_FRACTION),
TRUE
)
);
return !empty($result);
}
/**
* Recursively diff an associative array to find differences.
*
* If any difference is found bail early.
*/
private function arrayDiffAssocRecursive($array1, $array2): array {
$difference = [];
private function mappingsHaveDifferences(array $array1, array $array2): bool {
foreach ($array1 as $key => $value) {
if (is_array($value)) {
if (!isset($array2[$key]) || !is_array($array2[$key])) {
$difference[$key] = $value;
return TRUE;
}
else {
$newDiff = $this->arrayDiffAssocRecursive($value, $array2[$key]);
$newDiff = $this->mappingsHaveDifferences($value, $array2[$key]);
if (!empty($newDiff)) {
$difference[$key] = $newDiff;
return TRUE;
}
}
}
elseif (!array_key_exists($key, $array2) || $array2[$key] !== $value) {
$difference[$key] = $value;
return TRUE;
}
}
return $difference;
return FALSE;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment