# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1239027098 -7200 # Node ID 5c20a7f13c84ce9f29fb80d4fb7c7d20cd350090 # Parent 905d76e384337021b5e9aa950c3aa00a4102e59d new recreate argument to extid2eid when an external source want to recreate entities previously imported with a predictable ext id diff -r 905d76e38433 -r 5c20a7f13c84 server/hooks.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 diff -r 905d76e38433 -r 5c20a7f13c84 server/repository.py --- 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 diff -r 905d76e38433 -r 5c20a7f13c84 server/sources/__init__.py --- 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):