hooks/syncschema.py
changeset 4845 dc351b96f596
parent 4835 13b0b96d7982
parent 4839 f482dbdf2f8c
child 4930 9fcc9ae2aebe
equal deleted inserted replaced
4844:ad78b118b124 4845:dc351b96f596
   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 = entity = None # make pylint happy
   230     rschema = entity = values = None # make pylint happy
   231 
   231 
   232     def precommit_event(self):
   232     def precommit_event(self):
       
   233         rschema = self.rschema
       
   234         if rschema.final:
       
   235             return
   233         session = self.session
   236         session = self.session
   234         rschema = self.rschema
   237         if 'fulltext_container' in self.values:
   235         entity = self.entity
       
   236         if 'fulltext_container' in entity.edited_attributes:
       
   237             ftiupdates = session.transaction_data.setdefault(
   238             ftiupdates = session.transaction_data.setdefault(
   238                 'fti_update_etypes', set())
   239                 'fti_update_etypes', set())
   239             for subjtype, objtype in rschema.rdefs:
   240             for subjtype, objtype in rschema.rdefs:
   240                 ftiupdates.add(subjtype)
   241                 ftiupdates.add(subjtype)
   241                 ftiupdates.add(objtype)
   242                 ftiupdates.add(objtype)
   242             UpdateFTIndexOp(session)
   243             UpdateFTIndexOp(session)
   243         if rschema.final or not 'inlined' in entity.edited_attributes:
   244         if not 'inlined' in self.values:
   244             return # nothing to do
   245             return # nothing to do
   245         inlined = entity.inlined
   246         inlined = self.values['inlined']
   246         # check in-lining is necessary / possible
   247         # check in-lining is necessary / possible
   247         if not entity.inlined_changed(inlined):
   248         if inlined:
   248             return # nothing to do
   249             self.entity.check_inlined_allowed()
   249         # inlined changed, make necessary physical changes!
   250         # inlined changed, make necessary physical changes!
   250         sqlexec = self.session.system_sql
   251         sqlexec = self.session.system_sql
   251         rtype = rschema.type
   252         rtype = rschema.type
   252         eidcolumn = SQL_PREFIX + 'eid'
   253         eidcolumn = SQL_PREFIX + 'eid'
   253         if not inlined:
   254         if not inlined:
   932         MemSchemaCWRTypeAdd(self._cw, rtype)
   933         MemSchemaCWRTypeAdd(self._cw, rtype)
   933 
   934 
   934 
   935 
   935 class BeforeUpdateCWRTypeHook(DelCWRTypeHook):
   936 class BeforeUpdateCWRTypeHook(DelCWRTypeHook):
   936     """check name change, handle final"""
   937     """check name change, handle final"""
   937     __regid__ = 'checkupdatecwrtype'
   938     __regid__ = 'syncupdatecwrtype'
   938     events = ('before_update_entity',)
   939     events = ('before_update_entity',)
   939 
   940 
   940     def __call__(self):
   941     def __call__(self):
   941         check_valid_changes(self._cw, self.entity)
       
   942 
       
   943 
       
   944 class AfterUpdateCWRTypeHook(DelCWRTypeHook):
       
   945     __regid__ = 'syncupdatecwrtype'
       
   946     events = ('after_update_entity',)
       
   947 
       
   948     def __call__(self):
       
   949         entity = self.entity
   942         entity = self.entity
       
   943         check_valid_changes(self._cw, entity)
   950         newvalues = {}
   944         newvalues = {}
   951         for prop in ('symmetric', 'inlined', 'fulltext_container'):
   945         for prop in ('symmetric', 'inlined', 'fulltext_container'):
   952             if prop in entity.edited_attributes:
   946             if prop in entity.edited_attributes:
   953                 newvalues[prop] = entity[prop]
   947                 old, new = hook.entity_oldnewvalue(entity, prop)
       
   948                 if old != new:
       
   949                     newvalues[prop] = entity[prop]
   954         if newvalues:
   950         if newvalues:
   955             rschema = self._cw.vreg.schema.rschema(entity.name)
   951             rschema = self._cw.vreg.schema.rschema(entity.name)
   956             SourceDbCWRTypeUpdate(self._cw, rschema=rschema, entity=entity)
   952             SourceDbCWRTypeUpdate(self._cw, rschema=rschema, entity=entity,
       
   953                                   values=newvalues)
   957             MemSchemaCWRTypeUpdate(self._cw, rschema=rschema, values=newvalues)
   954             MemSchemaCWRTypeUpdate(self._cw, rschema=rschema, values=newvalues)
   958 
   955 
   959 
   956 
   960 class AfterDelRelationTypeHook(SyncSchemaHook):
   957 class AfterDelRelationTypeHook(SyncSchemaHook):
   961     """before deleting a CWAttribute or CWRelation entity:
   958     """before deleting a CWAttribute or CWRelation entity:
  1031 
  1028 
  1032 
  1029 
  1033 class AfterUpdateCWRDefHook(SyncSchemaHook):
  1030 class AfterUpdateCWRDefHook(SyncSchemaHook):
  1034     __regid__ = 'syncaddcwattribute'
  1031     __regid__ = 'syncaddcwattribute'
  1035     __select__ = SyncSchemaHook.__select__ & implements('CWAttribute',
  1032     __select__ = SyncSchemaHook.__select__ & implements('CWAttribute',
  1036                                                                'CWRelation')
  1033                                                         'CWRelation')
  1037     events = ('after_update_entity',)
  1034     events = ('before_update_entity',)
  1038 
  1035 
  1039     def __call__(self):
  1036     def __call__(self):
  1040         entity = self.entity
  1037         entity = self.entity
  1041         if self._cw.deleted_in_transaction(entity.eid):
  1038         if self._cw.deleted_in_transaction(entity.eid):
  1042             return
  1039             return
  1047             if prop == 'constraints':
  1044             if prop == 'constraints':
  1048                 continue
  1045                 continue
  1049             if prop == 'order':
  1046             if prop == 'order':
  1050                 prop = 'ordernum'
  1047                 prop = 'ordernum'
  1051             if prop in entity.edited_attributes:
  1048             if prop in entity.edited_attributes:
  1052                 newvalues[prop] = entity[prop]
  1049                 old, new = hook.entity_oldnewvalue(entity, prop)
       
  1050                 if old != new:
       
  1051                     newvalues[prop] = entity[prop]
  1053         if newvalues:
  1052         if newvalues:
  1054             subjtype = entity.stype.name
  1053             subjtype = entity.stype.name
  1055             MemSchemaRDefUpdate(self._cw, kobj=(subjtype, desttype),
  1054             MemSchemaRDefUpdate(self._cw, kobj=(subjtype, desttype),
  1056                                 rschema=rschema, values=newvalues)
  1055                                 rschema=rschema, values=newvalues)
  1057             SourceDbRDefUpdate(self._cw, kobj=(subjtype, desttype),
  1056             SourceDbRDefUpdate(self._cw, kobj=(subjtype, desttype),