server/migractions.py
changeset 3589 a5432f99f2d9
parent 3412 368c68ffb99e
parent 3582 28547f21308e
child 3659 993997b4b41d
equal deleted inserted replaced
3536:f6c9a5df80fb 3589:a5432f99f2d9
   624         rql = 'SET X %s VAL WHERE X is %s, X %s VAL' % (newname, etype, oldname)
   624         rql = 'SET X %s VAL WHERE X is %s, X %s VAL' % (newname, etype, oldname)
   625         card = eschema.rproperty(newname, 'cardinality')[0]
   625         card = eschema.rproperty(newname, 'cardinality')[0]
   626         if card == '1':
   626         if card == '1':
   627             rql += ', NOT X %s NULL' % oldname
   627             rql += ', NOT X %s NULL' % oldname
   628         self.rqlexec(rql, ask_confirm=self.verbosity>=2)
   628         self.rqlexec(rql, ask_confirm=self.verbosity>=2)
       
   629         # XXX if both attributes fulltext indexed, should skip fti rebuild
       
   630         # XXX if old attribute was fti indexed but not the new one old value
       
   631         # won't be removed from the index (this occurs on other kind of
       
   632         # fulltextindexed change...)
   629         self.cmd_drop_attribute(etype, oldname, commit=commit)
   633         self.cmd_drop_attribute(etype, oldname, commit=commit)
   630 
   634 
   631     def cmd_add_entity_type(self, etype, auto=True, commit=True):
   635     def cmd_add_entity_type(self, etype, auto=True, commit=True):
   632         """register a new entity type
   636         """register a new entity type
   633 
   637 
   952                 # cleanup unused constraints
   956                 # cleanup unused constraints
   953                 self.rqlexec('DELETE CWConstraint C WHERE NOT X constrained_by C')
   957                 self.rqlexec('DELETE CWConstraint C WHERE NOT X constrained_by C')
   954         if commit:
   958         if commit:
   955             self.commit()
   959             self.commit()
   956 
   960 
   957     @deprecated('[3.4] use sync_schema_props_perms(ertype, syncprops=False)')
   961     @deprecated('[3.2] use sync_schema_props_perms(ertype, syncprops=False)')
   958     def cmd_synchronize_permissions(self, ertype, commit=True):
   962     def cmd_synchronize_permissions(self, ertype, commit=True):
   959         self.cmd_sync_schema_props_perms(ertype, syncprops=False, commit=commit)
   963         self.cmd_sync_schema_props_perms(ertype, syncprops=False, commit=commit)
   960 
   964 
   961     # Workflows handling ######################################################
   965     # Workflows handling ######################################################
   962 
   966 
   963     def cmd_add_workflow(self, name, wfof, default=True, commit=False,
   967     def cmd_add_workflow(self, name, wfof, default=True, commit=False,
   964                          **kwargs):
   968                          **kwargs):
       
   969         """
       
   970         create a new workflow and links it to entity types
       
   971          :type name: unicode
       
   972          :param name: name of the workflow
       
   973 
       
   974          :type wfof: string or list/tuple of strings
       
   975          :param wfof: entity type(s) having this workflow
       
   976 
       
   977          :type default: bool
       
   978          :param default: tells wether this is the default workflow
       
   979                    for the specified entity type(s); set it to false in
       
   980                    the case of a subworkflow
       
   981 
       
   982          :rtype: `Workflow`
       
   983         """
   965         self.session.set_pool() # ensure pool is set
   984         self.session.set_pool() # ensure pool is set
   966         wf = self.cmd_create_entity('Workflow', name=unicode(name),
   985         wf = self.cmd_create_entity('Workflow', name=unicode(name),
   967                                     **kwargs)
   986                                     **kwargs)
   968         if not isinstance(wfof, (list, tuple)):
   987         if not isinstance(wfof, (list, tuple)):
   969             wfof = (wfof,)
   988             wfof = (wfof,)
   989                             {'et': etypes[0]})
  1008                             {'et': etypes[0]})
   990         if rset:
  1009         if rset:
   991             return rset.get_entity(0, 0)
  1010             return rset.get_entity(0, 0)
   992         return self.cmd_add_workflow('%s workflow' % ';'.join(etypes), etypes)
  1011         return self.cmd_add_workflow('%s workflow' % ';'.join(etypes), etypes)
   993 
  1012 
   994     @deprecated('use add_workflow and Workflow.add_state method')
  1013     @deprecated('[3.5] use add_workflow and Workflow.add_state method')
   995     def cmd_add_state(self, name, stateof, initial=False, commit=False, **kwargs):
  1014     def cmd_add_state(self, name, stateof, initial=False, commit=False, **kwargs):
   996         """method to ease workflow definition: add a state for one or more
  1015         """method to ease workflow definition: add a state for one or more
   997         entity type(s)
  1016         entity type(s)
   998         """
  1017         """
   999         wf = self._get_or_create_wf(stateof)
  1018         wf = self._get_or_create_wf(stateof)
  1000         state = wf.add_state(name, initial, **kwargs)
  1019         state = wf.add_state(name, initial, **kwargs)
  1001         if commit:
  1020         if commit:
  1002             self.commit()
  1021             self.commit()
  1003         return state.eid
  1022         return state.eid
  1004 
  1023 
  1005     @deprecated('use add_workflow and Workflow.add_transition method')
  1024     @deprecated('[3.5] use add_workflow and Workflow.add_transition method')
  1006     def cmd_add_transition(self, name, transitionof, fromstates, tostate,
  1025     def cmd_add_transition(self, name, transitionof, fromstates, tostate,
  1007                            requiredgroups=(), conditions=(), commit=False, **kwargs):
  1026                            requiredgroups=(), conditions=(), commit=False, **kwargs):
  1008         """method to ease workflow definition: add a transition for one or more
  1027         """method to ease workflow definition: add a transition for one or more
  1009         entity type(s), from one or more state and to a single state
  1028         entity type(s), from one or more state and to a single state
  1010         """
  1029         """
  1013                                conditions, **kwargs)
  1032                                conditions, **kwargs)
  1014         if commit:
  1033         if commit:
  1015             self.commit()
  1034             self.commit()
  1016         return tr.eid
  1035         return tr.eid
  1017 
  1036 
  1018     @deprecated('use Transition.set_transition_permissions method')
  1037     @deprecated('[3.5] use Transition.set_transition_permissions method')
  1019     def cmd_set_transition_permissions(self, treid,
  1038     def cmd_set_transition_permissions(self, treid,
  1020                                        requiredgroups=(), conditions=(),
  1039                                        requiredgroups=(), conditions=(),
  1021                                        reset=True, commit=False):
  1040                                        reset=True, commit=False):
  1022         """set or add (if `reset` is False) groups and conditions for a
  1041         """set or add (if `reset` is False) groups and conditions for a
  1023         transition
  1042         transition
  1026         tr = self.session.entity_from_eid(treid)
  1045         tr = self.session.entity_from_eid(treid)
  1027         tr.set_transition_permissions(requiredgroups, conditions, reset)
  1046         tr.set_transition_permissions(requiredgroups, conditions, reset)
  1028         if commit:
  1047         if commit:
  1029             self.commit()
  1048             self.commit()
  1030 
  1049 
  1031     @deprecated('use entity.fire_transition("transition") or entity.change_state("state")')
  1050     @deprecated('[3.5] use entity.fire_transition("transition") or entity.change_state("state")')
  1032     def cmd_set_state(self, eid, statename, commit=False):
  1051     def cmd_set_state(self, eid, statename, commit=False):
  1033         self.session.set_pool() # ensure pool is set
  1052         self.session.set_pool() # ensure pool is set
  1034         self.session.entity_from_eid(eid).change_state(statename)
  1053         self.session.entity_from_eid(eid).change_state(statename)
  1035         if commit:
  1054         if commit:
  1036             self.commit()
  1055             self.commit()