diff --git a/modules/dkan_metastore/src/Controller/MetastoreRevisionController.php b/modules/dkan_metastore/src/Controller/MetastoreRevisionController.php index 791d79858b..f919ca1d23 100644 --- a/modules/dkan_metastore/src/Controller/MetastoreRevisionController.php +++ b/modules/dkan_metastore/src/Controller/MetastoreRevisionController.php @@ -180,6 +180,12 @@ public function post(string $schema_id, string $identifier, Request $request) { $data = json_decode($request->getContent()); $entity->set('moderation_state', $data->state); $entity->setRevisionLogMessage($data->message); + if ($entity->isNewRevision()) { + // Set revision creation time to the current time because + // revisions will reuse the previous revision's timestamp if not set. + $time = new \DateTimeImmutable(); + $entity->setRevisionCreationTime($time->getTimestamp()); + } $entity->save(); } catch (\Exception $e) { diff --git a/modules/dkan_metastore/src/NodeWrapper/Data.php b/modules/dkan_metastore/src/NodeWrapper/Data.php index 6f4c4fa0cc..2d5d19f40b 100644 --- a/modules/dkan_metastore/src/NodeWrapper/Data.php +++ b/modules/dkan_metastore/src/NodeWrapper/Data.php @@ -289,6 +289,12 @@ public function getModerationState() { * service's POST and PUT functions rather than saving the node directly. */ public function save() { + if ($this->node->getEntityType()->isRevisionable() && $this->node->isNewRevision()) { + // Set revision creation time to the current time because + // revisions will reuse the previous revision's timestamp if not set. + $time = new \DateTimeImmutable(); + $this->node->setRevisionCreationTime($time->getTimestamp()); + } $this->node->save(); } diff --git a/modules/dkan_metastore/src/Reference/Referencer.php b/modules/dkan_metastore/src/Reference/Referencer.php index 5e51583a17..8ffa04f4ea 100644 --- a/modules/dkan_metastore/src/Reference/Referencer.php +++ b/modules/dkan_metastore/src/Reference/Referencer.php @@ -447,6 +447,12 @@ protected function checkExistingReference(string $property_id, $data) { // If an existing referenced node is found but unpublished, publish it. if ($node->get('moderation_state')->value !== 'published') { $node->set('moderation_state', 'published'); + if ($node->getEntityType()->isRevisionable() && $node->isNewRevision()) { + // Set revision creation time to the current time because + // revisions will reuse the previous revision's timestamp if not set. + $time = new \DateTimeImmutable(); + $node->setRevisionCreationTime($time->getTimestamp()); + } $node->save(); } return $node->uuid(); diff --git a/modules/dkan_metastore/src/Storage/Data.php b/modules/dkan_metastore/src/Storage/Data.php index e49c54a56a..8015435c48 100644 --- a/modules/dkan_metastore/src/Storage/Data.php +++ b/modules/dkan_metastore/src/Storage/Data.php @@ -254,6 +254,12 @@ protected function setWorkflowState(string $uuid, string $state): bool { } elseif ($state !== $entity->get('moderation_state')->getString()) { $entity->set('moderation_state', $state); + if ($entity->getEntityType()->isRevisionable() && $entity->isNewRevision()) { + // Set revision creation time to the current time because + // revisions will reuse the previous revision's timestamp if not set. + $time = new \DateTimeImmutable(); + $entity->setRevisionCreationTime($time->getTimestamp()); + } $entity->save(); return TRUE; }