1
0
Fork 0
mirror of https://github.com/requarks/wiki.git synced 2026-03-02 22:06:55 -05:00

Importing from Local File System is ignoring dateCreated and date fields #2548

Open
opened 2026-02-20 19:06:59 -05:00 by deekerman · 3 comments
Owner

Originally created by @rahul-r on GitHub (Oct 26, 2021).

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

  1. Enable local file system storage wiki.js (Settings > Storage > Local File System)
  2. Create a markdown file with the aforementioned content in the backup location
  3. Import the file into wiki.js by running 'Import Everything'
  4. Open the imported page in wiki.js and navigate to the page history page and note the creation and last edited times.
Originally created by @rahul-r on GitHub (Oct 26, 2021). <!-- Wiki.js 1.x? Go to https://github.com/Requarks/wiki-v1/issues --> ### 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 2. Enable local file system storage wiki.js (Settings > Storage > Local File System) 2. Create a markdown file with the aforementioned content in the backup location 3. Import the file into wiki.js by running 'Import Everything' 4. Open the imported page in wiki.js and navigate to the page history page and note the creation and last edited times. <!-- FOR FEATURE REQUESTS: Use the feature request board instead: https://requests.requarks.io/wiki --> <!-- Love Wiki.js? Please consider supporting our collective: 👉 https://opencollective.com/wikijs/donate -->
Author
Owner

@rtpt-romankarwacik commented on GitHub (Jan 23, 2024):

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

@rtpt-romankarwacik commented on GitHub (Jan 23, 2024): I used the following patch which disables the automatic updatedAt/createdAt setting, and imports the fields you mentioned (not fully tested though): ```diff 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 ```
Author
Owner

@MrSitnikov commented on GitHub (Feb 18, 2025):

Wiki is running in docker-compose:

version: "3"
services:
  db:
    image: postgres:16-alpine
    environment:
      - PUID=1000
      - PGID=1000
      - POSTGRES_DB=wiki
      - POSTGRES_PASSWORD=test
      - POSTGRES_USER=user
    logging:
      driver: "none"
    restart: unless-stopped
    volumes:
      - db-data:/var/lib/postgresql/data
  wiki:
    image: ghcr.io/requarks/wiki:2
    depends_on:
      - db
    environment:
      - PUID=1000
      - PGID=1000
      - DB_TYPE=postgres
      - DB_HOST=db
      - DB_PORT=5432
      - DB_USER=user
      - DB_PASS=test
      - DB_NAME=wiki
    restart: unless-stopped
    ports:
      - "8080:3000"
    volumes:
      - ./wiki_backup:/wiki/wiki_backup
volumes:
  db-data:

Specified the backup folder: - ./wiki_backup
In Local File System specified the same folder:./wiki_backup
Create Backup runs correctly, but Import Everything gives errors:

wiki_1  | 2025-02-18T19:58:17.795Z [MASTER] info: (STORAGE/DISK) Importing all content from local disk folder to the DB...
wiki_1  | 2025-02-18T19:58:17.818Z [MASTER] info: (STORAGE/DISK) Processing kup/_manual...
wiki_1  | 2025-02-18T19:58:17.822Z [MASTER] info: (STORAGE/DISK) Asset marked for import: kup/_manual
wiki_1  | 2025-02-18T19:58:17.875Z [MASTER] warn: EISDIR: illegal operation on a directory, read
wiki_1  | 2025-02-18T19:58:17.877Z [MASTER] info: (STORAGE/DISK) Processing kup/home.md...
wiki_1  | 2025-02-18T19:58:17.881Z [MASTER] warn: (STORAGE/DISK) Failed to process page kup/home.md
wiki_1  | 2025-02-18T19:58:17.881Z [MASTER] warn: ENOENT: no such file or directory, open 'wiki_backup/kup/home.md'
wiki_1  | 2025-02-18T19:58:17.884Z [MASTER] info: (STORAGE/DISK) Processing kup/_manual/wiki-20250218-195757.tar.gz...
wiki_1  | 2025-02-18T19:58:17.884Z [MASTER] info: (STORAGE/DISK) Asset marked for import: kup/_manual/wiki-20250218-195757.tar.gz
wiki_1  | 2025-02-18T19:58:17.936Z [MASTER] info: (STORAGE/DISK) Import completed.

Can you tell me the right way to do the recovery.

@MrSitnikov commented on GitHub (Feb 18, 2025): Wiki is running in docker-compose: ``` version: "3" services: db: image: postgres:16-alpine environment: - PUID=1000 - PGID=1000 - POSTGRES_DB=wiki - POSTGRES_PASSWORD=test - POSTGRES_USER=user logging: driver: "none" restart: unless-stopped volumes: - db-data:/var/lib/postgresql/data wiki: image: ghcr.io/requarks/wiki:2 depends_on: - db environment: - PUID=1000 - PGID=1000 - DB_TYPE=postgres - DB_HOST=db - DB_PORT=5432 - DB_USER=user - DB_PASS=test - DB_NAME=wiki restart: unless-stopped ports: - "8080:3000" volumes: - ./wiki_backup:/wiki/wiki_backup volumes: db-data: ``` Specified the backup folder: - ./wiki_backup In Local File System specified the same folder:./wiki_backup Create Backup runs correctly, but Import Everything gives errors: ``` wiki_1 | 2025-02-18T19:58:17.795Z [MASTER] info: (STORAGE/DISK) Importing all content from local disk folder to the DB... wiki_1 | 2025-02-18T19:58:17.818Z [MASTER] info: (STORAGE/DISK) Processing kup/_manual... wiki_1 | 2025-02-18T19:58:17.822Z [MASTER] info: (STORAGE/DISK) Asset marked for import: kup/_manual wiki_1 | 2025-02-18T19:58:17.875Z [MASTER] warn: EISDIR: illegal operation on a directory, read wiki_1 | 2025-02-18T19:58:17.877Z [MASTER] info: (STORAGE/DISK) Processing kup/home.md... wiki_1 | 2025-02-18T19:58:17.881Z [MASTER] warn: (STORAGE/DISK) Failed to process page kup/home.md wiki_1 | 2025-02-18T19:58:17.881Z [MASTER] warn: ENOENT: no such file or directory, open 'wiki_backup/kup/home.md' wiki_1 | 2025-02-18T19:58:17.884Z [MASTER] info: (STORAGE/DISK) Processing kup/_manual/wiki-20250218-195757.tar.gz... wiki_1 | 2025-02-18T19:58:17.884Z [MASTER] info: (STORAGE/DISK) Asset marked for import: kup/_manual/wiki-20250218-195757.tar.gz wiki_1 | 2025-02-18T19:58:17.936Z [MASTER] info: (STORAGE/DISK) Import completed. ``` Can you tell me the right way to do the recovery.
Author
Owner

@ReySadeghi commented on GitHub (Mar 3, 2025):

@MrSitnikov
I found that it seems search from kup/ folder so if you put your files in this directory on local disk, the files are imported under folder of kup/ on wiki.js: ./wiki_backup/kup/

but I don't know the reason and how to rename kup/ from wiki.js.
any help??
@NGPixel

@ReySadeghi commented on GitHub (Mar 3, 2025): @MrSitnikov I found that it seems search from kup/ folder so if you put your files in this directory on local disk, the files are imported under folder of kup/ on wiki.js: `./wiki_backup/kup/` but I don't know the reason and how to rename kup/ from wiki.js. any help?? @NGPixel
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/wiki-requarks#2548
No description provided.