mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	fix duplicating subtree with internal links, closes #3813
This commit is contained in:
		@@ -96,7 +96,7 @@ class BAttribute extends AbstractBeccaEntity {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (this.type === 'relation' && !(this.value in this.becca.notes)) {
 | 
					        if (this.type === 'relation' && !(this.value in this.becca.notes)) {
 | 
				
			||||||
            throw new Error(`Cannot save relation '${this.name}' of note '${this.noteId}' since it target not existing note '${this.value}'.`);
 | 
					            throw new Error(`Cannot save relation '${this.name}' of note '${this.noteId}' since it targets not existing note '${this.value}'.`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -97,7 +97,7 @@ class BNote extends AbstractBeccaEntity {
 | 
				
			|||||||
         * @private */
 | 
					         * @private */
 | 
				
			||||||
        this.parents = [];
 | 
					        this.parents = [];
 | 
				
			||||||
        /** @type {BNote[]}
 | 
					        /** @type {BNote[]}
 | 
				
			||||||
         * @private*/
 | 
					         * @private */
 | 
				
			||||||
        this.children = [];
 | 
					        this.children = [];
 | 
				
			||||||
        /** @type {BAttribute[]}
 | 
					        /** @type {BAttribute[]}
 | 
				
			||||||
         * @private */
 | 
					         * @private */
 | 
				
			||||||
@@ -107,11 +107,11 @@ class BNote extends AbstractBeccaEntity {
 | 
				
			|||||||
         * @private */
 | 
					         * @private */
 | 
				
			||||||
        this.__attributeCache = null;
 | 
					        this.__attributeCache = null;
 | 
				
			||||||
        /** @type {BAttribute[]|null}
 | 
					        /** @type {BAttribute[]|null}
 | 
				
			||||||
         * @private*/
 | 
					         * @private */
 | 
				
			||||||
        this.inheritableAttributeCache = null;
 | 
					        this.inheritableAttributeCache = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /** @type {BAttribute[]}
 | 
					        /** @type {BAttribute[]}
 | 
				
			||||||
         * @private*/
 | 
					         * @private */
 | 
				
			||||||
        this.targetRelations = [];
 | 
					        this.targetRelations = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.becca.addNote(this.noteId, this);
 | 
					        this.becca.addNote(this.noteId, this);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -841,7 +841,7 @@ function duplicateSubtree(origNoteId, newParentNoteId) {
 | 
				
			|||||||
        throw new Error('Duplicating root is not possible');
 | 
					        throw new Error('Duplicating root is not possible');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    log.info(`Duplicating ${origNoteId} subtree into ${newParentNoteId}`);
 | 
					    log.info(`Duplicating '${origNoteId}' subtree into '${newParentNoteId}'`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const origNote = becca.notes[origNoteId];
 | 
					    const origNote = becca.notes[origNoteId];
 | 
				
			||||||
    // might be null if orig note is not in the target newParentNoteId
 | 
					    // might be null if orig note is not in the target newParentNoteId
 | 
				
			||||||
@@ -919,7 +919,8 @@ function duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapp
 | 
				
			|||||||
                attr.value = noteIdMapping[attr.value];
 | 
					                attr.value = noteIdMapping[attr.value];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            attr.save();
 | 
					            // the relation targets may not be created yet, the mapping is pre-generated
 | 
				
			||||||
 | 
					            attr.save({skipValidation: true});
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const childBranch of origNote.getChildBranches()) {
 | 
					        for (const childBranch of origNote.getChildBranches()) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user