Skip to content

Commit 49aa318

Browse files
committed
fix: re-encode updatedAt in increase/decreaseDocumentAttribute when preserveDates is enabled
When preserveDates is true, getUpdatedAt() returns the decoded ISO 8601 format (e.g. 2026-03-10T10:33:54.726+00:00) which gets passed directly to the adapter. MariaDB rejects this format. Re-encode to DB format (Y-m-d H:i:s.v) before passing to the adapter.
1 parent 438cc82 commit 49aa318

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Database/Database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7396,7 +7396,7 @@ public function increaseDocumentAttribute(
73967396

73977397
$time = DateTime::now();
73987398
$updatedAt = $document->getUpdatedAt();
7399-
$updatedAt = (empty($updatedAt) || !$this->preserveDates) ? $time : $updatedAt;
7399+
$updatedAt = (empty($updatedAt) || !$this->preserveDates) ? $time : DateTime::format(new \DateTime($updatedAt));
74007400
$max = $max ? $max - $value : null;
74017401

74027402
$this->adapter->increaseDocumentAttribute(
@@ -7496,7 +7496,7 @@ public function decreaseDocumentAttribute(
74967496

74977497
$time = DateTime::now();
74987498
$updatedAt = $document->getUpdatedAt();
7499-
$updatedAt = (empty($updatedAt) || !$this->preserveDates) ? $time : $updatedAt;
7499+
$updatedAt = (empty($updatedAt) || !$this->preserveDates) ? $time : DateTime::format(new \DateTime($updatedAt));
75007500
$min = $min ? $min + $value : null;
75017501

75027502
$this->adapter->increaseDocumentAttribute(

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,32 @@ public function testIncreaseArrayAttribute(Document $document): void
15371537
}
15381538
}
15391539

1540+
/**
1541+
* @depends testIncreaseDecrease
1542+
*/
1543+
public function testIncreaseDecreasePreserveDates(Document $document): void
1544+
{
1545+
/** @var Database $database */
1546+
$database = $this->getDatabase();
1547+
1548+
$database->setPreserveDates(true);
1549+
1550+
$before = $database->getDocument('increase_decrease', $document->getId());
1551+
$updatedAt = $before->getUpdatedAt();
1552+
1553+
$database->increaseDocumentAttribute('increase_decrease', $document->getId(), 'increase', 1);
1554+
1555+
$after = $database->getDocument('increase_decrease', $document->getId());
1556+
$this->assertSame($updatedAt, $after->getUpdatedAt());
1557+
1558+
$database->decreaseDocumentAttribute('increase_decrease', $document->getId(), 'decrease', 1);
1559+
1560+
$after = $database->getDocument('increase_decrease', $document->getId());
1561+
$this->assertSame($updatedAt, $after->getUpdatedAt());
1562+
1563+
$database->setPreserveDates(false);
1564+
}
1565+
15401566
/**
15411567
* @depends testCreateDocument
15421568
*/

0 commit comments

Comments
 (0)