hooks/syncschema.py
changeset 4829 3b79a0fc91db
parent 4808 23df4a120c96
parent 4828 3e173d598cad
child 4835 13b0b96d7982
equal deleted inserted replaced
4823:e833520870ee 4829:3b79a0fc91db
   225                 (self.newname, self.oldname))
   225                 (self.newname, self.oldname))
   226 
   226 
   227 
   227 
   228 class SourceDbCWRTypeUpdate(hook.Operation):
   228 class SourceDbCWRTypeUpdate(hook.Operation):
   229     """actually update some properties of a relation definition"""
   229     """actually update some properties of a relation definition"""
   230     rschema = values = entity = None # make pylint happy
   230     rschema = entity = None # make pylint happy
   231 
   231 
   232     def precommit_event(self):
   232     def precommit_event(self):
   233         session = self.session
   233         session = self.session
   234         rschema = self.rschema
   234         rschema = self.rschema
   235         if rschema.final or not 'inlined' in self.values:
   235         entity = self.entity
       
   236         if 'fulltext_container' in entity.edited_attributes:
       
   237             ftiupdates = session.transaction_data.setdefault(
       
   238                 'fti_update_etypes', set())
       
   239             for subjtype, objtype in rschema.rdefs:
       
   240                 ftiupdates.add(subjtype)
       
   241                 ftiupdates.add(objtype)
       
   242             UpdateFTIndexOp(session)
       
   243         if rschema.final or not 'inlined' in entity.edited_attributes:
   236             return # nothing to do
   244             return # nothing to do
   237         inlined = self.values['inlined']
   245         inlined = entity.inlined
   238         entity = self.entity
       
   239         # check in-lining is necessary / possible
   246         # check in-lining is necessary / possible
   240         if not entity.inlined_changed(inlined):
   247         if not entity.inlined_changed(inlined):
   241             return # nothing to do
   248             return # nothing to do
   242         # inlined changed, make necessary physical changes!
   249         # inlined changed, make necessary physical changes!
   243         sqlexec = self.session.system_sql
   250         sqlexec = self.session.system_sql
   495             session.system_sql(sql)
   502             session.system_sql(sql)
   496         if 'fulltextindexed' in self.values:
   503         if 'fulltextindexed' in self.values:
   497             UpdateFTIndexOp(session)
   504             UpdateFTIndexOp(session)
   498             session.transaction_data.setdefault(
   505             session.transaction_data.setdefault(
   499                 'fti_update_etypes', set()).add(etype)
   506                 'fti_update_etypes', set()).add(etype)
   500         elif 'fulltext_container' in self.values:
       
   501             ftiupdates = session.transaction_data.setdefault(
       
   502                 'fti_update_etypes', set())
       
   503             ftiupdates.add(etype)
       
   504             ftiupdates.add(self.kobj[1])
       
   505             UpdateFTIndexOp(session)
       
   506 
   507 
   507 
   508 
   508 class SourceDbCWConstraintAdd(hook.Operation):
   509 class SourceDbCWConstraintAdd(hook.Operation):
   509     """actually update constraint of a relation definition"""
   510     """actually update constraint of a relation definition"""
   510     entity = None # make pylint happy
   511     entity = None # make pylint happy
   944     __regid__ = 'syncupdatecwrtype'
   945     __regid__ = 'syncupdatecwrtype'
   945     events = ('after_update_entity',)
   946     events = ('after_update_entity',)
   946 
   947 
   947     def __call__(self):
   948     def __call__(self):
   948         entity = self.entity
   949         entity = self.entity
   949         rschema = self._cw.vreg.schema.rschema(entity.name)
       
   950         newvalues = {}
   950         newvalues = {}
   951         for prop in ('meta', 'symmetric', 'inlined'):
   951         for prop in ('symmetric', 'inlined', 'fulltext_container'):
   952             if prop in entity:
   952             if prop in entity.edited_attributes:
   953                 newvalues[prop] = entity[prop]
   953                 newvalues[prop] = entity[prop]
   954         if newvalues:
   954         if newvalues:
       
   955             rschema = self._cw.vreg.schema.rschema(entity.name)
       
   956             SourceDbCWRTypeUpdate(self._cw, rschema=rschema, entity=entity)
   955             MemSchemaCWRTypeUpdate(self._cw, rschema=rschema, values=newvalues)
   957             MemSchemaCWRTypeUpdate(self._cw, rschema=rschema, values=newvalues)
   956             SourceDbCWRTypeUpdate(self._cw, rschema=rschema, values=newvalues,
       
   957                                   entity=entity)
       
   958 
   958 
   959 
   959 
   960 class AfterDelRelationTypeHook(SyncSchemaHook):
   960 class AfterDelRelationTypeHook(SyncSchemaHook):
   961     """before deleting a CWAttribute or CWRelation entity:
   961     """before deleting a CWAttribute or CWRelation entity:
   962     * if this is a final or inlined relation definition, instantiate an
   962     * if this is a final or inlined relation definition, instantiate an
  1162             rset = session.execute('Any X WHERE X is %s' % etype)
  1162             rset = session.execute('Any X WHERE X is %s' % etype)
  1163             self.info('Reindexing full text index for %i entity of type %s',
  1163             self.info('Reindexing full text index for %i entity of type %s',
  1164                       len(rset), etype)
  1164                       len(rset), etype)
  1165             still_fti = list(schema[etype].indexable_attributes())
  1165             still_fti = list(schema[etype].indexable_attributes())
  1166             for entity in rset.entities():
  1166             for entity in rset.entities():
  1167                 try:
  1167                 source.fti_unindex_entity(session, entity.eid)
  1168                     source.fti_unindex_entity(session, entity.eid)
  1168                 for container in entity.fti_containers():
  1169                     for container in entity.fti_containers():
  1169                     if still_fti or container is not entity:
  1170                         if still_fti or container is not entity:
  1170                         source.fti_unindex_entity(session, entity.eid)
  1171                             source.fti_unindex_entity(session, entity.eid)
  1171                         source.fti_index_entity(session, container)
  1172                             source.fti_index_entity(session, container)
       
  1173                 except Exception:
       
  1174                     self.critical('Error while updating Full Text Index for'
       
  1175                                   ' entity %s', entity.eid, exc_info=True)
       
  1176         if len(to_reindex):
  1172         if len(to_reindex):
  1177             # Transaction have already been committed
  1173             # Transaction have already been committed
  1178             session.pool.commit()
  1174             session.pool.commit()
  1179 
  1175 
  1180 
  1176