Commit b5703964 authored by Nicolas Delaby's avatar Nicolas Delaby

clean code

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15520 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f4d60091
...@@ -688,7 +688,7 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -688,7 +688,7 @@ class XMLSyncUtilsMixin(SyncCode):
if object is not None, this usually means we want to set the if object is not None, this usually means we want to set the
actual xupdate on the signature. actual xupdate on the signature.
""" """
#LOG('getSyncMLData starting...',0,'') #LOG('\ngetSyncMLData starting...',0, domain.getId())
if isinstance(conduit, str): if isinstance(conduit, str):
conduit = self.getConduitByName(conduit) conduit = self.getConduitByName(conduit)
local_gid_list = [] local_gid_list = []
...@@ -705,7 +705,7 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -705,7 +705,7 @@ class XMLSyncUtilsMixin(SyncCode):
# Objects to remove # Objects to remove
#LOG('remove object to remove ...',0,'') #LOG('remove object to remove ...',0,'')
for object_gid in subscriber.getGidList(): for object_gid in subscriber.getGidList():
if not (object_gid in local_gid_list): if object_gid not in local_gid_list:
# This is an object to remove # This is an object to remove
signature = subscriber.getSignatureFromGid(object_gid) signature = subscriber.getSignatureFromGid(object_gid)
if signature.getStatus()!=self.PARTIAL: # If partial, then we have a signature if signature.getStatus()!=self.PARTIAL: # If partial, then we have a signature
...@@ -719,7 +719,10 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -719,7 +719,10 @@ class XMLSyncUtilsMixin(SyncCode):
syncml_data += self.deleteXMLObject(xml_object=signature.getXML()\ syncml_data += self.deleteXMLObject(xml_object=signature.getXML()\
or '', object_gid=object_gid,cmd_id=cmd_id) or '', object_gid=object_gid,cmd_id=cmd_id)
cmd_id += 1 cmd_id += 1
#delete Signature if object does not exist anymore
for known_gid in subscriber.getGidList():
if known_gid not in local_gid_list:
subscriber.delSignature(known_gid)
local_gid_list = [] local_gid_list = []
loop = 0 loop = 0
for object_path in subscriber.getRemainingObjectPathList(): for object_path in subscriber.getRemainingObjectPathList():
...@@ -737,26 +740,27 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -737,26 +740,27 @@ class XMLSyncUtilsMixin(SyncCode):
if syncml_data.count('\n') < self.MAX_LINES and not \ if syncml_data.count('\n') < self.MAX_LINES and not \
object.id.startswith('.'): object.id.startswith('.'):
# If not we have to cut # If not we have to cut
#LOG('getSyncMLData',0,'xml_mapping: %s' % str(domain.xml_mapping)) #LOG('getSyncMLData',0,'object_path: %s' % '/'.join(object_path))
#LOG('getSyncMLData',0,'xml_mapping: %s' % str(domain.getXMLMapping()))
#LOG('getSyncMLData',0,'code: %s' % str(self.getAlertCode(remote_xml))) #LOG('getSyncMLData',0,'code: %s' % str(self.getAlertCode(remote_xml)))
#LOG('getSyncMLData',0,'gid_list: %s' % str(local_gid_list)) #LOG('getSyncMLData',0,'gid_list: %s' % str(local_gid_list))
#LOG('getSyncMLData',0,'subscriber.getGidList: %s' % subscriber.getGidList()) #LOG('getSyncMLData',0,'subscriber.getGidList: %s' % subscriber.getGidList())
#LOG('getSyncMLData',0,'hasSignature: %s' % str(subscriber.hasSignature(object_gid))) #LOG('getSyncMLData',0,'hasSignature: %s' % str(subscriber.hasSignature(object_gid)))
#LOG('getSyncMLData',0,'alert_code == slowsync: %s' % str(self.getAlertCode(remote_xml)==self.SLOW_SYNC)) #LOG('getSyncMLData',0,'alert_code == slowsync: %s' % str(self.getAlertCode(remote_xml)==self.SLOW_SYNC))
signature = subscriber.getSignatureFromGid(object_gid)
# Here we first check if the object was modified or not by looking at dates signature = subscriber.getSignatureFromGid(object_gid)
if signature is not None: ## Here we first check if the object was modified or not by looking at dates
signature.checkSynchronizationNeeded(object) #if signature is not None:
#LOG('getSyncMLData',0,'signature.getStatus: %s' % signature.getStatus())
status = self.SENT status = self.SENT
more_data=0 more_data=0
# For the case it was never synchronized, we have to send everything # For the case it was never synchronized, we have to send everything
if signature is not None and signature.getXMLMapping()==None: if signature is not None and signature.getXMLMapping() is None:
pass pass
elif signature == None or (signature.getXML() == None and \ elif signature is None or (signature.getXML() is None and \
signature.getStatus() != self.PARTIAL) or \ signature.getStatus() != self.PARTIAL) or \
self.getAlertCode(remote_xml) == self.SLOW_SYNC: self.getAlertCode(remote_xml) == self.SLOW_SYNC:
#LOG('PubSyncModif',0,'Current object.getPath: %s' % object.getPath()) #LOG('getSyncMLData',0,'Current object.getPath: %s' % object.getPath())
xml_object = domain.getXMLFromObject(object) xml_object = domain.getXMLFromObject(object)
xml_string = xml_object xml_string = xml_object
if isinstance(xml_string, unicode): if isinstance(xml_string, unicode):
...@@ -783,8 +787,8 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -783,8 +787,8 @@ class XMLSyncUtilsMixin(SyncCode):
gid = signature.getRid()#in fisrt, we try with rid if there is one gid = signature.getRid()#in fisrt, we try with rid if there is one
if gid == None: if gid == None:
gid = signature.getGid() gid = signature.getGid()
syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object, syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object,
gid=gid, xml_string=xml_string, gid=gid, xml_string=xml_string,
more_data=more_data, media_type=subscriber.getMediaType()) more_data=more_data, media_type=subscriber.getMediaType())
cmd_id += 1 cmd_id += 1
signature.setStatus(status) signature.setStatus(status)
...@@ -890,8 +894,8 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -890,8 +894,8 @@ class XMLSyncUtilsMixin(SyncCode):
gid = signature.getRid()#in fisrt, we try with rid if there is one gid = signature.getRid()#in fisrt, we try with rid if there is one
if gid == None: if gid == None:
gid = signature.getGid() gid = signature.getGid()
syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object, syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object,
gid=gid, xml_string=xml_string, gid=gid, xml_string=xml_string,
more_data=more_data, media_type=subscriber.getMediaType()) more_data=more_data, media_type=subscriber.getMediaType())
if not more_data: if not more_data:
subscriber.removeRemainingObjectPath(object_path) subscriber.removeRemainingObjectPath(object_path)
...@@ -929,17 +933,17 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -929,17 +933,17 @@ class XMLSyncUtilsMixin(SyncCode):
gid=rid gid=rid
object_id = domain.generateNewIdWithGenerator(object=destination,gid=gid) object_id = domain.generateNewIdWithGenerator(object=destination,gid=gid)
signature = subscriber.getSignatureFromGid(gid) signature = subscriber.getSignatureFromGid(gid)
if signature != None and rid != gid: if signature is not None and rid != gid:
#in this case, the object was created on another subscriber than erp5 #in this case, the object was created on another subscriber than erp5
# and we should save it's remote id # and we should save it's remote id
signature.setRid(rid) signature.setRid(rid)
#LOG('gid == rid ?', 0, 'gid=%s, rid=%s' % (gid, rid)) #LOG('gid == rid ?', 0, 'gid=%s, rid=%s' % (gid, rid))
object = subscriber.getObjectFromGid(gid) object = subscriber.getObjectFromGid(gid)
#LOG('applyActionList subscriber.getObjectFromGid %s' % gid,0,object) #LOG('applyActionList subscriber.getObjectFromGid %s' % gid,0,object)
if signature == None: if signature is None:
#LOG('applyActionList, signature is None',0,signature) #LOG('applyActionList, signature is None',0,signature)
if gid == rid: if gid == rid:
signature = Signature(id=gid, status=self.NOT_SYNCHRONIZED, signature = Signature(id=gid, status=self.NOT_SYNCHRONIZED,
object=object).__of__(subscriber) object=object).__of__(subscriber)
else: else:
signature = Signature(rid=rid, id=gid, status=self.NOT_SYNCHRONIZED, signature = Signature(rid=rid, id=gid, status=self.NOT_SYNCHRONIZED,
...@@ -1047,6 +1051,7 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -1047,6 +1051,7 @@ class XMLSyncUtilsMixin(SyncCode):
elif action.nodeName == 'Delete': elif action.nodeName == 'Delete':
object_id = signature.getId() object_id = signature.getId()
#LOG('Delete on : ',0, (signature.getId(), subscriber.getObjectFromGid(object_id)))
if subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']: if subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']:
data_subnode = self.getDataText(action) data_subnode = self.getDataText(action)
else: else:
...@@ -1121,10 +1126,9 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -1121,10 +1126,9 @@ class XMLSyncUtilsMixin(SyncCode):
signature.setStatus(self.SYNCHRONIZED) signature.setStatus(self.SYNCHRONIZED)
elif status_cmd == 'Delete': elif status_cmd == 'Delete':
if status_code == self.SUCCESS: if status_code == self.SUCCESS:
signature = subscriber.getSignatureFromGid(object_gid) signature = subscriber.getSignatureFromGid(object_gid) or subscriber.getSignatureFromRid(object_gid)
if signature == None: if signature is not None:
signature = subscriber.getSignatureFromRid(object_gid) subscriber.delSignature(signature.getGid())
subscriber.delSignature(signature.getGid())
return (destination_waiting_more_data, has_status_list) return (destination_waiting_more_data, has_status_list)
......
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