mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
Merge pull request #3590 from eliandoran/feature/fix_broken_reference_check
Fix broken reference consistency check
This commit is contained in:
commit
2c8fb90ecb
@ -148,13 +148,20 @@ class ConsistencyChecks {
|
||||
AND notes.noteId IS NULL`,
|
||||
({branchId, parentNoteId}) => {
|
||||
if (this.autoFix) {
|
||||
const branch = becca.getBranch(branchId);
|
||||
branch.parentNoteId = 'root';
|
||||
branch.save();
|
||||
// Delete the old branch and recreate it with root as parent.
|
||||
const oldBranch = becca.getBranch(branchId);
|
||||
const noteId = oldBranch.noteId;
|
||||
oldBranch.markAsDeleted("missing-parent");
|
||||
|
||||
const newBranch = new Branch({
|
||||
parentNoteId: 'root',
|
||||
noteId: noteId,
|
||||
prefix: 'recovered'
|
||||
}).save();
|
||||
|
||||
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 {
|
||||
logError(`Branch '${branchId}' references missing parent note '${parentNoteId}'`);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user