diff --git a/product/ERP5SyncML/Subscription.py b/product/ERP5SyncML/Subscription.py index 4b7d7bf91211bc089886537fe62fa30eb9c3cda5..be31619a6469010a3e623e8951d0380c21c0cfc2 100755 --- a/product/ERP5SyncML/Subscription.py +++ b/product/ERP5SyncML/Subscription.py @@ -213,7 +213,7 @@ class Conflict(SyncCode, Base): """ return self.keyword -class Signature(SyncCode,Folder): +class Signature(Folder,SyncCode): """ status -- SENT, CONFLICT... md5_object -- An MD5 value of a given document @@ -262,6 +262,7 @@ class Signature(SyncCode,Folder): # XXX This may be a problem, if the document is changed # during a synchronization self.setLastSynchronizationDate(DateTime()) + self.getParent().removeRemainingObject(self.getObject()) if status == self.NOT_SYNCHRONIZED: self.setTempXML(None) self.setPartialXML(None) @@ -497,10 +498,15 @@ class Signature(SyncCode,Folder): else: self.resetConflictList() + def getObject(self): + """ + Returns the object corresponding to this signature + """ + return self.getParent().getObjectFromGid(self.getGid()) + def addSubscription( self, id, title='', REQUEST=None ): """ - Add a new Category and generate UID by calling the - ZSQLCatalog + Add a new Subscribption """ o = Subscription( id ,'','','','','','') self._setObject( id, o ) @@ -509,7 +515,8 @@ def addSubscription( self, id, title='', REQUEST=None ): return o #class Subscription(SyncCode, Implicit): -class Subscription(SyncCode, Implicit, Folder): +#class Subscription(Folder, SyncCode, Implicit, Folder, Impli): +class Subscription(Folder, SyncCode): """ Subscription hold the definition of a master ODB from/to which a selection of objects will be synchronised @@ -960,6 +967,8 @@ class Subscription(SyncCode, Implicit, Folder): o = None if gid in self.objectIds(): o = self._getOb(gid) + #if o is not None: + # return o.__of__(self) return o def getSignatureList(self): @@ -998,6 +1007,47 @@ class Subscription(SyncCode, Implicit, Folder): conflict_list += signature.getConflictList() return conflict_list + def getRemainingObjectList(self): + """ + We should now wich objects should still + synchronize + """ + return getattr(self,'remaining_object_list',None) + + def setRemainingObjectList(self, value): + """ + We should now wich objects should still + synchronize + """ + setattr(self,'remaining_object_list',value) + + def removeRemainingObject(self, object): + """ + We should now wich objects should still + synchronize + """ + remaining_object_list = self.getRemainingObjectList() + if remaining_object_list is not None: + new_list = [] + for o in remaining_object_list: + if o != object: + new_list.append(o) + self.setRemainingObjectList(new_list) + +# def getCurrentObject(self): +# """ +# When we send some partial data, then we should +# always synchronize the same object until it is finished +# """ +# getattr(self,'current_object',None) +# +# def setCurrentObject(self,object): +# """ +# When we send some partial data, then we should +# always synchronize the same object until it is finished +# """ +# setattr(self,'current_object',object) + def startSynchronization(self): """ Set the status of every object as NOT_SYNCHRONIZED @@ -1009,3 +1059,4 @@ class Subscription(SyncCode, Implicit, Folder): o.setStatus(self.NOT_SYNCHRONIZED) o.setPartialXML(None) o.setTempXML(None) + self.setRemainingObjectList(None) diff --git a/product/ERP5SyncML/SynchronizationTool.py b/product/ERP5SyncML/SynchronizationTool.py index eea00b21ce8f876962ef63380c44cedb232a4553..f0fc552eb4709e4db7b528486cdfdb215a1646fe 100755 --- a/product/ERP5SyncML/SynchronizationTool.py +++ b/product/ERP5SyncML/SynchronizationTool.py @@ -874,11 +874,24 @@ class SynchronizationTool( SubscriptionSynchronization, PublicationSynchronizati """ return 'sub_' + title - - - - - +# security.declarePrivate('notify_sync') +# def notify_sync(self, event_type, object, infos): +# """Notification from the event service. +# +# # XXX very specific to cps +# +# Called when an object is added/deleted/modified. +# Update the date of sync +# """ +# from Products.CPSCore.utils import _isinstance +# from Products.CPSCore.ProxyBase import ProxyBase +# +# if event_type in ('sys_modify_object', +# 'modify_object'): +# if not(_isinstance(object, ProxyBase)): +# repotool = getToolByName(self, 'portal_repository') +# if repotool.isObjectInRepository(object): +# object_id = object.getId() InitializeClass( SynchronizationTool ) diff --git a/product/ERP5SyncML/XMLSyncUtils.py b/product/ERP5SyncML/XMLSyncUtils.py index ccf6aa7f27dbe27991809773b2be8255bcf068d6..579b94ab054cf9fdfd714a7059ba5debd6cbd7f6 100755 --- a/product/ERP5SyncML/XMLSyncUtils.py +++ b/product/ERP5SyncML/XMLSyncUtils.py @@ -556,7 +556,29 @@ class XMLSyncUtilsMixin(SyncCode): local_gid_list = [] syncml_data = '' - for object in domain.getObjectList(): + if subscriber.getRemainingObjectList() is None: + object_list = domain.getObjectList() + subscriber.setRemainingObjectList(object_list) + + #object_gid = domain.getGidFromObject(object) + local_gid_list = map(lambda x: domain.getGidFromObject(x),object_list) + # Objects to remove + #for object_id in id_list: + for object_gid in subscriber.getGidList(): + if not (object_gid in local_gid_list): + # This is an object to remove + signature = subscriber.getSignature(object_gid) + if signature.getStatus()!=self.PARTIAL: # If partial, then we have a signature + # but no local object + xml_object = signature.getXML() + if xml_object is not None: # This prevent to delete an object that we + # were not able to create + syncml_data += self.deleteXMLObject(xml_object=signature.getXML() or '', + object_gid=object_gid,cmd_id=cmd_id) + + + #for object in domain.getObjectList(): + for object in subscriber.getRemainingObjectList(): status = self.SENT #gid_generator = getattr(object,domain.getGidGenerator(),None) object_gid = domain.getGidFromObject(object) @@ -701,20 +723,6 @@ class XMLSyncUtilsMixin(SyncCode): elif signature.getAction()=='Add': syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object,gid=object_gid, xml_string=xml_string, more_data=more_data) - # Objects to remove - #for object_id in id_list: - for object_gid in subscriber.getGidList(): - if not (object_gid in local_gid_list): - # This is an object to remove - signature = subscriber.getSignature(object_gid) - if signature.getStatus()!=self.PARTIAL: # If partial, then we have a signature - # but no local object - xml_object = signature.getXML() - if xml_object is not None: # This prevent to delete an object that we - # were not able to create - syncml_data += self.deleteXMLObject(xml_object=signature.getXML() or '', - object_gid=object_gid,cmd_id=cmd_id) - return (syncml_data,xml_confirmation,cmd_id) def applyActionList(self, domain=None, subscriber=None,destination_path=None, @@ -736,7 +744,8 @@ class XMLSyncUtilsMixin(SyncCode): object_gid = self.getActionId(next_action) signature = subscriber.getSignature(object_gid) if signature == None: - signature = Signature(gid=object_gid,status=self.NOT_SYNCHRONIZED) + LOG('applyActionList, signature is None',0,signature) + signature = Signature(gid=object_gid,status=self.NOT_SYNCHRONIZED).__of__(subscriber) subscriber.addSignature(signature) force = signature.getForce() object = domain.getObjectFromGid(object_gid)