mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 17:38:47 +02:00
fix setNoteToParent and deprecate it
This commit is contained in:
parent
0837cabb41
commit
dea5195223
@ -282,9 +282,10 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix.
|
||||
*
|
||||
* @method
|
||||
* @deprecated - this method is pretty confusing and serves specialized purpose only
|
||||
* @param {string} noteId
|
||||
* @param {string} prefix
|
||||
* @param {string} [parentNoteId]
|
||||
* @param {string|null} parentNoteId
|
||||
*/
|
||||
this.setNoteToParent = treeService.setNoteToParent;
|
||||
|
||||
|
@ -195,7 +195,7 @@ async function findExistencyIssues() {
|
||||
HAVING
|
||||
COUNT(*) > 1`,
|
||||
async ({noteId, parentNoteId}) => {
|
||||
const branches = await repository.getEntities(`SELECT * FROM branches WHERE noteId = ? and parentNoteId = ? and isDeleted = 1`, [noteId, parentNoteId]);
|
||||
const branches = await repository.getEntities(`SELECT * FROM branches WHERE noteId = ? and parentNoteId = ? and isDeleted = 0`, [noteId, parentNoteId]);
|
||||
|
||||
// it's not necessarily "original" branch, it's just the only one which will survive
|
||||
const origBranch = branches[0];
|
||||
|
@ -36,7 +36,7 @@ async function validateParentChild(parentNoteId, childNoteId, branchId = null) {
|
||||
}
|
||||
|
||||
async function getExistingBranch(parentNoteId, childNoteId) {
|
||||
return await sql.getRow('SELECT * FROM branches WHERE noteId = ? AND parentNoteId = ? AND isDeleted = 0', [childNoteId, parentNoteId]);
|
||||
return await repository.getEntity('SELECT * FROM branches WHERE noteId = ? AND parentNoteId = ? AND isDeleted = 0', [childNoteId, parentNoteId]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,6 +123,9 @@ async function sortNotesAlphabetically(parentNoteId, directoriesFirst = false) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - this will be removed in the future
|
||||
*/
|
||||
async function setNoteToParent(noteId, prefix, parentNoteId) {
|
||||
const parentNote = await repository.getNote(parentNoteId);
|
||||
|
||||
@ -151,11 +154,19 @@ async function setNoteToParent(noteId, prefix, parentNoteId) {
|
||||
throw new Error(`Cannot create a branch for ${noteId} which is deleted.`);
|
||||
}
|
||||
|
||||
await new Branch({
|
||||
noteId: noteId,
|
||||
parentNoteId: parentNoteId,
|
||||
prefix: prefix
|
||||
}).save();
|
||||
const branch = await repository.getEntity('SELECT * FROM branches WHERE isDeleted = 0 AND noteId = ? AND parentNoteId = ?', [noteId, parentNoteId]);
|
||||
|
||||
if (branch) {
|
||||
branch.prefix = prefix;
|
||||
await branch.save();
|
||||
}
|
||||
else {
|
||||
await new Branch({
|
||||
noteId: noteId,
|
||||
parentNoteId: parentNoteId,
|
||||
prefix: prefix
|
||||
}).save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user