1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-12-05 22:57:29 +02:00

Desktop, Cli: Fixes #2331: Only de-duplicate imported notebook titles when needed

This commit is contained in:
Laurent Cozic
2020-06-28 18:00:51 +01:00
parent d601575549
commit eb8841379c
4 changed files with 68 additions and 4 deletions

View File

@@ -29,11 +29,21 @@ class BaseItem extends BaseModel {
throw new Error(`Invalid class name: ${className}`);
}
static async findUniqueItemTitle(title) {
static async findUniqueItemTitle(title, parentId = null) {
let counter = 1;
let titleToTry = title;
while (true) {
const item = await this.loadByField('title', titleToTry);
let item = null;
if (parentId !== null) {
item = await this.loadByFields({
title: titleToTry,
parent_id: parentId,
});
} else {
item = await this.loadByField('title', titleToTry);
}
if (!item) return titleToTry;
titleToTry = `${title} (${counter})`;
counter++;