Marino Faggiana 8 жил өмнө
parent
commit
4fedf4df41

+ 2 - 2
iOSClient/FileSystem/CCCoreData.h

@@ -120,7 +120,7 @@
 
 + (NSArray *)getRecordsTableMetadataPhotosCameraUpload:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
 
-+ (void)changeRevFileIDDB:(NSString *)revFileID revTo:(NSString *)revTo activeAccount:(NSString *)activeAccount;
++ (void)removeOfflineAllFileFromServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
 
 // ===== Directory =====
 
@@ -161,7 +161,7 @@
 + (void)addOffline:(NSString *)fileID activeAccount:(NSString *)activeAccount;
 
 + (void)deleteLocalFileWithPredicate:(NSPredicate *)predicate;
-+ (void)removeOfflineFromFileID:(NSString *)fileID activeAccount:(NSString *)activeAccount;
++ (void)removeOfflineFileID:(NSString *)fileID activeAccount:(NSString *)activeAccount;
 
 + (void)renameLocalFileWithFileID:(NSString *)fileID fileNameTo:(NSString *)fileNameTo fileNamePrintTo:(NSString *)fileNamePrintTo activeAccount:(NSString *)activeAccount;
 + (void)updateLocalFileModel:(CCMetadata *)metadata activeAccount:(NSString *)activeAccount;

+ 15 - 38
iOSClient/FileSystem/CCCoreData.m

@@ -788,43 +788,6 @@
     return [self getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (session == %@) AND ((sessionTaskIdentifier != %i) OR (sessionTaskIdentifierPlist != %i))", activeAccount, upload_session_wwan, taskIdentifierDone, taskIdentifierDone] context:nil];
 }
 
-+ (void)changeRevFileIDDB:(NSString *)revFileID revTo:(NSString *)revTo activeAccount:(NSString *)activeAccount
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    NSPredicate *predicate;
-    
-    // Metadata
-    predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", revFileID, activeAccount];
-    TableMetadata *recordMetadata = [TableMetadata MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (recordMetadata) {
-        
-        TableMetadata *localRecord = [recordMetadata MR_inContext:context];
-            
-        localRecord.fileID = revTo;
-        localRecord.rev = revTo;
-        
-        // Aggiorniamo la data nella directory (ottimizzazione v 2.10)
-        [self setDateReadDirectoryID:recordMetadata.directoryID activeAccount:activeAccount];
-        
-        [context MR_saveToPersistentStoreAndWait];
-    }
-    
-    // File
-    predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", revFileID, activeAccount];
-    TableLocalFile *recordLocalFile = [TableLocalFile MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (recordLocalFile) {
-        
-        TableLocalFile *localRecord = [recordLocalFile MR_inContext:context];
-            
-        localRecord.fileID = revTo;
-        localRecord.rev = revTo;
-        
-        [context MR_saveToPersistentStoreAndWait];
-    }
-}
-
 + (NSArray *)getRecordsTableMetadataPhotosCameraUpload:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
 {
     NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
@@ -856,6 +819,20 @@
     return [recordsPhotosCameraUpload sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];
 }
 
++ (void)removeOfflineAllFileFromServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
+{
+    NSString *directoryID = [self getDirectoryIDFromServerUrl:serverUrl activeAccount:activeAccount];
+    
+    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
+        
+        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", activeAccount, directoryID];
+        NSArray *records = [TableMetadata MR_findAllWithPredicate:predicate];
+        
+        for (TableMetadata *record in records)
+            [self removeOfflineFileID:record.fileID activeAccount:activeAccount];
+    }];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Directory =====
 #pragma --------------------------------------------------------------------------------------------
@@ -1299,7 +1276,7 @@
     }];
 }
 
-+ (void)removeOfflineFromFileID:(NSString *)fileID activeAccount:(NSString *)activeAccount
++ (void)removeOfflineFileID:(NSString *)fileID activeAccount:(NSString *)activeAccount
 {
     [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
         

+ 20 - 1
iOSClient/Main/CCMain.m

@@ -3031,7 +3031,7 @@
 
 - (void)removeOffline:(CCMetadata *)metadata
 {
-    [CCCoreData removeOfflineFromFileID:metadata.fileID activeAccount:app.activeAccount];
+    [CCCoreData removeOfflineFileID:metadata.fileID activeAccount:app.activeAccount];
     
     NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
     if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
@@ -4351,9 +4351,28 @@
                                         } else {
                                             
                                             NSString *dir = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
+                                            NSString *upDir = [CCUtility deletingLastPathComponentFromServerUrl:dir];
+                                            NSString *homeDir = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl typeCloud:app.typeCloud];
                                             
+                                            if (![upDir isEqualToString:homeDir] && [CCCoreData isOfflineDirectory:upDir activeAccount:app.activeAccount]) {
+                                            
+                                                [app messageNotification:@"_info_" description:@"_error_remove_offline_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
+                                                    return;
+                                                    
+                                            }
+                                            
+                                            // remove offline folder
                                             [CCCoreData setOfflineDirectory:dir offline:NO activeAccount:app.activeAccount];
                                             
+                                            // remove all subfolder
+                                            NSArray *directories = [CCCoreData getOfflineDirectoryActiveAccount:app.activeAccount];
+                                            
+                                            for (TableDirectory *directory in directories)
+                                                if ([directory.serverUrl containsString:dir]) {
+                                                    [CCCoreData setOfflineDirectory:directory.serverUrl offline:NO activeAccount:app.activeAccount];
+                                                    [CCCoreData removeOfflineAllFileFromServerUrl:directory.serverUrl activeAccount:app.activeAccount];
+                                                }
+                                            
                                             [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil];
                                         }
                                     }];

+ 1 - 1
iOSClient/Offline/CCOffline.m

@@ -440,7 +440,7 @@
     if ([self.serverUrlLocal isEqualToString:@"Offline"]) {
         
         NSManagedObject *record = [dataSource objectAtIndex:indexPath.row];
-        [CCCoreData removeOfflineFromFileID:[record valueForKey:@"fileID"] activeAccount:app.activeAccount];
+        [CCCoreData removeOfflineFileID:[record valueForKey:@"fileID"] activeAccount:app.activeAccount];
     }
     
     if ([self.serverUrlLocal isEqualToString:@"Offline"] == NO) {

+ 2 - 0
iOSClient/en.lproj/Localizable.strings

@@ -394,6 +394,8 @@
 "_paste_files_encrypted_"       = "Paste encrypted files";
 "_paste_cryptated_"             = "Paste encrypted file";
 
+"_error_remove_offline_"        = "Impossible to remove the offline";
+
 // Security
 
 "_reload_folder_"               = "Please reload folder";