mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
DB migration should convert only "perfect candidates" to attachments
This commit is contained in:
parent
4d00404f55
commit
2dac6ab281
@ -9,7 +9,7 @@ module.exports = () => {
|
|||||||
|
|
||||||
for (const note of Object.values(becca.notes)) {
|
for (const note of Object.values(becca.notes)) {
|
||||||
try {
|
try {
|
||||||
const attachment = note.convertToParentAttachment({force: false});
|
const attachment = note.convertToParentAttachment({autoConversion: true});
|
||||||
|
|
||||||
if (attachment) {
|
if (attachment) {
|
||||||
log.info(`Auto-converted note '${note.noteId}' into attachment '${attachment.attachmentId}'.`);
|
log.info(`Auto-converted note '${note.noteId}' into attachment '${attachment.attachmentId}'.`);
|
||||||
|
@ -1427,14 +1427,16 @@ class BNote extends AbstractBeccaEntity {
|
|||||||
return cloningService.cloneNoteToBranch(this.noteId, branch.branchId);
|
return cloningService.cloneNoteToBranch(this.noteId, branch.branchId);
|
||||||
}
|
}
|
||||||
|
|
||||||
isEligibleForConversionToAttachment() {
|
isEligibleForConversionToAttachment(opts = {autoConversion: false}) {
|
||||||
if (this.type !== 'image' || !this.isContentAvailable() || this.hasChildren() || this.getParentBranches().length !== 1) {
|
if (this.type !== 'image' || !this.isContentAvailable() || this.hasChildren() || this.getParentBranches().length !== 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetRelations = this.getTargetRelations().filter(relation => relation.name === 'imageLink');
|
const targetRelations = this.getTargetRelations().filter(relation => relation.name === 'imageLink');
|
||||||
|
|
||||||
if (targetRelations.length > 1) {
|
if (opts.autoConversion && targetRelations.length === 0) {
|
||||||
|
return false;
|
||||||
|
} else if (targetRelations.length > 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1461,16 +1463,16 @@ class BNote extends AbstractBeccaEntity {
|
|||||||
*
|
*
|
||||||
* Currently, works only for image notes.
|
* Currently, works only for image notes.
|
||||||
*
|
*
|
||||||
* In future, this functionality might get more generic and some of the requirements relaxed.
|
* In the future, this functionality might get more generic and some of the requirements relaxed.
|
||||||
*
|
*
|
||||||
* @params {Object} [opts]
|
* @params {Object} [opts]
|
||||||
* @params {bolean} [opts.force=false} it is envisioned that user can force the conversion even if some conditions
|
* @params {bolean} [opts.autoConversion=false} if true, the action is not triggered by user, but e.g. by migration,
|
||||||
* are not satisfied (e.g., relation to parent doesn't exist).
|
* and only perfect candidates will be migrated
|
||||||
*
|
*
|
||||||
* @returns {BAttachment|null} - null if note is not eligible for conversion
|
* @returns {BAttachment|null} - null if note is not eligible for conversion
|
||||||
*/
|
*/
|
||||||
convertToParentAttachment(opts = {force: false}) {
|
convertToParentAttachment(opts = {autoConversion: false}) {
|
||||||
if (!this.isEligibleForConversionToAttachment()) {
|
if (!this.isEligibleForConversionToAttachment(opts)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ function convertNoteToAttachment(req) {
|
|||||||
const note = becca.getNoteOrThrow(noteId);
|
const note = becca.getNoteOrThrow(noteId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
attachment: note.convertToParentAttachment({ force: true })
|
attachment: note.convertToParentAttachment()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user