mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fix manual erasing note revisions
This commit is contained in:
parent
1b0bb22273
commit
d0578971f7
@ -86,7 +86,7 @@
|
||||
"jsdoc": "3.6.6",
|
||||
"lorem-ipsum": "2.0.3",
|
||||
"rcedit": "3.0.0",
|
||||
"webpack": "5.10.1",
|
||||
"webpack": "5.10.3",
|
||||
"webpack-cli": "4.2.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
|
@ -21,7 +21,6 @@ const RELATION = 'relation';
|
||||
* @property {boolean} isProtected - true if note is protected
|
||||
* @property {boolean} isDeleted - true if note is deleted
|
||||
* @property {string|null} deleteId - ID identifying delete transaction
|
||||
* @property {boolean} isErased - true if note's content is erased after it has been deleted
|
||||
* @property {string} dateCreated - local date time (with offset)
|
||||
* @property {string} dateModified - local date time (with offset)
|
||||
* @property {string} utcDateCreated
|
||||
@ -70,9 +69,9 @@ class Note extends Entity {
|
||||
/** @returns {*} */
|
||||
getContent(silentNotFoundError = false) {
|
||||
if (this.content === undefined) {
|
||||
const content = sql.getValue(`SELECT content FROM note_contents WHERE noteId = ?`, [this.noteId]);
|
||||
const row = sql.getRow(`SELECT content FROM note_contents WHERE noteId = ?`, [this.noteId]);
|
||||
|
||||
if (!content) {
|
||||
if (!row) {
|
||||
if (silentNotFoundError) {
|
||||
return undefined;
|
||||
}
|
||||
@ -81,7 +80,7 @@ class Note extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
this.content = content;
|
||||
this.content = row.content;
|
||||
|
||||
if (this.isProtected) {
|
||||
if (this.isContentAvailable) {
|
||||
@ -783,7 +782,7 @@ class Note extends Entity {
|
||||
* @returns {NoteRevision[]}
|
||||
*/
|
||||
getRevisions() {
|
||||
return this.repository.getEntities("SELECT * FROM note_revisions WHERE isErased = 0 AND noteId = ?", [this.noteId]);
|
||||
return this.repository.getEntities("SELECT * FROM note_revisions WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,12 +28,11 @@ const entityChangesService = require('../services/entity_changes.js');
|
||||
class NoteRevision extends Entity {
|
||||
static get entityName() { return "note_revisions"; }
|
||||
static get primaryKeyName() { return "noteRevisionId"; }
|
||||
static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "isErased", "isProtected", "dateLastEdited", "dateCreated", "utcDateLastEdited", "utcDateCreated", "utcDateModified"]; }
|
||||
static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "isProtected", "dateLastEdited", "dateCreated", "utcDateLastEdited", "utcDateCreated", "utcDateModified"]; }
|
||||
|
||||
constructor(row) {
|
||||
super(row);
|
||||
|
||||
this.isErased = !!this.isErased;
|
||||
this.isProtected = !!this.isProtected;
|
||||
|
||||
if (this.isProtected) {
|
||||
|
@ -13,8 +13,7 @@ function getNoteRevisions(req) {
|
||||
LENGTH(note_revision_contents.content) AS contentLength
|
||||
FROM note_revisions
|
||||
JOIN note_revision_contents ON note_revisions.noteRevisionId = note_revision_contents.noteRevisionId
|
||||
WHERE noteId = ?
|
||||
AND isErased = 0
|
||||
WHERE noteId = ?
|
||||
ORDER BY utcDateCreated DESC`, [req.params.noteId]);
|
||||
}
|
||||
|
||||
@ -80,33 +79,16 @@ function downloadNoteRevision(req, res) {
|
||||
res.send(noteRevision.getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {NoteRevision} noteRevision
|
||||
*/
|
||||
function eraseOneNoteRevision(noteRevision) {
|
||||
noteRevision.isErased = true;
|
||||
noteRevision.title = null;
|
||||
noteRevision.save();
|
||||
|
||||
noteRevision.setContent(null);
|
||||
}
|
||||
|
||||
function eraseAllNoteRevisions(req) {
|
||||
const noteRevisionsToErase = repository.getEntities(
|
||||
'SELECT * FROM note_revisions WHERE isErased = 0 AND noteId = ?',
|
||||
const noteRevisionIdsToErase = sql.getColumn(
|
||||
'SELECT noteRevisionId FROM note_revisions WHERE isErased = 0 AND noteId = ?',
|
||||
[req.params.noteId]);
|
||||
|
||||
for (const noteRevision of noteRevisionsToErase) {
|
||||
eraseOneNoteRevision(noteRevision);
|
||||
}
|
||||
noteRevisionService.eraseNoteRevisions(noteRevisionIdsToErase);
|
||||
}
|
||||
|
||||
function eraseNoteRevision(req) {
|
||||
const noteRevision = repository.getNoteRevision(req.params.noteRevisionId);
|
||||
|
||||
if (noteRevision && !noteRevision.isErased) {
|
||||
eraseOneNoteRevision(noteRevision);
|
||||
}
|
||||
noteRevisionService.eraseNoteRevisions([req.params.noteRevisionId]);
|
||||
}
|
||||
|
||||
function restoreNoteRevision(req) {
|
||||
|
@ -114,6 +114,10 @@ function getTree(req) {
|
||||
const collectedNoteIds = new Set([subTreeNoteId]);
|
||||
|
||||
function collect(parentNote) {
|
||||
if (!parentNote) {
|
||||
console.trace(parentNote);
|
||||
}
|
||||
|
||||
for (const childNote of parentNote.children) {
|
||||
collectedNoteIds.add(childNote.noteId);
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
const NoteRevision = require('../entities/note_revision');
|
||||
const dateUtils = require('../services/date_utils');
|
||||
const log = require('../services/log');
|
||||
const dateUtils = require('./date_utils');
|
||||
const log = require('./log');
|
||||
const sql = require('./sql');
|
||||
|
||||
/**
|
||||
* @param {Note} note
|
||||
@ -69,7 +70,20 @@ function createNoteRevision(note) {
|
||||
return noteRevision;
|
||||
}
|
||||
|
||||
function eraseNoteRevisions(noteRevisionIdsToErase) {
|
||||
if (noteRevisionIdsToErase.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
sql.executeMany(`DELETE FROM note_revisions WHERE noteRevisionId IN (???)`, noteRevisionIdsToErase);
|
||||
sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'note_revisions' AND entityId IN (???)`, noteRevisionIdsToErase);
|
||||
|
||||
sql.executeMany(`DELETE FROM note_revision_contents WHERE noteRevisionId IN (???)`, noteRevisionIdsToErase);
|
||||
sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'note_revision_contents' AND entityId IN (???)`, noteRevisionIdsToErase);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
protectNoteRevisions,
|
||||
createNoteRevision
|
||||
createNoteRevision,
|
||||
eraseNoteRevisions
|
||||
};
|
||||
|
@ -698,7 +698,7 @@ function eraseNotes(noteIdsToErase) {
|
||||
const noteRevisionIdsToErase = sql.getManyRows(`SELECT noteRevisionId FROM note_revisions WHERE noteId IN (???)`, noteIdsToErase)
|
||||
.map(row => row.noteRevisionId);
|
||||
|
||||
eraseNoteRevisions(noteRevisionIdsToErase);
|
||||
noteRevisionService.eraseNoteRevisions(noteRevisionIdsToErase);
|
||||
|
||||
log.info(`Erased notes: ${JSON.stringify(noteIdsToErase)}`);
|
||||
}
|
||||
@ -723,18 +723,6 @@ function eraseAttributes(attributeIdsToErase) {
|
||||
sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'attributes' AND entityId IN (???)`, attributeIdsToErase);
|
||||
}
|
||||
|
||||
function eraseNoteRevisions(noteRevisionIdsToErase) {
|
||||
if (noteRevisionIdsToErase.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
sql.executeMany(`DELETE FROM note_revisions WHERE noteRevisionId IN (???)`, noteRevisionIdsToErase);
|
||||
sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'note_revisions' AND entityId IN (???)`, noteRevisionIdsToErase);
|
||||
|
||||
sql.executeMany(`DELETE FROM note_revision_contents WHERE noteRevisionId IN (???)`, noteRevisionIdsToErase);
|
||||
sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'note_revision_contents' AND entityId IN (???)`, noteRevisionIdsToErase);
|
||||
}
|
||||
|
||||
function eraseDeletedEntities(eraseEntitiesAfterTimeInSeconds = null) {
|
||||
if (eraseEntitiesAfterTimeInSeconds === null) {
|
||||
eraseEntitiesAfterTimeInSeconds = optionService.getOptionInt('eraseEntitiesAfterTimeInSeconds');
|
||||
|
Loading…
x
Reference in New Issue
Block a user