From f4febf2a15ca48dc0e98bef890840ae74989cf35 Mon Sep 17 00:00:00 2001 From: siwa-tkapplmueller <47564597+siwa-tkapplmueller@users.noreply.github.com> Date: Mon, 19 Jul 2021 14:13:42 +0200 Subject: [PATCH 1/2] Fix exception when oldProperty is null Fixes an exception that occurs when one property is null and the other is a DateTime object. --- Classes/Utility/UserUtility.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Classes/Utility/UserUtility.php b/Classes/Utility/UserUtility.php index 3160e1351c..841cd256a1 100644 --- a/Classes/Utility/UserUtility.php +++ b/Classes/Utility/UserUtility.php @@ -246,18 +246,22 @@ public static function getDirtyPropertiesFromUser(User $changedObject) && !in_array($propertyName, $ignoreProperties) ) { $newPropertyValue = $changedObject->{'get' . ucfirst($propertyName)}(); - if (!is_object($oldPropertyValue) || !is_object($newPropertyValue)) { + if (!is_object($oldPropertyValue) && !is_object($newPropertyValue)) { if ($oldPropertyValue !== $newPropertyValue) { $dirtyProperties[$propertyName]['old'] = $oldPropertyValue; $dirtyProperties[$propertyName]['new'] = $newPropertyValue; } } else { - if (get_class($oldPropertyValue) === 'DateTime') { + if (($oldPropertyValue != null && get_class($oldPropertyValue) === 'DateTime') || ($newPropertyValue != null && get_class($newPropertyValue) === 'DateTime')) { /** @var $oldPropertyValue \DateTime */ /** @var $newPropertyValue \DateTime */ - if ($oldPropertyValue->getTimestamp() !== $newPropertyValue->getTimestamp()) { - $dirtyProperties[$propertyName]['old'] = $oldPropertyValue->getTimestamp(); - $dirtyProperties[$propertyName]['new'] = $newPropertyValue->getTimestamp(); + + $oldTimestamp = $oldPropertyValue != null ? $oldPropertyValue->getTimestamp() : 0; + $newTimestamp = $newPropertyValue != null ? $newPropertyValue->getTimestamp() : 0; + + if ($oldTimestamp !== $newTimestamp) { + $dirtyProperties[$propertyName]['old'] = $oldTimestamp; + $dirtyProperties[$propertyName]['new'] = $newTimestamp; } } else { $titlesOld = ObjectUtility::implodeObjectStorageOnProperty($oldPropertyValue); From baf2cb042420f0aa5266d281a1f04e9401c21a98 Mon Sep 17 00:00:00 2001 From: siwa-tkapplmueller <47564597+siwa-tkapplmueller@users.noreply.github.com> Date: Mon, 19 Jul 2021 15:15:03 +0200 Subject: [PATCH 2/2] use type safe comparisons, use instanceof instead of get_class --- Classes/Utility/UserUtility.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Classes/Utility/UserUtility.php b/Classes/Utility/UserUtility.php index 841cd256a1..df5458d4be 100644 --- a/Classes/Utility/UserUtility.php +++ b/Classes/Utility/UserUtility.php @@ -252,12 +252,12 @@ public static function getDirtyPropertiesFromUser(User $changedObject) $dirtyProperties[$propertyName]['new'] = $newPropertyValue; } } else { - if (($oldPropertyValue != null && get_class($oldPropertyValue) === 'DateTime') || ($newPropertyValue != null && get_class($newPropertyValue) === 'DateTime')) { + if (($oldPropertyValue !== null && $oldPropertyValue instanceof \DateTime) || ($newPropertyValue !== null && $newPropertyValue instanceof \DateTime)) { /** @var $oldPropertyValue \DateTime */ /** @var $newPropertyValue \DateTime */ - $oldTimestamp = $oldPropertyValue != null ? $oldPropertyValue->getTimestamp() : 0; - $newTimestamp = $newPropertyValue != null ? $newPropertyValue->getTimestamp() : 0; + $oldTimestamp = $oldPropertyValue !== null ? $oldPropertyValue->getTimestamp() : 0; + $newTimestamp = $newPropertyValue !== null ? $newPropertyValue->getTimestamp() : 0; if ($oldTimestamp !== $newTimestamp) { $dirtyProperties[$propertyName]['old'] = $oldTimestamp;