mirror of
https://github.com/zadam/trilium.git
synced 2025-01-15 11:39:37 +08:00
Fix broken reference consistency check
If a branch was identified with a missing parent, the branch would be moved to root. However, the ID of the branch would be changed as a result of that, and this resulted in the creation of a new branch instead of updating the old one. Deleting the old one first solves the issue.
This commit is contained in:
parent
e7c6d912a4
commit
92f586486f
1 changed files with 11 additions and 4 deletions
|
@ -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…
Reference in a new issue