Hi,
I'm having a couple of conflicts in my documents and I thought I was
handling it properly, but it seems like I'm not able to get rid of the
conflicted documents. I've implemented the recommended code as follows. I'm
wondering if I've done something wrong?
- (BOOL)mergeConflictedDocument:(CBLDocument *)doc {
NSError* error;
NSArray* conflicts = [doc getConflictingRevisions: &error];
if (conflicts.count > 1) {
// There is more than one current revision, thus a conflict!
[self.couchDatabase inTransaction: ^BOOL{
// Come up with a merged/resolved document in some
way that's
// appropriate for the app. You could even just pick
the body of
// one of the revisions.
NSDictionary* mergedProps = [self mergeRevisions:
conflicts];
// Delete the conflicting revisions to get rid of
the conflict:
CBLSavedRevision* current = doc.currentRevision;
for (CBLSavedRevision* rev in conflicts) {
CBLUnsavedRevision *newRev = [rev
createRevision];
if (rev == current) {
// add the merged revision
newRev.properties = [
NSMutableDictionary dictionaryWithDictionary: mergedProps];
for (CBLAttachment *attachment in
rev.attachments) {
[newRev setAttachmentNamed:
attachment.name
withContentType:
attachment.contentType
content:
attachment.content];
}
} else {
// mark other conflicts as deleted
newRev.isDeletion = YES;
}
// saveAllowingConflict allows 'rev' to be
updated even if it
// is not the document's current revision.
NSError *error = nil;
if (![newRev saveAllowingConflict: &error])
{
TFFLog(@"Error saving conflicted
document: %@", error);
return NO;
}
}
return YES;
}];
}
return YES;
}
What's happening is even though the newRev.isDeletion is getting set and
saveAllowingConflict is saving without an error, the conflict just doesn't
seem to go away.
Just wondering if there's something else I should be implementing here to
solve this problem?
Thanks!
Brendan
--
You received this message because you are subscribed to the Google Groups
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/mobile-couchbase/2ec0b84a-8eb2-479c-add8-720c37a58a08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.