Merge pull request #3757 from kiwix/Fix#3756

Fixed: Migration of bookmarks is not working with recent versions of custom apps.
This commit is contained in:
Kelson 2024-03-19 20:27:19 +01:00 committed by GitHub
commit d4a3db11ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 5 deletions

View File

@ -55,15 +55,22 @@ class ObjectBoxToLibkiwixMigrator {
try {
// for saving book to library, otherwise it does not save the
// favicon and zimFilePath in library.
val archive = Archive(bookmarkEntity.zimFilePath)
val libkiwixBook = Book().apply {
update(archive)
var archive: Archive? = null
val libkiwixBook = bookmarkEntity.zimFilePath?.let {
archive = Archive(bookmarkEntity.zimFilePath)
Book().apply {
update(archive)
}
} ?: kotlin.run {
// for migrating bookmarks for recent custom apps since in recent version of
// custom app we are using the `assetFileDescriptor` which does not have the filePath.
null
}
libkiwixBookmarks.saveBookmark(
LibkiwixBookmarkItem(bookmarkEntity, libkiwixBook),
shouldWriteBookmarkToFile = index == bookMarksList.size - 1
)
archive.dispose()
archive?.dispose()
// TODO should we remove data from objectBox?
// removing the single entity from the object box after migration.
// box.query {

View File

@ -68,7 +68,7 @@ data class LibkiwixBookmarkItem(
constructor(
bookmarkEntity: BookmarkEntity,
libkiwixBook: Book
libkiwixBook: Book?
) : this(
zimId = bookmarkEntity.zimId,
zimFilePath = bookmarkEntity.zimFilePath,