From dcbb1c0dd1130386f4d37b634aa175e749904cc7 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Tue, 31 Oct 2023 00:47:33 +0100 Subject: [PATCH] Handle backups with categories having default category name (#745) We do not allow any category to have the default categories name ("default" case-insensitive). In case the backup includes a category with this name, it won't be matched to any category in our database and also won't insert a new category. This will then lead to an exception, causing the backup to fail. --- .../manga/impl/backup/proto/ProtoBackupImport.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/backup/proto/ProtoBackupImport.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/backup/proto/ProtoBackupImport.kt index 2c6fa1ae..f753a4a5 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/backup/proto/ProtoBackupImport.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/backup/proto/ProtoBackupImport.kt @@ -77,7 +77,13 @@ object ProtoBackupImport : ProtoBackupBase() { val categoryMapping = transaction { backup.backupCategories.associate { - it.order to CategoryTable.select { CategoryTable.name eq it.name }.first()[CategoryTable.id].value + val dbCategory = CategoryTable.select { CategoryTable.name eq it.name }.firstOrNull() + val categoryId = + dbCategory?.let { + categoryResultRow -> + categoryResultRow[CategoryTable.id].value + } ?: Category.DEFAULT_CATEGORY_ID + it.order to categoryId } }