1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-06 23:56:13 +02:00

All: Fixes #5223: Fixed issue with orphaned resource being created in case of a resource conflict

This commit is contained in:
Laurent Cozic
2021-08-05 14:25:25 +01:00
parent d3cd843fc8
commit f08af4d036
2 changed files with 27 additions and 4 deletions

View File

@ -389,15 +389,31 @@ export default class Resource extends BaseItem {
return newResource;
}
static async createConflictResourceNote(resource: ResourceEntity) {
const Note = this.getClass('Note');
public static async resourceConflictFolderId(): Promise<string> {
const folder = await this.resourceConflictFolder();
return folder.id;
}
private static async resourceConflictFolder(): Promise<any> {
const conflictFolderTitle = _('Conflicts (attachments)');
const Folder = this.getClass('Folder');
const folder = await Folder.loadByTitle(conflictFolderTitle);
if (!folder || folder.parent_id) {
return Folder.save({ title: conflictFolderTitle });
}
return folder;
}
public static async createConflictResourceNote(resource: ResourceEntity) {
const Note = this.getClass('Note');
const conflictResource = await Resource.duplicateResource(resource.id);
await Note.save({
title: _('Attachment conflict: "%s"', resource.title),
body: _('There was a [conflict](%s) on the attachment below.\n\n%s', 'https://joplinapp.org/conflict/', Resource.markdownTag(conflictResource)),
is_conflict: 1,
parent_id: await this.resourceConflictFolderId(),
}, { changeSource: ItemChange.SOURCE_SYNC });
}