hooks/syncschema.py
branchstable
changeset 4721 8f63691ccb7f
parent 4719 aaed3f813ef8
child 4722 9c13d5db03d9
equal deleted inserted replaced
4720:ddf4f19eb07a 4721:8f63691ccb7f
    82     # is done by the dbhelper)
    82     # is done by the dbhelper)
    83     session.pool.source('system').create_index(session, table, column)
    83     session.pool.source('system').create_index(session, table, column)
    84     session.info('added index on %s(%s)', table, column)
    84     session.info('added index on %s(%s)', table, column)
    85     session.transaction_data.setdefault('createdattrs', []).append(
    85     session.transaction_data.setdefault('createdattrs', []).append(
    86         '%s.%s' % (etype, rtype))
    86         '%s.%s' % (etype, rtype))
       
    87 
    87 
    88 
    88 def check_valid_changes(session, entity, ro_attrs=('name', 'final')):
    89 def check_valid_changes(session, entity, ro_attrs=('name', 'final')):
    89     errors = {}
    90     errors = {}
    90     # don't use getattr(entity, attr), we would get the modified value if any
    91     # don't use getattr(entity, attr), we would get the modified value if any
    91     for attr in entity.edited_attributes:
    92     for attr in entity.edited_attributes:
  1135     """
  1136     """
  1136 
  1137 
  1137     def postcommit_event(self):
  1138     def postcommit_event(self):
  1138         session = self.session
  1139         session = self.session
  1139         source = session.repo.system_source
  1140         source = session.repo.system_source
  1140         to_reindex = session.transaction_data.get('fti_update_etypes',())
  1141         to_reindex = session.transaction_data.get('fti_update_etypes', ())
  1141         self.info('%i etypes need full text indexed reindexation', len(to_reindex))
  1142         self.info('%i etypes need full text indexed reindexation',
       
  1143                   len(to_reindex))
  1142         schema = self.session.repo.vreg.schema
  1144         schema = self.session.repo.vreg.schema
  1143         for etype in to_reindex:
  1145         for etype in to_reindex:
  1144             rset = session.execute('Any X WHERE X is %s' % etype)
  1146             rset = session.execute('Any X WHERE X is %s' % etype)
  1145             self.info('Reindexing full text index for %i entity of type %s', len(rset), etype)
  1147             self.info('Reindexing full text index for %i entity of type %s',
       
  1148                       len(rset), etype)
  1146             still_fti = list(schema[etype].indexable_attributes())
  1149             still_fti = list(schema[etype].indexable_attributes())
  1147             for entity in rset.entities():
  1150             for entity in rset.entities():
  1148                 try:
  1151                 try:
  1149                   source.fti_unindex_entity(session, entity.eid)
  1152                     source.fti_unindex_entity(session, entity.eid)
  1150                   for container in entity.fti_containers():
  1153                     for container in entity.fti_containers():
  1151                       if still_fti or container is not entity:
  1154                         if still_fti or container is not entity:
  1152                           session.repo.index_entity(session, container)
  1155                             session.repo.index_entity(session, container)
  1153                 except Exception, ex:
  1156                 except Exception:
  1154                     self.critical('Error while updating Full Text Index for'
  1157                     self.critical('Error while updating Full Text Index for'
  1155                                   ' entity %s', entity.eid, exc_info=True)
  1158                                   ' entity %s', entity.eid, exc_info=True)
  1156         if len(to_reindex):
  1159         if len(to_reindex):
  1157             # Transaction have already been committed
  1160             # Transaction have already been committed
  1158             session.pool.commit()
  1161             session.pool.commit()