Merge pull request #3590 from eliandoran/feature/fix_broken_reference_check

Fix broken reference consistency check
This commit is contained in:
zadam 2023-02-10 09:58:24 +01:00 committed by GitHub
commit 2c8fb90ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -148,13 +148,20 @@ class ConsistencyChecks {
AND notes.noteId IS NULL`, AND notes.noteId IS NULL`,
({branchId, parentNoteId}) => { ({branchId, parentNoteId}) => {
if (this.autoFix) { if (this.autoFix) {
const branch = becca.getBranch(branchId); // Delete the old branch and recreate it with root as parent.
branch.parentNoteId = 'root'; const oldBranch = becca.getBranch(branchId);
branch.save(); const noteId = oldBranch.noteId;
oldBranch.markAsDeleted("missing-parent");
const newBranch = new Branch({
parentNoteId: 'root',
noteId: noteId,
prefix: 'recovered'
}).save();
this.reloadNeeded = true; this.reloadNeeded = true;
logFix(`Branch '${branchId}' was set to root parent since it was referencing missing parent note '${parentNoteId}'`); logFix(`Branch '${branchId}' was was missing parent note '${parentNoteId}', so it was deleted. ${newBranch.branchId} was created in the root instead.`);
} else { } else {
logError(`Branch '${branchId}' references missing parent note '${parentNoteId}'`); logError(`Branch '${branchId}' references missing parent note '${parentNoteId}'`);
} }