Open rahul-r opened 3 years ago
I used the following patch which disables the automatic updatedAt/createdAt setting, and imports the fields you mentioned (not fully tested though):
From 7adf73f65b88ac39c2c502032f9083b9646eec3f Mon Sep 17 00:00:00 2001
From: Roman Karwacik <roman.karwacik@redteam-pentesting.de>
Date: Tue, 23 Jan 2024 11:53:30 +0100
Subject: [PATCH] Fix creationDate import
---
server/models/pages.js | 11 ++++-------
server/modules/storage/disk/common.js | 8 ++++++--
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/server/models/pages.js b/server/models/pages.js
index bb5b6585..89e07c13 100644
--- a/server/models/pages.js
+++ b/server/models/pages.js
@@ -115,13 +115,6 @@ module.exports = class Page extends Model {
}
}
- $beforeUpdate() {
- this.updatedAt = new Date().toISOString()
- }
- $beforeInsert() {
- this.createdAt = new Date().toISOString()
- this.updatedAt = new Date().toISOString()
- }
/**
* Solving the violates foreign key constraint using cascade strategy
* using static hooks
@@ -310,6 +303,8 @@ module.exports = class Page extends Model {
path: opts.path,
publishEndDate: opts.publishEndDate || '',
publishStartDate: opts.publishStartDate || '',
+ createdAt: opts.createdAt || new Date().toISOString(),
+ updatedAt: opts.updatedAt || new Date().toISOString(),
title: opts.title,
toc: '[]',
extra: JSON.stringify({
@@ -431,6 +426,8 @@ module.exports = class Page extends Model {
publishEndDate: opts.publishEndDate || '',
publishStartDate: opts.publishStartDate || '',
title: opts.title,
+ createdAt: opts.createdAt || ogPage.createdAt || new Date().toISOString(),
+ updatedAt: opts.updatedAt || new Date().toISOString(),
extra: JSON.stringify({
...ogPage.extra,
js: scriptJs,
diff --git a/server/modules/storage/disk/common.js b/server/modules/storage/disk/common.js
index 9ed0b986..a25822de 100644
--- a/server/modules/storage/disk/common.js
+++ b/server/modules/storage/disk/common.js
@@ -93,7 +93,9 @@ module.exports = {
isPrivate: false,
content: pageData.content,
user: user,
- skipStorage: true
+ skipStorage: true,
+ createdAt: _.get(pageData, 'dateCreated', currentPage.createdAt).toISOString() || '',
+ updatedAt: _.get(pageData, 'date', currentPage.updatedAt).toISOString() || ''
})
} else {
// Not in the DB, can mark as new
@@ -110,7 +112,9 @@ module.exports = {
content: pageData.content,
user: user,
editor: pageEditor,
- skipStorage: true
+ skipStorage: true,
+ createdAt: _.get(pageData, 'dateCreated', '').toISOString() || '',
+ updatedAt: _.get(pageData, 'date', '').toISOString() || '',
})
}
},
--
2.43.0
Actual behavior
I setup local file system storage in wiki.js settings. I created a markdown file with the following content and imported everything to wiki.js (clicked the Run button on Import Everything). --- title: Note-1 description: published: true date: 2012-07-14T22:31:05Z tags: tag1, tag2 editor: markdown dateCreated: 2012-07-14T22:24:50Z --- Note content
The file got imported into wiki.js as expected but the 'last edited by' time in the imported page shows the current time instead of time from the 'date' field of imported file and the page history shows the creation time as current time instead of 'dateCreated' from the imported file
Expected behavior
Imported pages should use the creation time and last edited time from the imported file instead of current time.
Steps to reproduce the behavior