new recreate argument to extid2eid when an external source want to recreate entities previously imported with a predictable ext id
authorsylvain.thenault@logilab.fr
Mon, 06 Apr 2009 16:11:38 +0200
changeset 1250 5c20a7f13c84
parent 1249 905d76e38433
child 1251 af40e615dc89
new recreate argument to extid2eid when an external source want to recreate entities previously imported with a predictable ext id
server/hooks.py
server/repository.py
server/sources/__init__.py
--- a/server/hooks.py	Mon Apr 06 15:36:58 2009 +0200
+++ b/server/hooks.py	Mon Apr 06 16:11:38 2009 +0200
@@ -62,6 +62,8 @@
 
 def setis_after_add_entity(session, entity):
     """create a new entity -> set is relation"""
+    if hasattr(entity, '_cw_recreating'):
+        return
     session.unsafe_execute('SET X is E WHERE X eid %(x)s, E name %(name)s',
                            {'x': entity.eid, 'name': entity.id}, 'x')
     # XXX < 2.50 bw compat
--- a/server/repository.py	Mon Apr 06 15:36:58 2009 +0200
+++ b/server/repository.py	Mon Apr 06 16:11:38 2009 +0200
@@ -770,7 +770,8 @@
             raise UnknownEid(eid)
         return extid
 
-    def extid2eid(self, source, lid, etype, session=None, insert=True):
+    def extid2eid(self, source, lid, etype, session=None, insert=True,
+                  recreate=False):
         """get eid from a local id. An eid is attributed if no record is found"""
         cachekey = (str(lid), source.uri)
         try:
@@ -785,6 +786,15 @@
         if eid is not None:
             self._extid_cache[cachekey] = eid
             self._type_source_cache[eid] = (etype, source.uri, lid)
+            if recreate:
+                entity = source.before_entity_insertion(session, lid, etype, eid)
+                entity._cw_recreating = True
+                if source.should_call_hooks:
+                    self.hm.call_hooks('before_add_entity', etype, session, entity)
+                # XXX add fti op ?
+                source.after_entity_insertion(session, lid, entity)
+                if source.should_call_hooks:
+                    self.hm.call_hooks('after_add_entity', etype, session, entity)
             if reset_pool:
                 session.reset_pool()
             return eid
--- a/server/sources/__init__.py	Mon Apr 06 15:36:58 2009 +0200
+++ b/server/sources/__init__.py	Mon Apr 06 16:11:38 2009 +0200
@@ -137,8 +137,8 @@
     def eid2extid(self, eid, session=None):
         return self.repo.eid2extid(self, eid, session)
 
-    def extid2eid(self, value, etype, session=None, insert=True):
-        return self.repo.extid2eid(self, value, etype, session, insert)
+    def extid2eid(self, value, etype, session=None, **kwargs):
+        return self.repo.extid2eid(self, value, etype, session, **kwargs)
 
     PUBLIC_KEYS = ('adapter', 'uri')
     def remove_sensitive_information(self, sourcedef):