Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
importing of cloned notes should not depend on ZIP listing order, fixes #2440
zadam074eb1c02f75
diff --git a/src/becca/entities/branch.js b/src/becca/entities/branch.jsindex 6ac065c470..411d1812c4 100644--- a/src/becca/entities/branch.js+++ b/src/becca/entities/branch.js@@ -84,7 +84,7 @@ class Branch extends AbstractEntity {/** @returns {Note} */get childNote() {if (!(this.noteId in this.becca.notes)) {- // entities can come out of order in sync, create skeleton which will be filled later+ // entities can come out of order in sync/import, create skeleton which will be filled laterthis.becca.addNote(this.noteId, new Note({noteId: this.noteId}));}@@ -98,7 +98,7 @@ class Branch extends AbstractEntity {/** @returns {Note} */get parentNote() {if (!(this.parentNoteId in this.becca.notes)) {- // entities can come out of order in sync, create skeleton which will be filled later+ // entities can come out of order in sync/import, create skeleton which will be filled laterthis.becca.addNote(this.parentNoteId, new Note({noteId: this.parentNoteId}));}diff --git a/src/services/import/zip.js b/src/services/import/zip.jsindex 9645e9c106..7d68c27767 100644--- a/src/services/import/zip.js+++ b/src/services/import/zip.js@@ -351,7 +351,19 @@ async function importZip(taskContext, fileBuffer, importRootNote) {let note = becca.getNote(noteId);+ const isProtected = importRootNote.isProtected && protectedSessionService.isProtectedSessionAvailable();+if (note) {+ // only skeleton was created because of altered order of cloned notes in ZIP, we need to update+ // https://github.com/zadam/trilium/issues/2440+ if (note.type === undefined) {+ note.type = type;+ note.mime = mime;+ note.title = noteTitle;+ note.isProtected = isProtected;+ note.save();+ }+note.setContent(content);}else {@@ -367,7 +379,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) {// root notePosition should be ignored since it relates to original document// now import root should be placed after existing notes into new parentnotePosition: (noteMeta && firstNote) ? noteMeta.notePosition : undefined,- isProtected: importRootNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),+ isProtected: isProtected,}));createdNoteIds[note.noteId] = true;