942 % (rtype, new.eid, oldeid), ask_confirm=False) |
942 % (rtype, new.eid, oldeid), ask_confirm=False) |
943 # delete relations using SQL to avoid relations content removal |
943 # delete relations using SQL to avoid relations content removal |
944 # triggered by schema synchronization hooks. |
944 # triggered by schema synchronization hooks. |
945 session = self.session |
945 session = self.session |
946 for rdeftype in ('CWRelation', 'CWAttribute'): |
946 for rdeftype in ('CWRelation', 'CWAttribute'): |
947 thispending = set() |
947 thispending = set( (eid for eid, in self.sqlexec( |
948 for eid, in self.sqlexec('SELECT cw_eid FROM cw_%s ' |
948 'SELECT cw_eid FROM cw_%s WHERE cw_from_entity=%%(eid)s OR ' |
949 'WHERE cw_from_entity=%%(eid)s OR ' |
949 ' cw_to_entity=%%(eid)s' % rdeftype, |
950 ' cw_to_entity=%%(eid)s' % rdeftype, |
950 {'eid': oldeid}, ask_confirm=False)) ) |
951 {'eid': oldeid}, ask_confirm=False): |
951 # we should add deleted eids into pending eids else we may |
952 # we should add deleted eids into pending eids else we may |
952 # get some validation error on commit since integrity hooks |
953 # get some validation error on commit since integrity hooks |
953 # may think some required relation is missing... This also ensure |
954 # may think some required relation is missing... This also ensure |
954 # repository caches are properly cleanup |
955 # repository caches are properly cleanup |
955 hook.CleanupDeletedEidsCacheOp.get_instance(session).union(thispending) |
956 hook.CleanupDeletedEidsCacheOp.get_instance(session).add_data(eid) |
956 # and don't forget to remove record from system tables |
957 # and don't forget to remove record from system tables |
957 entities = [session.entity_from_eid(eid, rdeftype) for eid in thispending] |
958 self.repo.system_source.delete_info( |
958 self.repo.system_source.delete_info_multi(session, entities, 'system') |
959 session, session.entity_from_eid(eid, rdeftype), |
959 self.sqlexec('DELETE FROM cw_%s WHERE cw_from_entity=%%(eid)s OR ' |
960 'system', None) |
|
961 thispending.add(eid) |
|
962 self.sqlexec('DELETE FROM cw_%s ' |
|
963 'WHERE cw_from_entity=%%(eid)s OR ' |
|
964 'cw_to_entity=%%(eid)s' % rdeftype, |
960 'cw_to_entity=%%(eid)s' % rdeftype, |
965 {'eid': oldeid}, ask_confirm=False) |
961 {'eid': oldeid}, ask_confirm=False) |
966 # now we have to manually cleanup relations pointing to deleted |
962 # now we have to manually cleanup relations pointing to deleted |
967 # entities |
963 # entities |
968 thiseids = ','.join(str(eid) for eid in thispending) |
964 thiseids = ','.join(str(eid) for eid in thispending) |