Skip to content

Commit

Permalink
Fixed PFInstallation not updating automatic fields when using PFObjec…
Browse files Browse the repository at this point in the history
…t.saveAll().
  • Loading branch information
nlutsenko committed Sep 16, 2015
1 parent 2882c8e commit 6522ff3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
14 changes: 14 additions & 0 deletions Parse/Internal/Object/PFObjectPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

@protocol PFObjectPrivateSubclass <NSObject>

@required

///--------------------------------------
/// @name State
///--------------------------------------
Expand All @@ -58,6 +60,18 @@
*/
- (BFTask *)_validateSaveEventuallyAsync;

@optional

///--------------------------------------
/// @name Before Save
///--------------------------------------

/*!
Called before an object is going to be saved. Called in a context of object lock.
Subclasses can override this method to do any custom updates before an object gets saved.
*/
- (void)_objectWillSave;

@end

///--------------------------------------
Expand Down
17 changes: 1 addition & 16 deletions Parse/PFInstallation.m
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,6 @@ - (void)setChannels:(NSArray *)channels {
#pragma mark - PFObject
///--------------------------------------

- (BFTask *)saveInBackground {
[self _updateAutomaticInfo];
return [super saveInBackground];
}

- (BFTask *)_enqueueSaveEventuallyWithChildren:(BOOL)saveChildren {
[self _updateAutomaticInfo];
return [super _enqueueSaveEventuallyWithChildren:saveChildren];
}

- (BFTask *)saveEventually {
[self _updateAutomaticInfo];
return [super saveEventually];
}

- (BFTask *)saveAsync:(BFTask *)toAwait {
return [[super saveAsync:toAwait] continueWithBlock:^id(BFTask *task) {
// Do not attempt to resave an object if LDS is enabled, since changing objectId is not allowed.
Expand Down Expand Up @@ -257,7 +242,7 @@ - (BOOL)needsDefaultACL {
#pragma mark - Automatic Info
///--------------------------------------

- (void)_updateAutomaticInfo {
- (void)_objectWillSave {
if ([self _isCurrentInstallation]) {
@synchronized(self.lock) {
[self _updateTimeZoneFromDevice];
Expand Down
10 changes: 10 additions & 0 deletions Parse/PFObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ + (BFTask *)_deepSaveAsync:(id)object withCurrentUser:(PFUser *)currentUser sess
for (PFObject *object in objectBatch) {
PFRESTCommand *command = nil;
@synchronized ([object lock]) {
[object _objectWillSave];
[object _checkSaveParametersWithCurrentUser:currentUser];
command = [object _constructSaveCommandForChanges:[object unsavedChanges]
sessionToken:sessionToken
Expand Down Expand Up @@ -1148,6 +1149,7 @@ - (BFTask *)_enqueueSaveEventuallyWithChildren:(BOOL)saveChildren {
return [self _validateSaveEventuallyAsync];
}] continueWithSuccessBlock:^id(BFTask *task) {
@synchronized (lock) {
[self _objectWillSave];
if (![self isDirty:NO]) {
return [BFTask taskWithResult:@YES];
}
Expand Down Expand Up @@ -1484,6 +1486,8 @@ - (BFTask *)saveAsync:(BFTask *)toAwait {
return [BFTask taskWithResult:@YES];
}

[self _objectWillSave];

// Snapshot the current set of changes, and push a new changeset into the queue.
PFOperationSet *changes = [self unsavedChanges];

Expand Down Expand Up @@ -1799,6 +1803,12 @@ - (BFTask *)_validateSaveEventuallyAsync {
return [BFTask taskWithResult:nil];
}

#pragma mark Object Will Save

- (void)_objectWillSave {
// Do nothing.
}

///--------------------------------------
#pragma mark - Properties
///--------------------------------------
Expand Down

0 comments on commit 6522ff3

Please sign in to comment.