mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
Save categories when manga is unfavorited (#335)
Fixes non-library manga with categories in backups
This commit is contained in:
@@ -90,7 +90,7 @@ object CategoryManga {
|
|||||||
return transaction {
|
return transaction {
|
||||||
CategoryMangaTable.innerJoin(MangaTable)
|
CategoryMangaTable.innerJoin(MangaTable)
|
||||||
.slice(selectedColumns)
|
.slice(selectedColumns)
|
||||||
.select { CategoryMangaTable.category eq categoryId }
|
.select { (MangaTable.inLibrary eq true) and (CategoryMangaTable.category eq categoryId) }
|
||||||
.map(transform)
|
.map(transform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package suwayomi.tachidesk.manga.impl
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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.insert
|
||||||
import org.jetbrains.exposed.sql.select
|
import org.jetbrains.exposed.sql.select
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
@@ -24,17 +23,20 @@ object Library {
|
|||||||
if (!manga.inLibrary) {
|
if (!manga.inLibrary) {
|
||||||
transaction {
|
transaction {
|
||||||
val defaultCategories = CategoryTable.select { CategoryTable.isDefault eq true }.toList()
|
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 }) {
|
MangaTable.update({ MangaTable.id eq manga.id }) {
|
||||||
it[inLibrary] = true
|
it[inLibrary] = true
|
||||||
it[inLibraryAt] = Instant.now().epochSecond
|
it[inLibraryAt] = Instant.now().epochSecond
|
||||||
it[defaultCategory] = defaultCategories.isEmpty()
|
it[defaultCategory] = defaultCategories.isEmpty() && existingCategories.isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultCategories.forEach { category ->
|
if (existingCategories.isEmpty()) {
|
||||||
CategoryMangaTable.insert {
|
defaultCategories.forEach { category ->
|
||||||
it[CategoryMangaTable.category] = category[CategoryTable.id].value
|
CategoryMangaTable.insert {
|
||||||
it[CategoryMangaTable.manga] = mangaId
|
it[CategoryMangaTable.category] = category[CategoryTable.id].value
|
||||||
|
it[CategoryMangaTable.manga] = mangaId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,9 +49,7 @@ object Library {
|
|||||||
transaction {
|
transaction {
|
||||||
MangaTable.update({ MangaTable.id eq manga.id }) {
|
MangaTable.update({ MangaTable.id eq manga.id }) {
|
||||||
it[inLibrary] = false
|
it[inLibrary] = false
|
||||||
it[defaultCategory] = true
|
|
||||||
}
|
}
|
||||||
CategoryMangaTable.deleteWhere { CategoryMangaTable.manga eq mangaId }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user