Hi
I have this Hook:
return [
'debug' => true,
'hooks' => [
'page.update:after' => function ($newPage, $oldPage) {
$pageName = $newPage->uid();
$newField = json_encode($newPage->Addresses());
$oldField = json_encode($oldPage->Addresses());
// echo $newField;
echo $oldField;
// if old and new are equal then this returns true
$resultCompare = strcmp($newField, $oldField) !== 1;
echo $resultCompare;
if ($pageName == 'offers' AND strcmp($newField, $oldField) !== 1) {
$updateExcelsheet = New excelSheet();
$updateExcelsheet->excelWrite($newPage, 'offersdatabackup.xlsx');
site()->update([
'OffersdataLastupdate' => $newPage->modified()
]);
}
}
]
$newField and $oldField did not change.
But when I compare the Strings of $newField and $oldField then I see Linebreak-Sign in one of both:
This means when I compare them with strcmp() this it always returns 1 instead of 0.
Is this a bug or is there something I did not understand about it?
The goal is to check if the structured field “addresses” has changed or not.