hooks/syncschema.py
branchstable
changeset 4927 19fd1952ad63
parent 4839 f482dbdf2f8c
child 4928 cbca73dc9753
equal deleted inserted replaced
4926:626d31035662 4927:19fd1952ad63
   185         # do this last !
   185         # do this last !
   186         hook.Operation.__init__(self, session, **kwargs)
   186         hook.Operation.__init__(self, session, **kwargs)
   187         # every schema operation is triggering a schema update
   187         # every schema operation is triggering a schema update
   188         MemSchemaNotifyChanges(session)
   188         MemSchemaNotifyChanges(session)
   189 
   189 
   190     def prepare_constraints(self, subjtype, rtype, objtype):
   190     def prepare_constraints(self, rdef):
   191         rdef = rtype.rdef(subjtype, objtype)
   191         # if constraints is already a list, reuse it (we're updating multiple
   192         constraints = rdef.constraints
   192         # constraints of the same rdef in the same transactions
   193         self.constraints = list(constraints)
   193         if not isinstance(rdef.constraints, list):
   194         rdef.constraints = self.constraints
   194             rdef.constraints = list(rdef.constraints)
       
   195         self.constraints = rdef.constraints
   195 
   196 
   196 
   197 
   197 class MemSchemaEarlyOperation(MemSchemaOperation):
   198 class MemSchemaEarlyOperation(MemSchemaOperation):
   198     def insert_index(self):
   199     def insert_index(self):
   199         """schema operation which are inserted at the begining of the queue
   200         """schema operation which are inserted at the begining of the queue
   663         # so there is nothing to do here
   664         # so there is nothing to do here
   664         if self.session.added_in_transaction(rdef.eid):
   665         if self.session.added_in_transaction(rdef.eid):
   665             self.cancelled = True
   666             self.cancelled = True
   666             return
   667             return
   667         rdef = self.session.vreg.schema.schema_by_eid(rdef.eid)
   668         rdef = self.session.vreg.schema.schema_by_eid(rdef.eid)
       
   669         self.prepare_constraints(rdef)
   668         subjtype, rtype, objtype = rdef.as_triple()
   670         subjtype, rtype, objtype = rdef.as_triple()
   669         self.prepare_constraints(subjtype, rtype, objtype)
       
   670         cstrtype = self.entity.type
   671         cstrtype = self.entity.type
   671         self.cstr = rtype.rdef(subjtype, objtype).constraint_by_type(cstrtype)
   672         self.cstr = rtype.rdef(subjtype, objtype).constraint_by_type(cstrtype)
   672         self.newcstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value)
   673         self.newcstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value)
   673         self.newcstr.eid = self.entity.eid
   674         self.newcstr.eid = self.entity.eid
   674 
   675 
   686 
   687 
   687     has to be called before SourceDbCWConstraintDel
   688     has to be called before SourceDbCWConstraintDel
   688     """
   689     """
   689     rtype = subjtype = objtype = None # make pylint happy
   690     rtype = subjtype = objtype = None # make pylint happy
   690     def precommit_event(self):
   691     def precommit_event(self):
   691         self.prepare_constraints(self.subjtype, self.rtype, self.objtype)
   692         self.prepare_constraints(self.rdef)
   692 
   693 
   693     def commit_event(self):
   694     def commit_event(self):
   694         self.constraints.remove(self.cstr)
   695         self.constraints.remove(self.cstr)
   695 
   696 
   696 
   697 
  1083         try:
  1084         try:
  1084             cstr = rdef.constraint_by_type(entity.type)
  1085             cstr = rdef.constraint_by_type(entity.type)
  1085         except IndexError:
  1086         except IndexError:
  1086             self._cw.critical('constraint type no more accessible')
  1087             self._cw.critical('constraint type no more accessible')
  1087         else:
  1088         else:
  1088             subjtype, rtype, objtype = rdef.as_triple()
  1089             SourceDbCWConstraintDel(self._cw, cstr=cstr,
  1089             SourceDbCWConstraintDel(self._cw, subjtype=subjtype, rtype=rtype,
  1090                                     subjtype=rdef.subject, rtype=rdef.rtype)
  1090                                     objtype=objtype, cstr=cstr)
  1091             MemSchemaCWConstraintDel(self._cw, rdef=rdef, cstr=cstr)
  1091             MemSchemaCWConstraintDel(self._cw, subjtype=subjtype, rtype=rtype,
       
  1092                                      objtype=objtype, cstr=cstr)
       
  1093 
  1092 
  1094 
  1093 
  1095 # permissions synchronization hooks ############################################
  1094 # permissions synchronization hooks ############################################
  1096 
  1095 
  1097 class AfterAddPermissionHook(SyncSchemaHook):
  1096 class AfterAddPermissionHook(SyncSchemaHook):