Skip to content

Commit

Permalink
Save categories when manga is unfavorited (Suwayomi#335)
Browse files Browse the repository at this point in the history
Fixes non-library manga with categories in backups
  • Loading branch information
Syer10 authored Apr 8, 2022
1 parent a26b8ec commit db5c5ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object CategoryManga {
return transaction {
CategoryMangaTable.innerJoin(MangaTable)
.slice(selectedColumns)
.select { CategoryMangaTable.category eq categoryId }
.select { (MangaTable.inLibrary eq true) and (CategoryMangaTable.category eq categoryId) }
.map(transform)
}
}
Expand Down
16 changes: 8 additions & 8 deletions server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Library.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package suwayomi.tachidesk.manga.impl
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
Expand All @@ -24,17 +23,20 @@ object Library {
if (!manga.inLibrary) {
transaction {
val defaultCategories = CategoryTable.select { CategoryTable.isDefault eq true }.toList()
val existingCategories = CategoryMangaTable.select { CategoryMangaTable.manga eq mangaId }.toList()

MangaTable.update({ MangaTable.id eq manga.id }) {
it[inLibrary] = true
it[inLibraryAt] = Instant.now().epochSecond
it[defaultCategory] = defaultCategories.isEmpty()
it[defaultCategory] = defaultCategories.isEmpty() && existingCategories.isEmpty()
}

defaultCategories.forEach { category ->
CategoryMangaTable.insert {
it[CategoryMangaTable.category] = category[CategoryTable.id].value
it[CategoryMangaTable.manga] = mangaId
if (existingCategories.isEmpty()) {
defaultCategories.forEach { category ->
CategoryMangaTable.insert {
it[CategoryMangaTable.category] = category[CategoryTable.id].value
it[CategoryMangaTable.manga] = mangaId
}
}
}
}
Expand All @@ -47,9 +49,7 @@ object Library {
transaction {
MangaTable.update({ MangaTable.id eq manga.id }) {
it[inLibrary] = false
it[defaultCategory] = true
}
CategoryMangaTable.deleteWhere { CategoryMangaTable.manga eq mangaId }
}
}
}
Expand Down

0 comments on commit db5c5ed

Please sign in to comment.