305 rschema = self.rschema |
305 rschema = self.rschema |
306 if rschema.final: |
306 if rschema.final: |
307 return # watched changes to final relation type are unexpected |
307 return # watched changes to final relation type are unexpected |
308 session = self.session |
308 session = self.session |
309 if 'fulltext_container' in self.values: |
309 if 'fulltext_container' in self.values: |
|
310 op = UpdateFTIndexOp.get_instance(session) |
310 for subjtype, objtype in rschema.rdefs: |
311 for subjtype, objtype in rschema.rdefs: |
311 hook.set_operation(session, 'fti_update_etypes', subjtype, |
312 op.add_data(subjtype) |
312 UpdateFTIndexOp) |
313 op.add_data(objtype) |
313 hook.set_operation(session, 'fti_update_etypes', objtype, |
|
314 UpdateFTIndexOp) |
|
315 # update the in-memory schema first |
314 # update the in-memory schema first |
316 self.oldvalues = dict( (attr, getattr(rschema, attr)) for attr in self.values) |
315 self.oldvalues = dict( (attr, getattr(rschema, attr)) for attr in self.values) |
317 self.rschema.__dict__.update(self.values) |
316 self.rschema.__dict__.update(self.values) |
318 # then make necessary changes to the system source database |
317 # then make necessary changes to the system source database |
319 if not 'inlined' in self.values: |
318 if not 'inlined' in self.values: |
601 rdef.rtype.inlined) \ |
600 rdef.rtype.inlined) \ |
602 and self.values['cardinality'][0] != self.oldvalues['cardinality'][0]: |
601 and self.values['cardinality'][0] != self.oldvalues['cardinality'][0]: |
603 syssource.update_rdef_null_allowed(self.session, rdef) |
602 syssource.update_rdef_null_allowed(self.session, rdef) |
604 self.null_allowed_changed = True |
603 self.null_allowed_changed = True |
605 if 'fulltextindexed' in self.values: |
604 if 'fulltextindexed' in self.values: |
606 hook.set_operation(session, 'fti_update_etypes', rdef.subject, |
605 UpdateFTIndexOp.get_instance(session).add_data(rdef.subject) |
607 UpdateFTIndexOp) |
|
608 |
606 |
609 def revertprecommit_event(self): |
607 def revertprecommit_event(self): |
610 if self.rdef is None: |
608 if self.rdef is None: |
611 return |
609 return |
612 # revert changes on in memory schema |
610 # revert changes on in memory schema |
1179 MemSchemaPermissionDel(self._cw, action=action, eid=self.eidfrom, |
1177 MemSchemaPermissionDel(self._cw, action=action, eid=self.eidfrom, |
1180 expr=expr) |
1178 expr=expr) |
1181 |
1179 |
1182 |
1180 |
1183 |
1181 |
1184 class UpdateFTIndexOp(hook.SingleLastOperation): |
1182 class UpdateFTIndexOp(hook.DataOperationMixIn, hook.SingleLastOperation): |
1185 """operation to update full text indexation of entity whose schema change |
1183 """operation to update full text indexation of entity whose schema change |
1186 |
1184 |
1187 We wait after the commit to as the schema in memory is only updated after the commit. |
1185 We wait after the commit to as the schema in memory is only updated after |
|
1186 the commit. |
1188 """ |
1187 """ |
1189 |
1188 |
1190 def postcommit_event(self): |
1189 def postcommit_event(self): |
1191 session = self.session |
1190 session = self.session |
1192 source = session.repo.system_source |
1191 source = session.repo.system_source |
1193 to_reindex = session.transaction_data.pop('fti_update_etypes', ()) |
1192 schema = session.repo.vreg.schema |
|
1193 to_reindex = self.get_data() |
1194 self.info('%i etypes need full text indexed reindexation', |
1194 self.info('%i etypes need full text indexed reindexation', |
1195 len(to_reindex)) |
1195 len(to_reindex)) |
1196 schema = self.session.repo.vreg.schema |
|
1197 for etype in to_reindex: |
1196 for etype in to_reindex: |
1198 rset = session.execute('Any X WHERE X is %s' % etype) |
1197 rset = session.execute('Any X WHERE X is %s' % etype) |
1199 self.info('Reindexing full text index for %i entity of type %s', |
1198 self.info('Reindexing full text index for %i entity of type %s', |
1200 len(rset), etype) |
1199 len(rset), etype) |
1201 still_fti = list(schema[etype].indexable_attributes()) |
1200 still_fti = list(schema[etype].indexable_attributes()) |
1203 source.fti_unindex_entity(session, entity.eid) |
1202 source.fti_unindex_entity(session, entity.eid) |
1204 for container in entity.cw_adapt_to('IFTIndexable').fti_containers(): |
1203 for container in entity.cw_adapt_to('IFTIndexable').fti_containers(): |
1205 if still_fti or container is not entity: |
1204 if still_fti or container is not entity: |
1206 source.fti_unindex_entity(session, container.eid) |
1205 source.fti_unindex_entity(session, container.eid) |
1207 source.fti_index_entity(session, container) |
1206 source.fti_index_entity(session, container) |
1208 if len(to_reindex): |
1207 if to_reindex: |
1209 # Transaction have already been committed |
1208 # Transaction has already been committed |
1210 session.pool.commit() |
1209 session.pool.commit() |
1211 |
1210 |
1212 |
1211 |
1213 |
1212 |
1214 |
1213 |