workflow::case::action::enable (private)

 workflow::case::action::enable -case_id case_id -action_id action_id \
    [ -parent_enabled_action_id parent_enabled_action_id ] \
    [ -user_id user_id ] [ -assigned ] [ -assignees assignees ]

Defined in packages/workflow/tcl/case-procs.tcl

Update the workflow_case_enabled_actions table to say that the action is now enabled. Will automatically fire an automatic action. Does not flush the cache. Should only be called indirectly through the workflow API.

Switches:
-case_id (required)
-action_id (required)
-parent_enabled_action_id (optional)
-user_id (optional)
-assigned (optional, boolean)
-assignees (optional)
Author:
Lars Pind <lars@collaboraid.biz>

Partial Call Graph (max 5 caller/called nodes):
%3 workflow::case::state_changed_handler workflow::case::state_changed_handler (private) workflow::case::action::enable workflow::case::action::enable workflow::case::state_changed_handler->workflow::case::action::enable db_boolean db_boolean (public) workflow::case::action::enable->db_boolean db_dml db_dml (public) workflow::case::action::enable->db_dml db_nextval db_nextval (public) workflow::case::action::enable->db_nextval db_string db_string (public) workflow::case::action::enable->db_string db_transaction db_transaction (public) workflow::case::action::enable->db_transaction

Testcases:
No testcase defined.
Source code:
    workflow::action::get -action_id $action_id -array action
    set workflow_id $action(workflow_id)

    db_transaction {
        set enabled_action_id [db_nextval "workflow_case_enbl_act_seq"]

        if { $action(trigger_type) ne "user" } {
            # Action can only be assigned if it has trigger_type user
            # But its children can be assigned, so we keep the original assigned_p variable
            set db_assigned_p f
        } else {
            set db_assigned_p [db_boolean $assigned_p]
        }
        
        # Insert the enabled action row
        db_dml insert_enabled {}

        # Insert assignees
        if { ([info exists assignees] && $assignees ne "") } {
            foreach party_id $assignees {
                db_dml insert_assignee {
                    insert into workflow_case_action_assignees (enabled_action_id, party_id)
                    values (:enabled_action_id, :party_id)
                }
            }
        }

        switch $action(trigger_type) {
            "workflow" {
                # Find and execute child init action
                set child_init_id [db_string child_init { 
                    select action_id
                    from   workflow_actions 
                    where  parent_action_id = :action_id
                    and    trigger_type = 'init'
                } -default {}]
                
                if { $child_init_id eq "" } {
                    error "Child workflow for action $action(pretty_name) doesn't have an action with trigger_type = 'init', or it has more than one."
                }
                
                workflow::action::fsm::get -action_id $child_init_id -array initial_action
                if { $initial_action(new_state) eq "" } {
                    error "Initial action with short_name \"$initial_action(short_name)\" does not have any new_state. In order to be an initial state, it must have new_state set."
                }

                workflow::case::action::execute  -no_notification  -initial  -case_id $case_id  -action_id $child_init_id  -parent_enabled_action_id $enabled_action_id  -user_id $user_id
            }
            "parallel" {
                # Find and enable child actions
                foreach child_action_id $action(child_action_ids) {
                    workflow::case::action::enable  -case_id $case_id  -action_id $child_action_id  -parent_enabled_action_id $enabled_action_id  -user_id $user_id  -assigned=$assigned_p
                }
            }
            "dynamic" {
                # Find and enable all child actions, once for each party assigned to the role
                foreach child_action_id $action(child_action_ids) {
                    
                    set child_role_id [workflow::action::get_element  -action_id $child_action_id  -element assigned_role_id]
                    
                    set parties [workflow::case::role::get_assignees  -case_id $case_id  -role_id $child_role_id]
                    
                    
                    foreach elm $parties {
                        array unset party 
                        array set party $elm
                        
                        workflow::case::action::enable  -case_id $case_id  -action_id $child_action_id  -parent_enabled_action_id $enabled_action_id  -user_id $user_id  -assigned=$assigned_p  -assignees $party(party_id)
                    }
                }
            }
            "auto" {
                workflow::case::action::execute  -no_perm_check  -enabled_action_id $enabled_action_id  -user_id $user_id
            }
        }
    }
Generic XQL file:
packages/workflow/tcl/case-procs.xql

PostgreSQL XQL file:
<fullquery name="workflow::case::action::enable.insert_enabled">
    <querytext>
        insert into workflow_case_enabled_actions
              (enabled_action_id, 
               case_id, 
               action_id, 
               parent_enabled_action_id, 
               assigned_p, 
               execution_time)
        select :enabled_action_id, 
               :case_id, 
               :action_id, 
               :parent_enabled_action_id, 
               :db_assigned_p, 
               current_timestamp + a.timeout
        from   workflow_actions a
        where  a.action_id = :action_id
    </querytext>
</fullquery>
packages/workflow/tcl/case-procs-postgresql.xql

Oracle XQL file:
<fullquery name="workflow::case::action::enable.insert_enabled">
    <querytext>
        insert into workflow_case_enabled_actions
              (enabled_action_id, 
               case_id, 
               action_id, 
               parent_enabled_action_id, 
               assigned_p, 
               execution_time)
        select :enabled_action_id, 
               :case_id, 
               :action_id, 
               :parent_enabled_action_id, 
               :db_assigned_p, 
               sysdate + a.timeout_seconds/(24*60*60)
        from   workflow_actions a
        where  a.action_id = :action_id
    </querytext>
</fullquery>
packages/workflow/tcl/case-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: