mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Revert "- Fixed: attempt migrations fix from 0.5.10 to 0.6.0"
This reverts commit ae8e9a3506.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,70 +0,0 @@
|
||||
//
|
||||
// AppPermission11To17MigrationPolicy.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Magesh K on 11/03/25.
|
||||
// Copyright © 2025 SideStore. All rights reserved.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
|
||||
@objc(AppPermission11To17MigrationPolicy)
|
||||
class AppPermission11To17MigrationPolicy: NSEntityMigrationPolicy {
|
||||
|
||||
override func createDestinationInstances(forSource sInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws {
|
||||
// Let the default implementation create the basic destination AppPermission
|
||||
try super.createDestinationInstances(forSource: sInstance, in: mapping, manager: manager)
|
||||
|
||||
// Get the destination AppPermission instance that was created
|
||||
guard let destinationPermission = manager.destinationInstances(forEntityMappingName: mapping.name, sourceInstances: [sInstance]).first else {
|
||||
print("Failed to locate destination AppPdestinationAppermission instance")
|
||||
return
|
||||
}
|
||||
|
||||
// Extract the type value from source
|
||||
if let type = sInstance.value(forKey: #keyPath(AppPermission.type)) as? String {
|
||||
// In the new model, "permission" is the actual permission string, which needs to be derived from the old "type"
|
||||
let permission = self.derivePermissionFromType(type)
|
||||
destinationPermission.setValue(permission, forKey: #keyPath(AppPermission._permission))
|
||||
}
|
||||
|
||||
// set initial values copied from source as-is to satisfy unique constraints
|
||||
// (will be updated by StoreApp and Source migration policy in its createRelationship() method)
|
||||
if let storeApp = sInstance.value(forKey: #keyPath(AppPermission.app)) as? NSManagedObject{
|
||||
if let appBundle = storeApp.value(forKey: #keyPath(StoreApp.bundleIdentifier)) as? String{
|
||||
destinationPermission.setValue(appBundle, forKey: #keyPath(AppPermission.appBundleID))
|
||||
}
|
||||
|
||||
if let sourceID = storeApp.value(forKey: #keyPath(StoreApp.sourceIdentifier)) as? String {
|
||||
destinationPermission.setValue(sourceID, forKey: #keyPath(AppPermission.sourceID))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to derive permission string from type
|
||||
private func derivePermissionFromType(_ type: String) -> String {
|
||||
// Based on the code in the documents, we need to map the ALTAppPermissionType to permission strings
|
||||
switch type {
|
||||
case "photos": return "NSPhotosUsageDescription"
|
||||
case "camera": return "NSCameraUsageDescription"
|
||||
case "location": return "NSLocationUsageDescription"
|
||||
case "contacts": return "NSContactsUsageDescription"
|
||||
case "reminders": return "NSRemindersUsageDescription"
|
||||
case "music": return "NSAppleMusicUsageDescription"
|
||||
case "microphone": return "NSMicrophoneUsageDescription"
|
||||
case "speech-recognition": return "NSSpeechRecognitionUsageDescription"
|
||||
case "background-audio": return "NSBackgroundAudioUsageDescription"
|
||||
case "background-fetch": return "NSBackgroundFetchUsageDescription"
|
||||
case "bluetooth": return "NSBluetoothUsageDescription"
|
||||
case "network": return "NSNetworkUsageDescription"
|
||||
case "calendars": return "NSCalendarsUsageDescription"
|
||||
case "touchID": return "NSTouchIDUsageDescription"
|
||||
case "faceID": return "NSFaceIDUsageDescription"
|
||||
case "siri": return "NSSiriUsageDescription"
|
||||
case "motion": return "NSMotionUsageDescription"
|
||||
case "entitlement": return type // For entitlements, we might keep the raw value
|
||||
case "privacy": return type // For privacy permissions, we might keep the raw value
|
||||
default: return type // Default fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,6 @@ fileprivate extension NSManagedObject
|
||||
return sourceURL
|
||||
}
|
||||
|
||||
var sourceSourceId: String? {
|
||||
let sourceId = self.value(forKey: #keyPath(Source.identifier)) as? String
|
||||
return sourceId
|
||||
}
|
||||
|
||||
var sourceApps: NSOrderedSet? {
|
||||
let apps = self.value(forKey: #keyPath(Source._apps)) as? NSOrderedSet
|
||||
return apps
|
||||
@@ -33,15 +28,10 @@ fileprivate extension NSManagedObject
|
||||
|
||||
fileprivate extension NSManagedObject
|
||||
{
|
||||
func setSourceId(_ sourceID: String)
|
||||
func setSourceSourceID(_ sourceID: String)
|
||||
{
|
||||
self.setValue(sourceID, forKey: #keyPath(Source.identifier))
|
||||
}
|
||||
|
||||
func setSourceSourceUrl(_ sourceURL: URL)
|
||||
{
|
||||
self.setValue(sourceURL, forKey: #keyPath(Source.sourceURL))
|
||||
}
|
||||
|
||||
func setStoreAppSourceID(_ sourceID: String)
|
||||
{
|
||||
@@ -62,11 +52,6 @@ fileprivate extension NSManagedObject
|
||||
{
|
||||
self.setValue(sourceID, forKey: #keyPath(AppPermission.sourceID))
|
||||
}
|
||||
|
||||
func setAppPermissionAppBundleID(_ appBundleID: String)
|
||||
{
|
||||
self.setValue(appBundleID, forKey: #keyPath(AppPermission.appBundleID))
|
||||
}
|
||||
|
||||
func setAppScreenshotSourceID(_ sourceID: String)
|
||||
{
|
||||
@@ -76,11 +61,6 @@ fileprivate extension NSManagedObject
|
||||
|
||||
fileprivate extension NSManagedObject
|
||||
{
|
||||
var bundleId: String? {
|
||||
let bundleID = self.value(forKey: #keyPath(StoreApp.bundleIdentifier)) as? String
|
||||
return bundleID
|
||||
}
|
||||
|
||||
var storeAppVersions: NSOrderedSet? {
|
||||
let versions = self.value(forKey: #keyPath(StoreApp._versions)) as? NSOrderedSet
|
||||
return versions
|
||||
@@ -108,28 +88,15 @@ class Source11To17MigrationPolicy: NSEntityMigrationPolicy
|
||||
|
||||
// Copied from Source.setSourceURL()
|
||||
|
||||
// sidestore official source has been moved to sidestore.io/apps-v2.json
|
||||
// sidestore official soruce has been moved to sidestore.io/apps-v2.json
|
||||
// if we don't switch, users will end up with 2 offical sources
|
||||
if let host = sourceURL.host,
|
||||
host == "apps.sidestore.io" // if using old source
|
||||
if sourceURL.absoluteString.contains("apps.sidestore.io") // if using old source
|
||||
{
|
||||
sourceURL = Source.altStoreSourceURL // switch to latest
|
||||
dInstance.setSourceSourceUrl(sourceURL)
|
||||
}
|
||||
|
||||
let sourceID: String
|
||||
if let existingID = dInstance.sourceSourceId {
|
||||
sourceID = existingID
|
||||
} else {
|
||||
sourceID = try Source.sourceID(from: sourceURL)
|
||||
dInstance.setSourceId(sourceID)
|
||||
}
|
||||
|
||||
if URL(string: sourceID)?.host == "apps.sidestore.io" || sourceID == Source.altStoreSourceURL.absoluteString
|
||||
{
|
||||
dInstance.setSourceId(Source.altStoreIdentifier)
|
||||
}
|
||||
|
||||
let sourceID = try Source.sourceID(from: sourceURL)
|
||||
dInstance.setSourceSourceID(sourceID)
|
||||
|
||||
for case let newsItem as NSManagedObject in dInstance.sourceNewsItems ?? []
|
||||
{
|
||||
@@ -150,9 +117,6 @@ class Source11To17MigrationPolicy: NSEntityMigrationPolicy
|
||||
for case let permission as NSManagedObject in app.storeAppPermissions ?? []
|
||||
{
|
||||
permission.setAppPermissionSourceID(sourceID)
|
||||
if let bundleID = app.bundleId {
|
||||
permission.setAppPermissionAppBundleID(bundleID)
|
||||
}
|
||||
}
|
||||
|
||||
for case let screenshot as NSManagedObject in app.storeAppScreenshots ?? []
|
||||
|
||||
@@ -106,10 +106,9 @@ class StoreApp11To17MigrationPolicy: NSEntityMigrationPolicy {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Create a new ReleaseTrack entity
|
||||
let context = dInstance.managedObjectContext!
|
||||
let releaseTrack = NSEntityDescription.insertNewObject(forEntityName: ReleaseTrack.entity().name! ?? ReleaseTrack.description(), into: context)
|
||||
let releaseTrack = NSEntityDescription.insertNewObject(forEntityName: ReleaseTrack.entity().name!, into: context)
|
||||
releaseTrack.setValue(defaultChannel, forKey: #keyPath(ReleaseTrack._track))
|
||||
|
||||
// Connect the releaseTrack to the destination StoreApp
|
||||
@@ -117,7 +116,7 @@ class StoreApp11To17MigrationPolicy: NSEntityMigrationPolicy {
|
||||
|
||||
|
||||
// Find the mapping name for AppVersion (make sure this exactly matches your mapping model)
|
||||
let appVersionMappingName = findEntityMappingName(for: AppVersion.entity().name ?? AppVersion.description(), in: manager)
|
||||
let appVersionMappingName = findEntityMappingName(for: AppVersion.entity().name!, in: manager)
|
||||
|
||||
// Create a mutable ordered set for the destination AppVersion objects
|
||||
let destinationVersionsSet = NSMutableOrderedSet()
|
||||
@@ -146,4 +145,5 @@ class StoreApp11To17MigrationPolicy: NSEntityMigrationPolicy {
|
||||
// dInstance.setValue(NSOrderedSet(), forKey: #keyPath(StoreApp._versions))
|
||||
dInstance.setValue(nil, forKey: #keyPath(StoreApp._versions))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user