Skip to content

Changeset with the field date is lost in some edge cases #2538

Open
@olivier34000

Description

@olivier34000

BC Break Report

Q A
BC Break yes
Version 2.1

Summary

When we have a field with the type date if the field is updated in less than 1 second the update does not work correctly. The field is not updated

Previous behavior

In this previous version when the field was a date we compared 2 MongoDate
https://github.com/doctrine/mongodb-odm/blob/1.3.x/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L816-L823

In the MongoDate object we have a timestamp and the miliseconds.

In the new version we have https://github.com/doctrine/mongodb-odm/blob/2.6.x/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L798-L809

The UTCDateTime object contains also the milliseconds but we loose this information in the changeSet.

Is-it possible to only cast the UTCDateTime in string in order to keep this information ?

The code should be

                // skip equivalent date values
                if (isset($class->fieldMappings[$propName]['type']) && $class->fieldMappings[$propName]['type'] === 'date') {
                    /** @var DateType $dateType */
                    $dateType      = Type::getType('date');
                    $dbOrgValue    = $dateType->convertToDatabaseValue($orgValue);
                    $dbActualValue = $dateType->convertToDatabaseValue($actualValue);

                    $orgMillisec    = $dbOrgValue instanceof UTCDateTime ? (string) $dbOrgValue : null;
                    $actualMillsec = $dbActualValue instanceof UTCDateTime ? (string) $dbActualValue : null;

                    if ($orgMillisec === $actualMillsec) {
                        continue;
                    }
                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions