[multi-sources-removal] Drop no more necessary scleanup (source cleanup) argument
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 21 Jun 2013 16:18:20 +0200
changeset 9455 62e89e696a3b
parent 9454 a173f9cf9f26
child 9456 a79e88aad555
[multi-sources-removal] Drop no more necessary scleanup (source cleanup) argument Related to #2919300
server/repository.py
server/test/unittest_repository.py
--- a/server/repository.py	Wed Jan 22 10:39:57 2014 +0100
+++ b/server/repository.py	Fri Jun 21 16:18:20 2013 +0200
@@ -1123,30 +1123,22 @@
         hook.CleanupNewEidsCacheOp.get_instance(session).add_data(entity.eid)
         self.system_source.add_info(session, entity, source, extid, complete)
 
-    def delete_info(self, session, entity, sourceuri, scleanup=None):
+    def delete_info(self, session, entity, sourceuri):
         """called by external source when some entity known by the system source
         has been deleted in the external source
         """
         # mark eid as being deleted in session info and setup cache update
         # operation
         hook.CleanupDeletedEidsCacheOp.get_instance(session).add_data(entity.eid)
-        self._delete_info(session, entity, sourceuri, scleanup)
+        self._delete_info(session, entity, sourceuri)
 
-    def _delete_info(self, session, entity, sourceuri, scleanup=None):
+    def _delete_info(self, session, entity, sourceuri):
         """delete system information on deletion of an entity:
 
         * delete all remaining relations from/to this entity
         * call delete info on the system source
-
-        When scleanup is specified, it's expected to be the source's eid, in
-        which case we'll specify the target's relation source so that this
-        source is ignored. E.g. we want to delete relations stored locally, as
-        the deletion information comes from the external source, it's its
-        responsability to have cleaned-up its own relations.
         """
         pendingrtypes = session.transaction_data.get('pendingrtypes', ())
-        if scleanup is not None:
-            source = self.sources_by_eid[scleanup]
         # delete remaining relations: if user can delete the entity, he can
         # delete all its relations without security checking
         with session.security_enabled(read=False, write=False):
@@ -1161,13 +1153,8 @@
                     rql = 'DELETE X %s Y WHERE X eid %%(x)s' % rtype
                 else:
                     rql = 'DELETE Y %s X WHERE X eid %%(x)s' % rtype
-                if scleanup is not None:
-                    # source cleaning: only delete relations stored locally
-                    # (here, scleanup
-                    rql += ', NOT (Y cw_source S, S eid %(seid)s)'
                 try:
-                    session.execute(rql, {'x': eid, 'seid': scleanup},
-                                    build_descr=False)
+                    session.execute(rql, {'x': eid}, build_descr=False)
                 except Exception:
                     if self.config.mode == 'test':
                         raise
@@ -1175,13 +1162,11 @@
                                    'from %s. RQL: %s', entity, sourceuri, rql)
         self.system_source.delete_info_multi(session, [entity])
 
-    def _delete_info_multi(self, session, entities, scleanup=None):
+    def _delete_info_multi(self, session, entities):
         """same as _delete_info but accepts a list of entities with
         the same etype and belinging to the same source.
         """
         pendingrtypes = session.transaction_data.get('pendingrtypes', ())
-        if scleanup is not None:
-            source = self.sources_by_eid[scleanup]
         # delete remaining relations: if user can delete the entity, he can
         # delete all its relations without security checking
         with session.security_enabled(read=False, write=False):
@@ -1196,11 +1181,8 @@
                     rql = 'DELETE X %s Y WHERE X eid IN (%s)' % (rtype, in_eids)
                 else:
                     rql = 'DELETE Y %s X WHERE X eid IN (%s)' % (rtype, in_eids)
-                if scleanup is not None:
-                    # source cleaning: only delete relations stored locally
-                    rql += ', NOT (Y cw_source S, S eid %(seid)s)'
                 try:
-                    session.execute(rql, {'seid': scleanup}, build_descr=False)
+                    session.execute(rql, build_descr=False)
                 except ValidationError:
                     raise
                 except Unauthorized:
--- a/server/test/unittest_repository.py	Wed Jan 22 10:39:57 2014 +0100
+++ b/server/test/unittest_repository.py	Fri Jun 21 16:18:20 2013 +0200
@@ -697,7 +697,7 @@
         data = cu.fetchall()
         self.assertEqual(tuplify(data), [(-1, 'Personne', 'system', 'system',
                                           None)])
-        self.repo.delete_info(self.session, entity, 'system', None)
+        self.repo.delete_info(self.session, entity, 'system')
         #self.repo.commit()
         cu = self.session.system_sql('SELECT * FROM entities WHERE eid = -1')
         data = cu.fetchall()