Skip to content

Commit d974128

Browse files
committed
Allowing to re-save installation if LDS is enabled
1 parent d4974f1 commit d974128

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,13 @@ - (void)updateObjectIdForObject:(PFObject *)object
10001000
oldObjectId:(NSString *)oldObjectId
10011001
newObjectId:(NSString *)newObjectId {
10021002
if (oldObjectId != nil) {
1003-
PFConsistencyAssert([oldObjectId isEqualToString:newObjectId], @"objectIds cannot be changed in offline mode.");
1003+
if ([object isKindOfClass:[PFInstallation class]]
1004+
&& newObjectId == nil) {
1005+
NSString *key = [self _generateKeyForClassName:object.parseClassName objectId:oldObjectId];
1006+
[self.classNameAndObjectIdToObjectMap removeObjectForKey:key];
1007+
} else {
1008+
PFConsistencyAssert([oldObjectId isEqualToString:newObjectId], @"objectIds cannot be changed in offline mode.");
1009+
}
10041010
return;
10051011
}
10061012

Parse/PFInstallation.m

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#import "PFQueryPrivate.h"
2929
#import "Parse_Private.h"
3030
#import "PFErrorUtilities.h"
31+
#import "PFObjectState_Private.h"
3132

3233
@implementation PFInstallation (Private)
3334

@@ -83,6 +84,14 @@ - (NSString *)displayClassName {
8384
return NSStringFromClass([PFInstallation class]);
8485
}
8586

87+
///--------------------------------------
88+
#pragma mark - Properties
89+
///--------------------------------------
90+
91+
- (void) setObjectId:(NSString *)objectId {
92+
PFParameterAssertionFailure(@"Installation's objectIds cannot be changed");
93+
}
94+
8695
///--------------------------------------
8796
#pragma mark - Command Handlers
8897
///--------------------------------------
@@ -223,16 +232,13 @@ - (void)setChannels:(NSArray<NSString *> *)channels {
223232

224233
- (BFTask *)saveAsync:(BFTask *)toAwait {
225234
return [[super saveAsync:toAwait] continueWithBlock:^id(BFTask *task) {
226-
// Do not attempt to resave an object if LDS is enabled, since changing objectId is not allowed.
227-
if ([Parse _currentManager].offlineStoreLoaded) {
228-
return task;
229-
}
230-
231235
if (task.error.code == kPFErrorObjectNotFound) {
232236
@synchronized (self.lock) {
233237
// Retry the fetch as a save operation because this Installation was deleted on the server.
234238
// We always want [currentInstallation save] to succeed.
235-
self.objectId = nil;
239+
PFObjectState *state = [PFObjectState stateWithState:self._state];
240+
state.objectId = nil;
241+
self._state = state;
236242
[self _markAllFieldsDirty];
237243
return [super saveAsync:nil];
238244
}

0 commit comments

Comments
 (0)