Marino Faggiana 6 năm trước cách đây
mục cha
commit
4a377764bf
2 tập tin đã thay đổi với 42 bổ sung0 xóa
  1. 24 0
      iOSClient/AppDelegate.m
  2. 18 0
      iOSClient/Database/NCManageDatabase.swift

+ 24 - 0
iOSClient/AppDelegate.m

@@ -1596,6 +1596,30 @@
         [[NCManageDatabase sharedInstance] setClearAllDateReadDirectory];
     }
     
+    if (([actualVersion compare:@"2.22.0" options:NSNumericSearch] == NSOrderedAscending)) {
+     
+        NSArray *records = [[NCManageDatabase sharedInstance] getTableLocalFilesWithPredicate:[NSPredicate predicateWithFormat:@"size > 0"] sorted:@"account" ascending:NO];
+        
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
+            
+            NSString *account = @"";
+            NSString *directoryUser = @"";
+            NSString *fileName;
+            
+            for (tableLocalFile *record in records) {
+                if (![account isEqualToString:record.account]) {
+                    tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ ", record.account]];
+                    if (tableAccount)
+                        directoryUser = [CCUtility getDirectoryActiveUser:tableAccount.account activeUrl:tableAccount.url];
+                }
+                fileName = [NSString stringWithFormat:@"%@/%@", directoryUser, record.fileName];
+                if (![directoryUser isEqualToString:@""] && [[NSFileManager defaultManager] fileExistsAtPath:fileName]) {
+                    [CCUtility moveFileAtPath:fileName toPath:[CCUtility getDirectoryProviderStorageFileID:record.fileID fileName:record.fileName]];
+                }
+            }
+        });
+    }
+    
     return YES;
 }
 

+ 18 - 0
iOSClient/Database/NCManageDatabase.swift

@@ -1499,6 +1499,24 @@ class NCManageDatabase: NSObject {
 
         return tableLocalFile.init(value: result)
     }
+    
+    @objc func getTableLocalFiles(predicate: NSPredicate, sorted: String, ascending: Bool) -> [tableLocalFile]? {
+        
+        guard self.getAccountActive() != nil else {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        realm.refresh()
+        
+        let results = realm.objects(tableLocalFile.self).filter(predicate).sorted(byKeyPath: sorted, ascending: ascending)
+        
+        if (results.count > 0) {
+            return Array(results.map { tableLocalFile.init(value:$0) })
+        } else {
+            return nil
+        }
+    }
 
     //MARK: -
     //MARK: Table Metadata