mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01: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
@ -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}'`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user