server/repository.py
changeset 6626 5c20a005bddc
parent 6491 ee9a10b6620e
child 6629 edaa96d031b2
equal deleted inserted replaced
6625:54847e2c4a50 6626:5c20a005bddc
  1086         """
  1086         """
  1087         # begin by inserting eid/type/source/extid into the entities table
  1087         # begin by inserting eid/type/source/extid into the entities table
  1088         hook.CleanupNewEidsCacheOp.get_instance(session).add_data(entity.eid)
  1088         hook.CleanupNewEidsCacheOp.get_instance(session).add_data(entity.eid)
  1089         self.system_source.add_info(session, entity, source, extid, complete)
  1089         self.system_source.add_info(session, entity, source, extid, complete)
  1090 
  1090 
  1091     def delete_info(self, session, entity, sourceuri, extid):
  1091     def delete_info(self, session, entity, sourceuri, extid, scleanup=False):
  1092         """called by external source when some entity known by the system source
  1092         """called by external source when some entity known by the system source
  1093         has been deleted in the external source
  1093         has been deleted in the external source
  1094         """
  1094         """
  1095         # mark eid as being deleted in session info and setup cache update
  1095         # mark eid as being deleted in session info and setup cache update
  1096         # operation
  1096         # operation
  1097         hook.CleanupDeletedEidsCacheOp.get_instance(session).add_data(entity.eid)
  1097         hook.CleanupDeletedEidsCacheOp.get_instance(session).add_data(entity.eid)
  1098         self._delete_info(session, entity, sourceuri, extid)
  1098         self._delete_info(session, entity, sourceuri, extid, scleanup)
  1099 
  1099 
  1100     def _delete_info(self, session, entity, sourceuri, extid):
  1100     def _delete_info(self, session, entity, sourceuri, extid, scleanup):
  1101                      # attributes=None, relations=None):
       
  1102         """delete system information on deletion of an entity:
  1101         """delete system information on deletion of an entity:
  1103         * delete all remaining relations from/to this entity
  1102         * delete all remaining relations from/to this entity
  1104         * call delete info on the system source which will transfer record from
  1103         * call delete info on the system source which will transfer record from
  1105           the entities table to the deleted_entities table
  1104           the entities table to the deleted_entities table
  1106         """
  1105         """
  1117                     # don't skip inlined relation so they are regularly
  1116                     # don't skip inlined relation so they are regularly
  1118                     # deleted and so hooks are correctly called
  1117                     # deleted and so hooks are correctly called
  1119                     rql = 'DELETE X %s Y WHERE X eid %%(x)s' % rtype
  1118                     rql = 'DELETE X %s Y WHERE X eid %%(x)s' % rtype
  1120                 else:
  1119                 else:
  1121                     rql = 'DELETE Y %s X WHERE X eid %%(x)s' % rtype
  1120                     rql = 'DELETE Y %s X WHERE X eid %%(x)s' % rtype
  1122                 session.execute(rql, {'x': eid}, build_descr=False)
  1121                 if scleanup:
       
  1122                     # source cleaning: only delete relations stored locally
       
  1123                     rql += ', NOT Y cw_source S, S name %(source)s'
       
  1124                 session.execute(rql, {'x': eid, 'source': sourceuri},
       
  1125                                 build_descr=False)
  1123         self.system_source.delete_info(session, entity, sourceuri, extid)
  1126         self.system_source.delete_info(session, entity, sourceuri, extid)
  1124 
  1127 
  1125     def locate_relation_source(self, session, subject, rtype, object):
  1128     def locate_relation_source(self, session, subject, rtype, object):
  1126         subjsource = self.source_from_eid(subject, session)
  1129         subjsource = self.source_from_eid(subject, session)
  1127         objsource = self.source_from_eid(object, session)
  1130         objsource = self.source_from_eid(object, session)