From ade22ea8259591461f3a8f319fc225eabd636bce Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 10 Feb 2023 10:09:06 +0100 Subject: [PATCH] recover notes into root only if no other valid branch exists, #3590 --- src/services/consistency_checks.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 41598733e..4cc8e6cbb 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -153,15 +153,23 @@ class ConsistencyChecks { const noteId = oldBranch.noteId; oldBranch.markAsDeleted("missing-parent"); - const newBranch = new Branch({ - parentNoteId: 'root', - noteId: noteId, - prefix: 'recovered' - }).save(); + let message = `Branch '${branchId}' was was missing parent note '${parentNoteId}', so it was deleted. `; + + if (becca.getNote(noteId).getParentBranches().length === 0) { + const newBranch = new Branch({ + parentNoteId: 'root', + noteId: noteId, + prefix: 'recovered' + }).save(); + + message += `${newBranch.branchId} was created in the root instead.`; + } else { + message += `There is one or more valid branches, so no new one will be created as a replacement.`; + } this.reloadNeeded = true; - logFix(`Branch '${branchId}' was was missing parent note '${parentNoteId}', so it was deleted. ${newBranch.branchId} was created in the root instead.`); + logFix(message); } else { logError(`Branch '${branchId}' references missing parent note '${parentNoteId}'`); }