diff --git a/App/App_iOS.swift b/App/App_iOS.swift index 41e37aad..f9e06615 100644 --- a/App/App_iOS.swift +++ b/App/App_iOS.swift @@ -31,10 +31,7 @@ struct Kiwix: App { UNUserNotificationCenter.current().delegate = appDelegate // MARK: - migrations if !ProcessInfo.processInfo.arguments.contains("testing") { - let migrations = MigrationService(migrations: [ - Migrations.schemeToZIM(using: Database.shared.viewContext) - ]) - _ = migrations.migrateAll() + _ = MigrationService().migrateAll() } } diff --git a/App/App_macOS.swift b/App/App_macOS.swift index 5ca46b7a..1bdfcad5 100644 --- a/App/App_macOS.swift +++ b/App/App_macOS.swift @@ -230,10 +230,7 @@ struct RootView: View { } // MARK: - migrations if !ProcessInfo.processInfo.arguments.contains("testing") { - let migrations = MigrationService(migrations: [ - Migrations.schemeToZIM(using: Database.shared.viewContext) - ]) - _ = migrations.migrateAll() + _ = MigrationService().migrateAll() } } .withHostingWindow { [windowTracker] hostWindow in diff --git a/Model/Migration/MigrateSchemeToZIM.swift b/Model/Migration/MigrateSchemeToZIM.swift index 0446aee0..2729c56b 100644 --- a/Model/Migration/MigrateSchemeToZIM.swift +++ b/Model/Migration/MigrateSchemeToZIM.swift @@ -16,8 +16,7 @@ import Foundation import CoreData -enum Migrations { - +extension Migrations { /// Change the bookmarks articleURLs from "kiwix://..." to "zim://..." /// - Parameter context: DataBase context /// - Returns: Migration - general struct diff --git a/Model/Migration/MigrationService.swift b/Model/Migration/MigrationService.swift index 6b16cd7e..d7d5993c 100644 --- a/Model/Migration/MigrationService.swift +++ b/Model/Migration/MigrationService.swift @@ -39,6 +39,10 @@ struct Migration { struct MigrationService { let migrations: [Migration] + init(migrations: [Migration] = Migrations.all) { + self.migrations = migrations + } + func migrateAll(using userDefaults: UserDefaulting = UserDefaults.standard) -> Bool { var allSucceeded = true for migration in migrations where migration.migrate(userDefaults) == false { diff --git a/Model/Migration/Migrations.swift b/Model/Migration/Migrations.swift new file mode 100644 index 00000000..ece022d6 --- /dev/null +++ b/Model/Migration/Migrations.swift @@ -0,0 +1,25 @@ +// This file is part of Kiwix for iOS & macOS. +// +// Kiwix is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// any later version. +// +// Kiwix is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kiwix; If not, see https://www.gnu.org/licenses/. + +import Foundation + +enum Migrations { + + /// A central place for all migrations + /// they will be executed in the order specified here + static let all: [Migration] = [ + Self.schemeToZIM(using: Database.shared.viewContext) + ] +}