Commit dce9bcd2 authored by Aurel's avatar Aurel

implement deletion checking using SQL

parent bda033fe
...@@ -220,7 +220,6 @@ class SyncMLSubscription(XMLObject): ...@@ -220,7 +220,6 @@ class SyncMLSubscription(XMLObject):
# Build Message # Build Message
if response_message_id: if response_message_id:
syncml_response = self.generateBaseResponse() syncml_response = self.generateBaseResponse()
syncml_response.addBody()
else: else:
syncml_response = None syncml_response = None
...@@ -637,7 +636,6 @@ class SyncMLSubscription(XMLObject): ...@@ -637,7 +636,6 @@ class SyncMLSubscription(XMLObject):
the "sending_modification" stage of the synchronization the "sending_modification" stage of the synchronization
""" """
syncml_response = self.generateBaseResponse() syncml_response = self.generateBaseResponse()
syncml_response.addBody()
syncml_response.addFinal() syncml_response.addFinal()
final_activate_kw = { final_activate_kw = {
...@@ -651,6 +649,37 @@ class SyncMLSubscription(XMLObject): ...@@ -651,6 +649,37 @@ class SyncMLSubscription(XMLObject):
self.activate(**final_activate_kw).sendMessage(xml=str(syncml_response)) self.activate(**final_activate_kw).sendMessage(xml=str(syncml_response))
def getDeletedSyncMLData(self, syncml_response=None):
"""
Retrieve & generate the syncml message for messages that were deleted
This message also contains the final tag to let know that the sending
of modification is over
"""
if not syncml_response:
syncml_response = self.generateBaseResponse()
# Compare gid between signature & source to know which data were deleted
deleted_signature_set = self.z_get_syncml_deleted_gid_list(
signature_path=self.getSearchablePath(),
source_path=self.getSearchableSourcePath())
syncml_logger.info("\t---> delete signature are %r" % (len(deleted_signature_set)))
for r in deleted_signature_set:
syncml_response.addDeleteCommand(gid=r.gid)
syncml_logger.info("\t\t---> %r" % (r.gid))
syncml_response.addFinal()
# Now send the message
final_activate_kw = {
'after_method_id' : ("processServerSynchronization",
"processClientSynchronization"),
'priority' :ACTIVITY_PRIORITY + 1,
'tag' : "%s_delete" %(self.getRelativeUrl(),)
}
syncml_logger.info("Sending final message for modificationson on %s"
% (self.getRelativeUrl(),))
self.activate(**final_activate_kw).sendMessage(xml=str(syncml_response))
def getSearchablePath(self): def getSearchablePath(self):
return "%s%%" %(self.getPath().replace('_', '\_'),) return "%s%%" %(self.getPath().replace('_', '\_'),)
...@@ -668,40 +697,13 @@ class SyncMLSubscription(XMLObject): ...@@ -668,40 +697,13 @@ class SyncMLSubscription(XMLObject):
finished = True finished = True
conduit = self.getConduit() conduit = self.getConduit()
portal = self.getPortalObject()
traverse = portal.restrictedTraverse
# Compare gid list to know which data were deleted # Check deletion now ?
source_gid_list = [x.gid for x in self.z_get_syncml_gid_list( if portal.portal_preferences.getPreferredCheckDeleteAtEnd() is False:
strict_min_gid=None, raise NotImplementedError
min_gid=min_gid,
max_gid=max_gid,
path =self.getSearchableSourcePath(),
limit=None)]
src = self.z_get_syncml_gid_list(
src__=1,
strict_min_gid=None,
min_gid=min_gid,
max_gid=max_gid,
path = self.getSearchablePath(),
limit=None)
syncml_logger.info("source %r" % (src,))
signature_list = [x.gid for x in self.z_get_syncml_gid_list(
strict_min_gid=None,
min_gid=min_gid,
max_gid=max_gid,
path = self.getSearchablePath(),
limit=None)]
signature_set = set(signature_list)
source_gid_set = set(source_gid_list) # XXX get it with mysql
deleted_signature_set = signature_set - source_gid_set
syncml_logger.info("\t---> delete signature are %r from %r - %r"
% (deleted_signature_set, signature_set, source_gid_set))
for gid in deleted_signature_set:
syncml_response.addDeleteCommand(gid=gid)
traverse = self.getPortalObject().restrictedTraverse
object_list = [traverse(x.path) for x in self.z_get_syncml_path_list( object_list = [traverse(x.path) for x in self.z_get_syncml_path_list(
min_gid=min_gid, min_gid=min_gid,
max_gid=max_gid, max_gid=max_gid,
...@@ -1170,7 +1172,6 @@ class SyncMLSubscription(XMLObject): ...@@ -1170,7 +1172,6 @@ class SyncMLSubscription(XMLObject):
conflict_list.extend(signature.getConflictList()) conflict_list.extend(signature.getConflictList())
return conflict_list return conflict_list
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'indexSourceData') 'indexSourceData')
def indexSourceData(self, client=False): def indexSourceData(self, client=False):
...@@ -1178,6 +1179,8 @@ class SyncMLSubscription(XMLObject): ...@@ -1178,6 +1179,8 @@ class SyncMLSubscription(XMLObject):
Index source data into mysql for ensemble comparison Index source data into mysql for ensemble comparison
This depends on synchronization type This depends on synchronization type
""" """
# XXX Must check & index signature also (check lenght of BTree against
# lenght of data in sql
if (client and self.getSyncmlAlertCode() not in \ if (client and self.getSyncmlAlertCode() not in \
("one_way_from_server", "refresh_from_server_only")) or \ ("one_way_from_server", "refresh_from_server_only")) or \
(not client and self.getSyncmlAlertCode() not in \ (not client and self.getSyncmlAlertCode() not in \
......
...@@ -261,8 +261,12 @@ class SyncMLAsynchronousEngine(EngineMixin): ...@@ -261,8 +261,12 @@ class SyncMLAsynchronousEngine(EngineMixin):
activity_count=pref.getPreferredRetrievalActivityCount(), activity_count=pref.getPreferredRetrievalActivityCount(),
) )
# then send the final message of this sync part # then send the final message of this sync part
subscription.activate(after_tag=tag, if pref.getPreferredCheckDeleteAtEnd():
priority=ACTIVITY_PRIORITY+1)._sendFinalMessage() subscription.activate(after_tag=tag,
priority=ACTIVITY_PRIORITY+1).getDeletedSyncMLData()
else:
subscription.activate(after_tag=tag,
priority=ACTIVITY_PRIORITY+1)._sendFinalMessage()
return True return True
......
...@@ -86,9 +86,7 @@ class SyncMLSynchronousEngine(EngineMixin): ...@@ -86,9 +86,7 @@ class SyncMLSynchronousEngine(EngineMixin):
syncml_logger.info("-> Client sendind modification, finished %s" % (finished,)) syncml_logger.info("-> Client sendind modification, finished %s" % (finished,))
if finished: if finished:
# Add deleted objets # Add deleted objets
#subscription._getDeletedData(syncml_response=syncml_response) subscription.getDeletedSyncMLData(syncml_response=syncml_response)
# Notify that all modifications were sent
syncml_response.addFinal()
# Will then start processing sync commands from server # Will then start processing sync commands from server
subscription.processSyncRequest() subscription.processSyncRequest()
...@@ -207,8 +205,7 @@ class SyncMLSynchronousEngine(EngineMixin): ...@@ -207,8 +205,7 @@ class SyncMLSynchronousEngine(EngineMixin):
min_gid=None, max_gid=None) min_gid=None, max_gid=None)
syncml_logger.info("-> Server sendind data, finished %s" % (finished,)) syncml_logger.info("-> Server sendind data, finished %s" % (finished,))
if finished: if finished:
#subscriber._getDeletedData(syncml_response=syncml_response) subscriber.getDeletedSyncMLData(syncml_response=syncml_response)
syncml_response.addFinal()
subscriber.waitNotifications() subscriber.waitNotifications()
# Do not go into finished here as we must wait for # Do not go into finished here as we must wait for
# notifications from client # notifications from client
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment