server/repository.py
branchstable
changeset 2873 51bcd8e8f65c
parent 2854 5777ec682642
child 2875 b7399ef8b3e0
equal deleted inserted replaced
2872:9d641d98cc86 2873:51bcd8e8f65c
  1037         if source.should_call_hooks:
  1037         if source.should_call_hooks:
  1038             self.hm.call_hooks('after_add_entity', etype, session, entity)
  1038             self.hm.call_hooks('after_add_entity', etype, session, entity)
  1039             # call hooks for inlined relations
  1039             # call hooks for inlined relations
  1040             for attr, value in relations:
  1040             for attr, value in relations:
  1041                 self.hm.call_hooks('before_add_relation', attr, session,
  1041                 self.hm.call_hooks('before_add_relation', attr, session,
  1042                                     entity.eid, attr, value)
  1042                                    entity.eid, attr, value)
  1043                 self.hm.call_hooks('after_add_relation', attr, session,
  1043                 self.hm.call_hooks('after_add_relation', attr, session,
  1044                                     entity.eid, attr, value)
  1044                                    entity.eid, attr, value)
  1045         return entity.eid
  1045         return entity.eid
  1046 
  1046 
  1047     def glob_update_entity(self, session, entity, edited_attributes):
  1047     def glob_update_entity(self, session, entity, edited_attributes):
  1048         """replace an entity in the repository
  1048         """replace an entity in the repository
  1049         the type and the eid of an entity must not be changed
  1049         the type and the eid of an entity must not be changed
  1056         entity.check()
  1056         entity.check()
  1057         eschema = entity.e_schema
  1057         eschema = entity.e_schema
  1058         session.set_entity_cache(entity)
  1058         session.set_entity_cache(entity)
  1059         only_inline_rels, need_fti_update = True, False
  1059         only_inline_rels, need_fti_update = True, False
  1060         relations = []
  1060         relations = []
  1061         for attr in entity.keys():
  1061         for attr in edited_attributes:
  1062             if attr == 'eid':
  1062             if attr == 'eid':
  1063                 continue
  1063                 continue
  1064             rschema = eschema.subject_relation(attr)
  1064             rschema = eschema.subject_relation(attr)
  1065             if rschema.is_final():
  1065             if rschema.is_final():
  1066                 if eschema.rproperty(attr, 'fulltextindexed'):
  1066                 if eschema.rproperty(attr, 'fulltextindexed'):
  1067                     need_fti_update = True
  1067                     need_fti_update = True
  1068                 only_inline_rels = False
  1068                 only_inline_rels = False
  1069             else:
  1069             else:
  1070                 # inlined relation
  1070                 # inlined relation
  1071                 previous_value = entity.related(attr)
  1071                 previous_value = entity.related(attr) or None
  1072                 if previous_value:
  1072                 if previous_value is not None:
  1073                     previous_value = previous_value[0][0] # got a result set
  1073                     previous_value = previous_value[0][0] # got a result set
  1074                     if previous_value == entity[attr]:
  1074                     if previous_value == entity[attr]:
  1075                         previous_value = None
  1075                         previous_value = None
  1076                     else:
  1076                     else:
  1077                         self.hm.call_hooks('before_delete_relation', attr,
  1077                         self.hm.call_hooks('before_delete_relation', attr,
  1098                                     entity)
  1098                                     entity)
  1099         if source.should_call_hooks:
  1099         if source.should_call_hooks:
  1100             for attr, value, prevvalue in relations:
  1100             for attr, value, prevvalue in relations:
  1101                 # if the relation is already cached, update existant cache
  1101                 # if the relation is already cached, update existant cache
  1102                 relcache = entity.relation_cached(attr, 'subject')
  1102                 relcache = entity.relation_cached(attr, 'subject')
  1103                 if prevvalue:
  1103                 if prevvalue is not None:
  1104                     self.hm.call_hooks('after_delete_relation', attr, session,
  1104                     self.hm.call_hooks('after_delete_relation', attr, session,
  1105                                        entity.eid, attr, prevvalue)
  1105                                        entity.eid, attr, prevvalue)
  1106                     if relcache is not None:
  1106                     if relcache is not None:
  1107                         session.update_rel_cache_del(entity.eid, attr, prevvalue)
  1107                         session.update_rel_cache_del(entity.eid, attr, prevvalue)
  1108                 del_existing_rel_if_needed(session, entity.eid, attr, value)
  1108                 del_existing_rel_if_needed(session, entity.eid, attr, value)