1128 source is ignored. E.g. we want to delete relations stored locally, as |
1128 source is ignored. E.g. we want to delete relations stored locally, as |
1129 the deletion information comes from the external source, it's its |
1129 the deletion information comes from the external source, it's its |
1130 responsability to have cleaned-up its own relations. |
1130 responsability to have cleaned-up its own relations. |
1131 """ |
1131 """ |
1132 pendingrtypes = session.transaction_data.get('pendingrtypes', ()) |
1132 pendingrtypes = session.transaction_data.get('pendingrtypes', ()) |
|
1133 if scleanup is not None: |
|
1134 source = self.sources_by_eid[scleanup] |
1133 # delete remaining relations: if user can delete the entity, he can |
1135 # delete remaining relations: if user can delete the entity, he can |
1134 # delete all its relations without security checking |
1136 # delete all its relations without security checking |
1135 with security_enabled(session, read=False, write=False): |
1137 with security_enabled(session, read=False, write=False): |
1136 eid = entity.eid |
1138 eid = entity.eid |
1137 for rschema, _, role in entity.e_schema.relation_definitions(): |
1139 for rschema, _, role in entity.e_schema.relation_definitions(): |
1143 # deleted and so hooks are correctly called |
1145 # deleted and so hooks are correctly called |
1144 rql = 'DELETE X %s Y WHERE X eid %%(x)s' % rtype |
1146 rql = 'DELETE X %s Y WHERE X eid %%(x)s' % rtype |
1145 else: |
1147 else: |
1146 rql = 'DELETE Y %s X WHERE X eid %%(x)s' % rtype |
1148 rql = 'DELETE Y %s X WHERE X eid %%(x)s' % rtype |
1147 if scleanup is not None: |
1149 if scleanup is not None: |
|
1150 # if the relation can't be crossed, nothing to cleanup (we |
|
1151 # would get a BadRQLQuery from the multi-sources planner). |
|
1152 # This may still leave some junk if the mapping has changed |
|
1153 # at some point, but one can still run db-check to catch |
|
1154 # those |
|
1155 if not source in self.can_cross_relation(rtype): |
|
1156 continue |
1148 # source cleaning: only delete relations stored locally |
1157 # source cleaning: only delete relations stored locally |
1149 # (here, scleanup |
1158 # (here, scleanup |
1150 rql += ', NOT (Y cw_source S, S eid %(seid)s)' |
1159 rql += ', NOT (Y cw_source S, S eid %(seid)s)' |
1151 try: |
1160 try: |
1152 session.execute(rql, {'x': eid, 'seid': scleanup}, |
1161 session.execute(rql, {'x': eid, 'seid': scleanup}, |
1161 def _delete_info_multi(self, session, entities, sourceuri, scleanup=None): |
1170 def _delete_info_multi(self, session, entities, sourceuri, scleanup=None): |
1162 """same as _delete_info but accepts a list of entities with |
1171 """same as _delete_info but accepts a list of entities with |
1163 the same etype and belinging to the same source. |
1172 the same etype and belinging to the same source. |
1164 """ |
1173 """ |
1165 pendingrtypes = session.transaction_data.get('pendingrtypes', ()) |
1174 pendingrtypes = session.transaction_data.get('pendingrtypes', ()) |
|
1175 if scleanup is not None: |
|
1176 source = self.sources_by_eid[scleanup] |
1166 # delete remaining relations: if user can delete the entity, he can |
1177 # delete remaining relations: if user can delete the entity, he can |
1167 # delete all its relations without security checking |
1178 # delete all its relations without security checking |
1168 with security_enabled(session, read=False, write=False): |
1179 with security_enabled(session, read=False, write=False): |
1169 eids = [_e.eid for _e in entities] |
1180 eids = [_e.eid for _e in entities] |
1170 in_eids = ','.join((str(eid) for eid in eids)) |
1181 in_eids = ','.join((str(eid) for eid in eids)) |
1177 # deleted and so hooks are correctly called |
1188 # deleted and so hooks are correctly called |
1178 rql = 'DELETE X %s Y WHERE X eid IN (%s)' % (rtype, in_eids) |
1189 rql = 'DELETE X %s Y WHERE X eid IN (%s)' % (rtype, in_eids) |
1179 else: |
1190 else: |
1180 rql = 'DELETE Y %s X WHERE X eid IN (%s)' % (rtype, in_eids) |
1191 rql = 'DELETE Y %s X WHERE X eid IN (%s)' % (rtype, in_eids) |
1181 if scleanup is not None: |
1192 if scleanup is not None: |
|
1193 # if the relation can't be crossed, nothing to cleanup (we |
|
1194 # would get a BadRQLQuery from the multi-sources planner). |
|
1195 # This may still leave some junk if the mapping has changed |
|
1196 # at some point, but one can still run db-check to catch |
|
1197 # those |
|
1198 if not source in self.can_cross_relation(rtype): |
|
1199 continue |
1182 # source cleaning: only delete relations stored locally |
1200 # source cleaning: only delete relations stored locally |
1183 rql += ', NOT (Y cw_source S, S eid %(seid)s)' |
1201 rql += ', NOT (Y cw_source S, S eid %(seid)s)' |
1184 try: |
1202 try: |
1185 session.execute(rql, {'seid': scleanup}, build_descr=False) |
1203 session.execute(rql, {'seid': scleanup}, build_descr=False) |
1186 except Exception: |
1204 except Exception: |