浏览代码

replace db

Marino Faggiana 8 年之前
父节点
当前提交
3b352026cc

+ 15 - 13
iOSClient/AppDelegate.m

@@ -136,23 +136,23 @@
 #endif
     
     // Verify upgrade
-    [self upgrade];
+    if ([self upgrade]) {
     
-    // Set account, if no exists clear all
-    //TableAccount *recordAccount = [CCCoreData getActiveAccount];
-    tableAccount *recordAccount = [[NCManageDatabase sharedInstance] getAccountActive];
+        // Set account, if no exists clear all
+        tableAccount *recordAccount = [[NCManageDatabase sharedInstance] getAccountActive];
     
-    if (recordAccount == nil) {
+        if (recordAccount == nil) {
         
-        // remove all the keys Chain
-        [CCUtility deleteAllChainStore];
+            // remove all the keys Chain
+            [CCUtility deleteAllChainStore];
     
-        // remove all the App group key
-        [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
+            // remove all the App group key
+            [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
 
-    } else {
+        } else {
         
-        [self settingActiveAccount:recordAccount.account activeUrl:recordAccount.url activeUser:recordAccount.user activePassword:recordAccount.password];
+            [self settingActiveAccount:recordAccount.account activeUrl:recordAccount.url activeUser:recordAccount.user activePassword:recordAccount.password];
+        }
     }
     
     // Operation Queue OC Networking
@@ -1587,7 +1587,7 @@
 #pragma mark ===== UPGRADE =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)upgrade
+- (BOOL)upgrade
 {
 #ifdef DEBUG
    
@@ -1625,7 +1625,7 @@
             [[NCManageDatabase sharedInstance] addCertificates:certificateLocation];
     }
     
-    if (([actualVersion compare:@"2.17.3" options:NSNumericSearch] == NSOrderedAscending)) {
+    if (([actualVersion compare:@"2.17.5" options:NSNumericSearch] == NSOrderedAscending)) {
         
         // Migrate Account Table From CoreData to Realm
         
@@ -1634,6 +1634,8 @@
             [[NCManageDatabase sharedInstance] addTableAccountOldDB:account];
 
     }
+    
+    return YES;
 }
 
 @end

+ 1 - 1
iOSClient/Brand/Picker.plist

@@ -17,7 +17,7 @@
 	<key>CFBundlePackageType</key>
 	<string>XPC!</string>
 	<key>CFBundleShortVersionString</key>
-	<string>2.17.4</string>
+	<string>2.17.5</string>
 	<key>CFBundleVersion</key>
 	<string>00001</string>
 	<key>NSExtension</key>

+ 1 - 1
iOSClient/Brand/PickerFileProvider.plist

@@ -17,7 +17,7 @@
 	<key>CFBundlePackageType</key>
 	<string>XPC!</string>
 	<key>CFBundleShortVersionString</key>
-	<string>2.17.4</string>
+	<string>2.17.5</string>
 	<key>CFBundleVersion</key>
 	<string>00001</string>
 	<key>NSExtension</key>

+ 1 - 1
iOSClient/Brand/Share.plist

@@ -17,7 +17,7 @@
 	<key>CFBundlePackageType</key>
 	<string>XPC!</string>
 	<key>CFBundleShortVersionString</key>
-	<string>2.17.4</string>
+	<string>2.17.5</string>
 	<key>CFBundleVersion</key>
 	<string>00001</string>
 	<key>NSAppTransportSecurity</key>

+ 1 - 1
iOSClient/Brand/iOSClient.plist

@@ -46,7 +46,7 @@
 	<key>CFBundlePackageType</key>
 	<string>APPL</string>
 	<key>CFBundleShortVersionString</key>
-	<string>2.17.4</string>
+	<string>2.17.5</string>
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleURLTypes</key>

+ 1 - 1
iOSClient/FileSystem/CCCoreData.m

@@ -41,7 +41,7 @@
     records = [TableAccount MR_findAllInContext:context];
     
     for (TableAccount *tableAccount in records)
-        [accounts addObject:tableAccount.account];
+        [accounts addObject:tableAccount];
     
     return accounts;
 }

+ 22 - 5
iOSClient/FileSystem/NCManageDatabase.swift

@@ -33,11 +33,25 @@ class NCManageDatabase: NSObject {
     override init() {
         
         let dirGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.sharedInstance.capabilitiesGroups)
-        var config = Realm.Configuration()
+        let config = Realm.Configuration(
+        
+            fileURL: dirGroup?.appendingPathComponent("\(appDatabaseNextcloud)/\(k_databaseDefault)"),
+            schemaVersion: 1,
+            
+            migrationBlock: { migration, oldSchemaVersion in
+                // We haven’t migrated anything yet, so oldSchemaVersion == 0
+                if (oldSchemaVersion < 1) {
+                    // Nothing to do!
+                    // Realm will automatically detect new properties and removed properties
+                    // And will update the schema on disk automatically
+                }
+        })
         
-        config.fileURL = dirGroup?.appendingPathComponent("\(appDatabaseNextcloud)/\(k_databaseDefault)")
+        
+        //config.fileURL = dirGroup?.appendingPathComponent("\(appDatabaseNextcloud)/\(k_databaseDefault)")
         
         Realm.Configuration.defaultConfiguration = config
+        _ = try! Realm()
     }
     
     //MARK: -
@@ -126,7 +140,6 @@ class NCManageDatabase: NSObject {
                 if table.active == 1 {
                     addAccount.active = true
                 }
-                addAccount.address = table.address!
                 if table.cameraUpload == 1 {
                     addAccount.cameraUpload = true
                 }
@@ -142,8 +155,12 @@ class NCManageDatabase: NSObject {
                 if table.cameraUploadDateVideo != nil {
                     addAccount.cameraUploadDateVideo = table.cameraUploadDateVideo! as NSDate
                 }
-                addAccount.cameraUploadFolderName = table.cameraUploadFolderName!
-                addAccount.cameraUploadFolderPath = table.cameraUploadFolderPath!
+                if table.cameraUploadFolderName != nil {
+                    addAccount.cameraUploadFolderName = table.cameraUploadFolderName!
+                }
+                if table.cameraUploadFolderPath != nil {
+                    addAccount.cameraUploadFolderPath = table.cameraUploadFolderPath!
+                }
                 if table.cameraUploadFull == 1 {
                     addAccount.cameraUploadFull = true
                 }