Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes changeset being empty when datetime change is sub second #2676

Merged
merged 7 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/Doctrine/ODM/MongoDB/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Doctrine\Persistence\NotifyPropertyChanged;
use Doctrine\Persistence\PropertyChangedListener;
use InvalidArgumentException;
use MongoDB\BSON\UTCDateTime;
use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern;
Expand Down Expand Up @@ -835,10 +834,9 @@ private function computeOrRecomputeChangeSet(ClassMetadata $class, object $docum
$dbOrgValue = $dateType->convertToDatabaseValue($orgValue);
$dbActualValue = $dateType->convertToDatabaseValue($actualValue);

$orgTimestamp = $dbOrgValue instanceof UTCDateTime ? $dbOrgValue->toDateTime()->getTimestamp() : null;
$actualTimestamp = $dbActualValue instanceof UTCDateTime ? $dbActualValue->toDateTime()->getTimestamp() : null;

if ($orgTimestamp === $actualTimestamp) {
// We rely on loose comparison to compare every field (including microseconds)
// phpcs:ignore SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedEqualOperator
if ($dbOrgValue == $dbActualValue) {
magnetik marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ public static function provideEquivalentDates(): array
];
}

public function testDateInstanceChangeWhenValueDifferenceIsSubSecond(): void
{
$user = new User();
$user->setCreatedAt(new UTCDateTime(100000000000));
$this->dm->persist($user);
$this->dm->flush();
$this->dm->clear();

$user = $this->dm->getRepository($user::class)->findOneBy([]);
$user->setCreatedAt(new UTCDateTime(100000000123));
$this->dm->getUnitOfWork()->computeChangeSets();
$changeset = $this->dm->getUnitOfWork()->getDocumentChangeSet($user);
self::assertNotEmpty($changeset);
}

public function testDateInstanceValueChangeDoesCauseUpdateIfValueIsTheSame(): void
{
$user = new User();
Expand Down
Loading