Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -7396,7 +7396,7 @@ public function increaseDocumentAttribute(

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

$this->adapter->increaseDocumentAttribute(
Expand Down Expand Up @@ -7496,7 +7496,7 @@ public function decreaseDocumentAttribute(

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

$this->adapter->increaseDocumentAttribute(
Expand Down
26 changes: 26 additions & 0 deletions tests/e2e/Adapter/Scopes/DocumentTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,32 @@ public function testIncreaseArrayAttribute(Document $document): void
}
}

/**
* @depends testIncreaseDecrease
*/
public function testIncreaseDecreasePreserveDates(Document $document): void
{
/** @var Database $database */
$database = $this->getDatabase();

$database->setPreserveDates(true);

$before = $database->getDocument('increase_decrease', $document->getId());
$updatedAt = $before->getUpdatedAt();

$database->increaseDocumentAttribute('increase_decrease', $document->getId(), 'increase', 1);

$after = $database->getDocument('increase_decrease', $document->getId());
$this->assertSame($updatedAt, $after->getUpdatedAt());

$database->decreaseDocumentAttribute('increase_decrease', $document->getId(), 'decrease', 1);

$after = $database->getDocument('increase_decrease', $document->getId());
$this->assertSame($updatedAt, $after->getUpdatedAt());
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

$database->setPreserveDates(false);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

/**
* @depends testCreateDocument
*/
Expand Down
Loading