Commit 31d9605f authored by Sebastien Robin's avatar Sebastien Robin

allow to synchronize object from many places


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1865 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 390c50b4
......@@ -239,8 +239,10 @@ class Signature(Folder,SyncCode):
"""
# Constructor
def __init__(self,gid=None, id=None, status=None, xml_string=None):
def __init__(self,gid=None, id=None, status=None, xml_string=None,object=None):
self.setGid(gid)
if object is not None:
self.setPath(object.getPhysicalPath())
self.setId(id)
self.status = status
self.setXML(xml_string)
......@@ -275,7 +277,7 @@ class Signature(Folder,SyncCode):
# XXX This may be a problem, if the document is changed
# during a synchronization
self.setLastSynchronizationDate(DateTime())
self.getParent().removeRemainingObjectId(self.getId())
self.getParent().removeRemainingObjectPath(self.getPath())
if status == self.NOT_SYNCHRONIZED:
self.setTempXML(None)
self.setPartialXML(None)
......@@ -289,6 +291,18 @@ class Signature(Folder,SyncCode):
"""
return self.status
def getPath(self):
"""
get the force value (if we need to force update or not)
"""
return getattr(self,'path',None)
def setPath(self, path):
"""
set the force value (if we need to force update or not)
"""
self.path = path
def getForce(self):
"""
get the force value (if we need to force update or not)
......@@ -1079,32 +1093,32 @@ class Subscription(Folder, SyncCode):
conflict_list += signature.getConflictList()
return conflict_list
def getRemainingObjectIdList(self):
def getRemainingObjectPathList(self):
"""
We should now wich objects should still
synchronize
"""
return getattr(self,'remaining_object_id_list',None)
return getattr(self,'remaining_object_path_list',None)
def setRemainingObjectIdList(self, value):
def setRemainingObjectPathList(self, value):
"""
We should now wich objects should still
synchronize
"""
setattr(self,'remaining_object_id_list',value)
setattr(self,'remaining_object_path_list',value)
def removeRemainingObjectId(self, object_id):
def removeRemainingObjectPath(self, object_path):
"""
We should now wich objects should still
synchronize
"""
remaining_object_list = self.getRemainingObjectIdList()
remaining_object_list = self.getRemainingObjectPathList()
if remaining_object_list is not None:
new_list = []
for o in remaining_object_list:
if o != object_id:
if o != object_path:
new_list.append(o)
self.setRemainingObjectIdList(new_list)
self.setRemainingObjectPathList(new_list)
# def getCurrentObject(self):
# """
......@@ -1131,5 +1145,5 @@ class Subscription(Folder, SyncCode):
o.setStatus(self.NOT_SYNCHRONIZED)
o.setPartialXML(None)
o.setTempXML(None)
self.setRemainingObjectIdList(None)
self.setRemainingObjectPathList(None)
......@@ -557,11 +557,11 @@ class XMLSyncUtilsMixin(SyncCode):
local_gid_list = []
syncml_data = ''
if subscriber.getRemainingObjectIdList() is None:
if subscriber.getRemainingObjectPathList() is None:
object_list = domain.getObjectList()
object_id_list = map(lambda x: x.id,object_list)
LOG('getSyncMLData, object_id_list',0,object_id_list)
subscriber.setRemainingObjectIdList(object_id_list)
object_path_list = map(lambda x: x.getPhysicalPath(),object_list)
LOG('getSyncMLData, object_path_list',0,object_path_list)
subscriber.setRemainingObjectPathList(object_path_list)
#object_gid = domain.getGidFromObject(object)
local_gid_list = map(lambda x: domain.getGidFromObject(x),object_list)
......@@ -581,8 +581,13 @@ class XMLSyncUtilsMixin(SyncCode):
#for object in domain.getObjectList():
for object_id in subscriber.getRemainingObjectIdList():
object = subscriber.getDestination()._getOb(object_id)
for object_path in subscriber.getRemainingObjectPathList():
#object = subscriber.getDestination()._getOb(object_id)
#object = subscriber.getDestination()._getOb(object_id)
#try:
object = self.unrestrictedTraverse(object_path)
#except KeyError:
#object = None
status = self.SENT
#gid_generator = getattr(object,domain.getGidGenerator(),None)
object_gid = domain.getGidFromObject(object)
......@@ -612,7 +617,7 @@ class XMLSyncUtilsMixin(SyncCode):
#LOG('PubSyncModif',0,'Current object.getPath: %s' % object.getPath())
LOG('getSyncMLData',0,'no signature for gid: %s' % object_gid)
xml_string = xml_object
signature = Signature(gid=object_gid,id=object.getId())
signature = Signature(gid=object_gid,id=object.getId(),object=object)
signature.setTempXML(xml_object)
if xml_string.count('\n') > self.MAX_LINES:
if xml_string.find('--') >= 0: # This make comment fails, so we need to replace
......@@ -739,12 +744,12 @@ class XMLSyncUtilsMixin(SyncCode):
partial_data = self.getPartialData(next_action)
object_gid = self.getActionId(next_action)
signature = subscriber.getSignature(object_gid)
object = domain.getObjectFromGid(object_gid)
if signature == None:
LOG('applyActionList, signature is None',0,signature)
signature = Signature(gid=object_gid,status=self.NOT_SYNCHRONIZED).__of__(subscriber)
signature = Signature(gid=object_gid,status=self.NOT_SYNCHRONIZED,object=object).__of__(subscriber)
subscriber.addSignature(signature)
force = signature.getForce()
object = domain.getObjectFromGid(object_gid)
LOG('applyActionList',0,'object: %s' % repr(object))
if self.checkActionMoreData(next_action) == 0:
data_subnode = None
......@@ -768,6 +773,7 @@ class XMLSyncUtilsMixin(SyncCode):
conflict_list += conduit.addNode(xml=data_subnode, object=destination_path,
object_id=object_id)
object = domain.getObjectFromGid(object_gid)
signature.setPath(object.getPhysicalPath())
LOG('applyActionList',0,'object after add: %s' % repr(object))
if object is not None:
LOG('SyncModif',0,'addNode, found the object')
......@@ -961,6 +967,10 @@ class XMLSyncUtils(XMLSyncUtilsMixin):
alert_code = self.getAlertCode(remote_xml)
#conduit = ERP5Conduit()
conduit_name = subscriber.getConduit()
LOG('getConduit: conduit_name',0,conduit_name)
LOG('getConduit: Conduit',0,Conduit)
LOG('getConduit: getattr(Conduit,conduit_name)',0,getattr(Conduit,conduit_name))
LOG('getConduit: getattargetattr(Conduit,conduit_name)',0,getattr(getattr(Conduit,conduit_name),conduit_name))
conduit = getattr(getattr(Conduit,conduit_name),conduit_name)()
LOG('SyncModif, subscriber: ',0,subscriber)
# Then apply the list of actions
......
......@@ -177,6 +177,8 @@ class TestERP5SyncML(ERP5TypeTestCase):
def login(self, quiet=0):
uf = self.getPortal().acl_users
uf._doAddUser('seb', '', ['Manager'], [])
uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], [])
uf._doAddUser('syncml', '', ['Manager'], [])
user = uf.getUserById('seb').__of__(uf)
newSecurityManager(None, user)
......@@ -1260,7 +1262,6 @@ class TestERP5SyncML(ERP5TypeTestCase):
self.subscription_url1,'/%s/person_client1' % portal_id,'objectValues',
'','ERP5Conduit','')
sub = portal_sync.getSubscription(self.sub_id1)
#sub.setOneWaySyncFromServer(1)
self.failUnless(sub is not None)
def test_33_OneWaySync(self, quiet=0, run=1):
......
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