diff --git a/src/Database/Database.php b/src/Database/Database.php index 6ed45aa99..6d55e5f17 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -5025,6 +5025,19 @@ public function createOrUpdateDocumentsWithIncrease( throw new StructureException($validator->getDescription()); } + if (!$old->isEmpty()) { + // Check if document was updated after the request timestamp + try { + $oldUpdatedAt = new \DateTime($old->getUpdatedAt()); + } catch (Exception $e) { + throw new DatabaseException($e->getMessage(), $e->getCode(), $e); + } + + if (!\is_null($this->timestamp) && $oldUpdatedAt > $this->timestamp) { + throw new ConflictException('Document was updated after the request timestamp'); + } + } + if ($this->resolveRelationships) { $document = $this->silent(fn () => $this->createDocumentRelationships($collection, $document)); }