Browse Source

remove record if exists AddMetadata

Marino Faggiana 8 years ago
parent
commit
de9f730818

+ 1 - 1
Share Ext/InfoNextcloud.plist

@@ -21,7 +21,7 @@
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
-	<string>00007</string>
+	<string>00008</string>
 	<key>NSAppTransportSecurity</key>
 	<dict>
 		<key>NSAllowsArbitraryLoads</key>

+ 24 - 5
iOSClient/AppDelegate.m

@@ -392,9 +392,22 @@
 
 - (void)verifyProcess
 {
-    // Verify Synchronized Folder
-    NSMutableArray *metadatasNet = [self verifyExistsInQueuesUploadSelector:selectorDownloadSynchronized];
+    // Not in background
     
+    if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateBackground) {
+    
+        // Verify Synchronized Folder
+        NSMutableArray *metadatasNet = [self verifyExistsInQueuesUploadSelector:selectorDownloadSynchronized];
+    
+        if ([CCCoreData countTableAutomaticUploadForAccount:self.activeAccount selector:selectorUploadAutomatic] > 0)
+            if ([[self verifyExistsInQueuesUploadSelector:selectorUploadAutomatic] count] == 0)
+                [app loadTableAutomaticUploadForSelector:selectorUploadAutomatic];
+    
+        if ([CCCoreData countTableAutomaticUploadForAccount:self.activeAccount selector:selectorUploadAutomaticAll] > 0)
+            if ([[self verifyExistsInQueuesUploadSelector:selectorUploadAutomaticAll] count] == 0)
+                [app loadTableAutomaticUploadForSelector:selectorUploadAutomaticAll];
+
+    }
     //NSLog(@"5 sec. %lu", (unsigned long)[metadatasNet count]);
 }
 
@@ -1058,11 +1071,11 @@
         
         for (OCnetworking *operation in [self.netQueueUpload operations])
             if ([operation.metadataNet.selector isEqualToString:selector])
-                [metadatasNet addObject:operation.metadataNet];
+                [metadatasNet addObject:[operation.metadataNet copy]];
         
         for (OCnetworking *operation in [self.netQueueUploadWWan operations])
             if ([operation.metadataNet.selector isEqualToString:selector])
-                [metadatasNet addObject:operation.metadataNet];
+                [metadatasNet addObject:[operation.metadataNet copy]];
     }
     
 #ifdef CC
@@ -1093,6 +1106,12 @@
     
         NSUInteger count = [TableMetadata MR_countOfEntitiesWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (sessionSelector == %@) AND ((sessionTaskIdentifier == %i) OR (sessionTaskIdentifierPlist == %i))", app.activeAccount, selectorUploadAutomaticAll,taskIdentifierError, taskIdentifierError]];
         
+        /*
+        TableMetadata *record = [TableMetadata MR_findFirstWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (sessionSelector == %@) AND ((sessionTaskIdentifier == %i) OR (sessionTaskIdentifierPlist == %i))", app.activeAccount, selectorUploadAutomaticAll,taskIdentifierError, taskIdentifierError]];
+        
+        CCMetadata *metadata = [CCCoreData insertEntityInMetadata:record];
+        */
+        
         if (count >= 10) {
             
             [app messageNotification:@"_error_" description:@"_too_errors_automatic_all_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
@@ -1103,7 +1122,7 @@
     
     // Add Network queue
     
-    CCMetadataNet *metadataNet = [CCCoreData getTableAutomaticUploadForAccount:self.activeAccount selector:selector delete:YES context:nil];
+    CCMetadataNet *metadataNet = [CCCoreData getTableAutomaticUploadForAccount:self.activeAccount selector:selector context:nil];
     
     if (metadataNet) {
         

+ 1 - 1
iOSClient/FileSystem/CCCoreData.h

@@ -179,7 +179,7 @@
 // ===== Automatic Upload =====
 
 + (void)addTableAutomaticUpload:(CCMetadataNet *)metadataNet account:(NSString *)account context:(NSManagedObjectContext *)context;
-+ (CCMetadataNet *)getTableAutomaticUploadForAccount:(NSString *)account selector:(NSString *)selector delete:(BOOL)delete context:(NSManagedObjectContext *)context;
++ (CCMetadataNet *)getTableAutomaticUploadForAccount:(NSString *)account selector:(NSString *)selector context:(NSManagedObjectContext *)context;
 + (NSUInteger)countTableAutomaticUploadForAccount:(NSString *)account selector:(NSString *)selector;
 
 // ===== GPS =====

+ 7 - 6
iOSClient/FileSystem/CCCoreData.m

@@ -614,6 +614,10 @@
     [TableMetadata MR_deleteAllMatchingPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (fileID == %@)", activeAccount, metadata.fileID] inContext:context];
     [context MR_saveToPersistentStoreAndWait];
     
+    // remove record if exists
+    [TableMetadata MR_deleteAllMatchingPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (fileName == %@) AND (directoryID == %@)", activeAccount, metadata.fileName, metadata.directoryID] inContext:context];
+    [context MR_saveToPersistentStoreAndWait];
+    
     // create new record Metadata
     TableMetadata *record = [TableMetadata MR_createEntityInContext:context];
 
@@ -1497,7 +1501,7 @@
     [context MR_saveToPersistentStoreAndWait];
 }
 
-+ (CCMetadataNet *)getTableAutomaticUploadForAccount:(NSString *)account selector:(NSString *)selector delete:(BOOL)delete context:(NSManagedObjectContext *)context
++ (CCMetadataNet *)getTableAutomaticUploadForAccount:(NSString *)account selector:(NSString *)selector context:(NSManagedObjectContext *)context
 {
     if (context == nil)
         context = [NSManagedObjectContext MR_context];
@@ -1518,11 +1522,8 @@
         metadataNet.session = record.session;
         metadataNet.taskStatus = taskStatusResume;                          // Default
         
-        if (delete) {                                                       // Remove record
-            
-            [record MR_deleteEntityInContext:context];
-            [context MR_saveToPersistentStoreAndWait];
-        }
+        [record MR_deleteEntityInContext:context];                          // Remove record
+        [context MR_saveToPersistentStoreAndWait];
         
         return metadataNet;
     }

+ 1 - 1
iOSClient/InfoPlist/InfoNextcloud.plist

@@ -69,7 +69,7 @@
 		</dict>
 	</array>
 	<key>CFBundleVersion</key>
-	<string>00007</string>
+	<string>00008</string>
 	<key>ITSAppUsesNonExemptEncryption</key>
 	<true/>
 	<key>ITSEncryptionExportComplianceCode</key>

+ 0 - 16
iOSClient/Main/CCMain.m

@@ -319,26 +319,10 @@
         // Initializations
         [app applicationInitialized];
         
-        // restart Automatic Upload
-        [app loadTableAutomaticUploadForSelector:selectorUploadAutomatic];
-        [app loadTableAutomaticUploadForSelector:selectorUploadAutomaticAll];
-        
         // message TestFlight
         if (app.isRunningTestFlight) {
             
-            NSString *messageDebug;
-            
             [app messageNotification:@"_info_" description:@"This version is beta and only fot TestFlight, send report at ios@nextcloud.com" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
-            
-            NSMutableArray *metadatasNet = [app verifyExistsInQueuesUploadSelector:selectorUploadAutomaticAll];
-            CCMetadataNet *metadataNet = [CCCoreData getTableAutomaticUploadForAccount:app.activeAccount selector:selectorUploadAutomaticAll delete:NO context:nil];
-            
-            if ([metadatasNet count] > 0) {
-                
-                messageDebug = [NSString stringWithFormat:@"DEBUG UploadAutomaticAll : %lu - %@", (unsigned long)[metadatasNet count], metadataNet];
-                
-                [app messageNotification:@"_info_" description:messageDebug visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
-            }
         }
         
     } else {