Skip to content

Commit 2bb2ede

Browse files
committed
Merge pull request #267 from ParsePlatform/nlutsenko.installation
Fixed PFInstallation not updating automatic fields when using PFObject.saveAll().
2 parents 2882c8e + 6522ff3 commit 2bb2ede

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

Parse/Internal/Object/PFObjectPrivate.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
@protocol PFObjectPrivateSubclass <NSObject>
4040

41+
@required
42+
4143
///--------------------------------------
4244
/// @name State
4345
///--------------------------------------
@@ -58,6 +60,18 @@
5860
*/
5961
- (BFTask *)_validateSaveEventuallyAsync;
6062

63+
@optional
64+
65+
///--------------------------------------
66+
/// @name Before Save
67+
///--------------------------------------
68+
69+
/*!
70+
Called before an object is going to be saved. Called in a context of object lock.
71+
Subclasses can override this method to do any custom updates before an object gets saved.
72+
*/
73+
- (void)_objectWillSave;
74+
6175
@end
6276

6377
///--------------------------------------

Parse/PFInstallation.m

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,6 @@ - (void)setChannels:(NSArray *)channels {
214214
#pragma mark - PFObject
215215
///--------------------------------------
216216

217-
- (BFTask *)saveInBackground {
218-
[self _updateAutomaticInfo];
219-
return [super saveInBackground];
220-
}
221-
222-
- (BFTask *)_enqueueSaveEventuallyWithChildren:(BOOL)saveChildren {
223-
[self _updateAutomaticInfo];
224-
return [super _enqueueSaveEventuallyWithChildren:saveChildren];
225-
}
226-
227-
- (BFTask *)saveEventually {
228-
[self _updateAutomaticInfo];
229-
return [super saveEventually];
230-
}
231-
232217
- (BFTask *)saveAsync:(BFTask *)toAwait {
233218
return [[super saveAsync:toAwait] continueWithBlock:^id(BFTask *task) {
234219
// Do not attempt to resave an object if LDS is enabled, since changing objectId is not allowed.
@@ -257,7 +242,7 @@ - (BOOL)needsDefaultACL {
257242
#pragma mark - Automatic Info
258243
///--------------------------------------
259244

260-
- (void)_updateAutomaticInfo {
245+
- (void)_objectWillSave {
261246
if ([self _isCurrentInstallation]) {
262247
@synchronized(self.lock) {
263248
[self _updateTimeZoneFromDevice];

Parse/PFObject.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ + (BFTask *)_deepSaveAsync:(id)object withCurrentUser:(PFUser *)currentUser sess
476476
for (PFObject *object in objectBatch) {
477477
PFRESTCommand *command = nil;
478478
@synchronized ([object lock]) {
479+
[object _objectWillSave];
479480
[object _checkSaveParametersWithCurrentUser:currentUser];
480481
command = [object _constructSaveCommandForChanges:[object unsavedChanges]
481482
sessionToken:sessionToken
@@ -1148,6 +1149,7 @@ - (BFTask *)_enqueueSaveEventuallyWithChildren:(BOOL)saveChildren {
11481149
return [self _validateSaveEventuallyAsync];
11491150
}] continueWithSuccessBlock:^id(BFTask *task) {
11501151
@synchronized (lock) {
1152+
[self _objectWillSave];
11511153
if (![self isDirty:NO]) {
11521154
return [BFTask taskWithResult:@YES];
11531155
}
@@ -1484,6 +1486,8 @@ - (BFTask *)saveAsync:(BFTask *)toAwait {
14841486
return [BFTask taskWithResult:@YES];
14851487
}
14861488

1489+
[self _objectWillSave];
1490+
14871491
// Snapshot the current set of changes, and push a new changeset into the queue.
14881492
PFOperationSet *changes = [self unsavedChanges];
14891493

@@ -1799,6 +1803,12 @@ - (BFTask *)_validateSaveEventuallyAsync {
17991803
return [BFTask taskWithResult:nil];
18001804
}
18011805

1806+
#pragma mark Object Will Save
1807+
1808+
- (void)_objectWillSave {
1809+
// Do nothing.
1810+
}
1811+
18021812
///--------------------------------------
18031813
#pragma mark - Properties
18041814
///--------------------------------------

0 commit comments

Comments
 (0)