Fix favorites migration
This commit is contained in:
@@ -5,9 +5,7 @@ import org.koitharu.kotatsu.core.db.MangaDatabase
|
|||||||
import org.koitharu.kotatsu.core.model.getPreferredBranch
|
import org.koitharu.kotatsu.core.model.getPreferredBranch
|
||||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.details.domain.DetailsLoadUseCase
|
|
||||||
import org.koitharu.kotatsu.details.domain.ProgressUpdateUseCase
|
import org.koitharu.kotatsu.details.domain.ProgressUpdateUseCase
|
||||||
import org.koitharu.kotatsu.favourites.data.FavouriteEntity
|
|
||||||
import org.koitharu.kotatsu.history.data.HistoryEntity
|
import org.koitharu.kotatsu.history.data.HistoryEntity
|
||||||
import org.koitharu.kotatsu.history.data.PROGRESS_NONE
|
import org.koitharu.kotatsu.history.data.PROGRESS_NONE
|
||||||
import org.koitharu.kotatsu.history.data.toMangaHistory
|
import org.koitharu.kotatsu.history.data.toMangaHistory
|
||||||
@@ -21,7 +19,6 @@ class MigrateUseCase @Inject constructor(
|
|||||||
private val mangaDataRepository: MangaDataRepository,
|
private val mangaDataRepository: MangaDataRepository,
|
||||||
private val database: MangaDatabase,
|
private val database: MangaDatabase,
|
||||||
private val progressUpdateUseCase: ProgressUpdateUseCase,
|
private val progressUpdateUseCase: ProgressUpdateUseCase,
|
||||||
private val useCase: DetailsLoadUseCase
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(oldManga: Manga, newManga: Manga) {
|
suspend operator fun invoke(oldManga: Manga, newManga: Manga) {
|
||||||
@@ -41,16 +38,12 @@ class MigrateUseCase @Inject constructor(
|
|||||||
database.withTransaction {
|
database.withTransaction {
|
||||||
// replace favorites
|
// replace favorites
|
||||||
val favoritesDao = database.getFavouritesDao()
|
val favoritesDao = database.getFavouritesDao()
|
||||||
val oldFavourite = favoritesDao.find(oldDetails.id)
|
val oldFavourites = favoritesDao.findAllRaw(oldDetails.id)
|
||||||
if (oldFavourite != null) {
|
if (oldFavourites.isNotEmpty()) {
|
||||||
favoritesDao.delete(oldManga.id)
|
favoritesDao.delete(oldManga.id)
|
||||||
for (f in oldFavourite.categories) {
|
for (f in oldFavourites) {
|
||||||
val e = FavouriteEntity(
|
val e = f.copy(
|
||||||
mangaId = newManga.id,
|
mangaId = newManga.id,
|
||||||
categoryId = f.categoryId.toLong(),
|
|
||||||
sortKey = f.sortKey,
|
|
||||||
createdAt = f.createdAt,
|
|
||||||
deletedAt = 0,
|
|
||||||
)
|
)
|
||||||
favoritesDao.upsert(e)
|
favoritesDao.upsert(e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,9 @@ abstract class FavouritesDao {
|
|||||||
@Query("SELECT * FROM favourites WHERE manga_id = :id AND deleted_at = 0 GROUP BY manga_id")
|
@Query("SELECT * FROM favourites WHERE manga_id = :id AND deleted_at = 0 GROUP BY manga_id")
|
||||||
abstract suspend fun find(id: Long): FavouriteManga?
|
abstract suspend fun find(id: Long): FavouriteManga?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM favourites WHERE manga_id = :mangaId AND deleted_at = 0")
|
||||||
|
abstract suspend fun findAllRaw(mangaId: Long): List<FavouriteEntity>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Deprecated("Ignores order")
|
@Deprecated("Ignores order")
|
||||||
@Query("SELECT * FROM favourites WHERE manga_id = :id AND deleted_at = 0 GROUP BY manga_id")
|
@Query("SELECT * FROM favourites WHERE manga_id = :id AND deleted_at = 0 GROUP BY manga_id")
|
||||||
|
|||||||
Reference in New Issue
Block a user