mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix creating revisions for non-text notes #4176
This commit is contained in:
parent
bb81f110dd
commit
a749e24147
@ -1624,10 +1624,10 @@ class BNote extends AbstractBeccaEntity {
|
||||
noteContent = noteContent.replaceAll(new RegExp(`href="[^"]*attachmentId=${noteAttachment.attachmentId}[^"]*"`, 'gi'),
|
||||
`href="api/attachments/${revisionAttachment.attachmentId}/download"`);
|
||||
}
|
||||
|
||||
revision.setContent(noteContent, {forceSave: true});
|
||||
}
|
||||
|
||||
revision.setContent(noteContent);
|
||||
|
||||
return revision;
|
||||
});
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ const BBranch = require('../becca/entities/bbranch');
|
||||
const revisionService = require('./revisions');
|
||||
const becca = require("../becca/becca");
|
||||
const utils = require("../services/utils");
|
||||
const eraseService = require("../services/erase");
|
||||
const {sanitizeAttributeName} = require("./sanitize_attribute_name");
|
||||
const noteTypes = require("../services/note_types").getNoteTypeNames();
|
||||
|
||||
@ -440,7 +441,7 @@ class ConsistencyChecks {
|
||||
this.findAndFixIssues(`
|
||||
SELECT notes.noteId, notes.type, notes.mime
|
||||
FROM notes
|
||||
JOIN blobs USING (blobId)
|
||||
JOIN blobs USING (blobId)
|
||||
WHERE isDeleted = 0
|
||||
AND isProtected = 0
|
||||
AND content IS NULL`,
|
||||
@ -460,19 +461,36 @@ class ConsistencyChecks {
|
||||
}
|
||||
|
||||
this.findAndFixIssues(`
|
||||
SELECT revisions.revisionId
|
||||
SELECT revisions.revisionId, blobs.blobId
|
||||
FROM revisions
|
||||
LEFT JOIN blobs USING (blobId)
|
||||
WHERE blobs.blobId IS NULL`,
|
||||
({revisionId}) => {
|
||||
({revisionId, blobId}) => {
|
||||
if (this.autoFix) {
|
||||
revisionService.eraseRevisions([revisionId]);
|
||||
|
||||
this.reloadNeeded = true;
|
||||
|
||||
logFix(`Note revision content '${revisionId}' was set to erased since its content did not exist.`);
|
||||
logFix(`Note revision '${revisionId}' was erased since the referenced blob '${blobId}' did not exist.`);
|
||||
} else {
|
||||
logError(`Note revision content '${revisionId}' does not exist`);
|
||||
logError(`Note revision '${revisionId}' blob '${blobId}' does not exist`);
|
||||
}
|
||||
});
|
||||
|
||||
this.findAndFixIssues(`
|
||||
SELECT attachments.attachmentId, blobs.blobId
|
||||
FROM attachments
|
||||
LEFT JOIN blobs USING (blobId)
|
||||
WHERE blobs.blobId IS NULL`,
|
||||
({attachmentId, blobId}) => {
|
||||
if (this.autoFix) {
|
||||
eraseService.eraseAttachments([attachmentId]);
|
||||
|
||||
this.reloadNeeded = true;
|
||||
|
||||
logFix(`Attachment '${attachmentId}' was erased since the referenced blob '${blobId}' did not exist.`);
|
||||
} else {
|
||||
logError(`Attachment '${attachmentId}' blob '${blobId}' does not exist`);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -183,5 +183,6 @@ module.exports = {
|
||||
eraseDeletedNotesNow,
|
||||
eraseUnusedAttachmentsNow,
|
||||
eraseNotesWithDeleteId,
|
||||
eraseUnusedBlobs
|
||||
eraseUnusedBlobs,
|
||||
eraseAttachments
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ function eraseRevisions(revisionIdsToErase) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.info(`Removing note revisions: ${JSON.stringify(revisionIdsToErase)}`);
|
||||
log.info(`Removing revisions: ${JSON.stringify(revisionIdsToErase)}`);
|
||||
|
||||
sql.executeMany(`DELETE FROM revisions WHERE revisionId IN (???)`, revisionIdsToErase);
|
||||
sql.executeMany(`UPDATE entity_changes SET isErased = 1, utcDateChanged = '${dateUtils.utcNowDateTime()}' WHERE entityName = 'revisions' AND entityId IN (???)`, revisionIdsToErase);
|
||||
|
Loading…
x
Reference in New Issue
Block a user