fix: import JSON/HTML ne conserve qu’un lien par import (id=0 + REPLACE) #3
@@ -50,7 +50,17 @@ class BookmarkImporter @Inject constructor(
|
|||||||
var imported = 0
|
var imported = 0
|
||||||
var skipped = 0
|
var skipped = 0
|
||||||
val errors = mutableListOf<String>()
|
val errors = mutableListOf<String>()
|
||||||
|
|
||||||
|
// BUG CORRIGÉ : LinkEntity.id est une @PrimaryKey sans autoGenerate et
|
||||||
|
// insertLink utilise OnConflictStrategy.REPLACE. Donner id = 0 à chaque
|
||||||
|
// lien faisait donc écraser la ligne précédente à chaque insertion :
|
||||||
|
// seul le dernier lien du fichier survivait (le compteur, lui, était
|
||||||
|
// incrémenté avant l'insertion, d'où un dialogue « 1785 importés »
|
||||||
|
// pour 1 seul lien visible). On alloue donc un id temporaire négatif
|
||||||
|
// unique par lien, comme le fait déjà LinkRepositoryImpl.addLink,
|
||||||
|
// en vérifiant qu'il n'existe pas déjà en base.
|
||||||
|
var nextTempId = -1
|
||||||
|
|
||||||
links.forEach { bookmark ->
|
links.forEach { bookmark ->
|
||||||
try {
|
try {
|
||||||
// Vérifier si le lien existe déjà
|
// Vérifier si le lien existe déjà
|
||||||
@@ -59,9 +69,14 @@ class BookmarkImporter @Inject constructor(
|
|||||||
skipped++
|
skipped++
|
||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (linkDao.getLinkById(nextTempId) != null) {
|
||||||
|
nextTempId--
|
||||||
|
}
|
||||||
|
val tempId = nextTempId--
|
||||||
|
|
||||||
val entity = LinkEntity(
|
val entity = LinkEntity(
|
||||||
id = 0,
|
id = tempId,
|
||||||
url = bookmark.url,
|
url = bookmark.url,
|
||||||
title = bookmark.title,
|
title = bookmark.title,
|
||||||
description = bookmark.description ?: "",
|
description = bookmark.description ?: "",
|
||||||
@@ -104,7 +119,14 @@ class BookmarkImporter @Inject constructor(
|
|||||||
var imported = 0
|
var imported = 0
|
||||||
var skipped = 0
|
var skipped = 0
|
||||||
val errors = mutableListOf<String>()
|
val errors = mutableListOf<String>()
|
||||||
|
|
||||||
|
// Même correctif que pour importFromHtml : id = 0 pour tous les liens
|
||||||
|
// + insert REPLACE écrasait chaque ligne par la suivante, ne laissant
|
||||||
|
// qu'un seul lien en base par import (le dernier non encore présent
|
||||||
|
// après la synchro, qui libérait l'id 0). Chaque lien importé reçoit
|
||||||
|
// donc un id temporaire négatif unique, vérifié contre la base.
|
||||||
|
var nextTempId = -1
|
||||||
|
|
||||||
exportData.links.forEach { link ->
|
exportData.links.forEach { link ->
|
||||||
try {
|
try {
|
||||||
val existing = linkDao.getLinkByUrl(link.url)
|
val existing = linkDao.getLinkByUrl(link.url)
|
||||||
@@ -112,7 +134,12 @@ class BookmarkImporter @Inject constructor(
|
|||||||
skipped++
|
skipped++
|
||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (linkDao.getLinkById(nextTempId) != null) {
|
||||||
|
nextTempId--
|
||||||
|
}
|
||||||
|
val tempId = nextTempId--
|
||||||
|
|
||||||
val contentType = try {
|
val contentType = try {
|
||||||
ContentType.valueOf(link.contentType)
|
ContentType.valueOf(link.contentType)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -120,7 +147,7 @@ class BookmarkImporter @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val entity = LinkEntity(
|
val entity = LinkEntity(
|
||||||
id = 0,
|
id = tempId,
|
||||||
url = link.url,
|
url = link.url,
|
||||||
title = link.title,
|
title = link.title,
|
||||||
description = link.description,
|
description = link.description,
|
||||||
|
|||||||
Reference in New Issue
Block a user