fix isProtected consistency for images and files + related consistency check

This commit is contained in:
zadam 2019-03-08 22:25:12 +01:00
parent ae17e4dc60
commit a432ad7483
4 changed files with 20 additions and 8 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "trilium",
"version": "0.30.3-beta",
"version": "0.30.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -117,7 +117,10 @@ async function saveNote() {
}
note.title = $noteTitle.val();
note.noteContent.content = getCurrentNoteContent(note);
if (note.noteContent != null) { // might be null for file/image
note.noteContent.content = getCurrentNoteContent(note);
}
// it's important to set the flag back to false immediatelly after retrieving title and content
// otherwise we might overwrite another change (especially async code)

View File

@ -357,6 +357,13 @@ async function findLogicIssues() {
logFix(`Removed link ${linkId} because target note ${targetNoteId} is also deleted.`);
});
await findIssues(`
SELECT noteId
FROM notes
JOIN note_contents USING(noteId)
WHERE notes.isDeleted = 0 AND notes.isProtected != note_contents.isProtected`,
({noteId}) => `Note ${noteId} has inconsistent isProtected in notes and note_contents tables`);
}
async function runSyncRowChecks(entityName, key) {

View File

@ -332,19 +332,21 @@ async function updateNote(noteId, noteUpdates) {
const noteTitleChanged = note.title !== noteUpdates.title;
noteUpdates.noteContent.content = await saveLinks(note, noteUpdates.noteContent.content);
note.title = noteUpdates.title;
note.isProtected = noteUpdates.isProtected;
await note.save();
if (note.type !== 'file' && note.type !== 'image') {
const noteContent = await note.getNoteContent();
const noteContent = await note.getNoteContent();
if (!['file', 'image'].includes(note.type)) {
noteUpdates.noteContent.content = await saveLinks(note, noteUpdates.noteContent.content);
noteContent.content = noteUpdates.noteContent.content;
noteContent.isProtected = noteUpdates.isProtected;
await noteContent.save();
}
noteContent.isProtected = noteUpdates.isProtected;
await noteContent.save();
if (noteTitleChanged) {
await triggerNoteTitleChanged(note);
}