Skip to content

Conversation

@siwa-tkapplmueller
Copy link

@siwa-tkapplmueller siwa-tkapplmueller commented Jul 19, 2021

resolves #381

Additionally when the value of a DateTime property is null, 0 is returned instead of the timestamp.

Fixes an exception that occurs when one property is null and the other is a DateTime object.
) {
$newPropertyValue = $changedObject->{'get' . ucfirst($propertyName)}();
if (!is_object($oldPropertyValue) || !is_object($newPropertyValue)) {
if (!is_object($oldPropertyValue) && !is_object($newPropertyValue)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move the condition of the next line into this condition.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That condition should probably stay as is, otherwise the else part starting in line 267 is entered when it shouldn't be.

}
} else {
if (get_class($oldPropertyValue) === 'DateTime') {
if (($oldPropertyValue != null && get_class($oldPropertyValue) === 'DateTime') || ($newPropertyValue != null && get_class($newPropertyValue) === 'DateTime')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use type safe comparisons (!==)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, use $oldPropertyValue instanceof \DateTime::class instead of get_class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added your suggestions, but i left out the ::class since \DateTime is already the fully qualified class name.

$dirtyProperties[$propertyName]['old'] = $oldPropertyValue->getTimestamp();
$dirtyProperties[$propertyName]['new'] = $newPropertyValue->getTimestamp();

$oldTimestamp = $oldPropertyValue != null ? $oldPropertyValue->getTimestamp() : 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$oldPropertyValue cannot be null and must therefore be a DateTime object, it's checked in the condition before.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition in line 255 only checks if at least one of the two propertyValues is a DateTime. Therefore either one of them could still be null inside the condition and has to checked again,

@sbusemann sbusemann added this to the candidates for next release milestone Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GeneralUtility throws an Exception when generating changeRequest XML where the oldProperty is null and newProperty is a DateTime

3 participants