crm_run_state_machine

one of the documented procedures in this installation of the ACS
Usage:
crm_run_state_machine
What it does:
Updates all the users' crm_state information.
Defined in: /web/philip/tcl/crm-defs.tcl

Source code:


    set dbs [ns_db gethandle subquery 2]
    set db [lindex $dbs 0]
    set sub_db [lindex $dbs 1]

    ns_log Notice "Starting CRM update"

    set now [database_to_tcl_string $db "select to_char(sysdate, 'YYYYMMDDHH24MISS') from dual"]

    # Sleep for a second, so that we don't inadvertently step on our toes below.
    ns_sleep 1

    set selection [ns_db select $db "select state_name, next_state, transition_condition
from crm_state_transitions
order by triggering_order"]

    with_transaction $sub_db {
	while { [ns_db getrow $db $selection] } {
	    set_variables_after_query
	    
	    ns_db dml $sub_db "update users
set crm_state = '$next_state', crm_state_entered_date = sysdate
where crm_state = '$state_name'
and crm_state_entered_date < to_date('$now', 'YYYYMMDDHH24MISS')
and ($transition_condition)"
        }
    } {
        ns_log Bug "CRM update failed: $errmsg"
    }


    ns_db releasehandle $db
    ns_db releasehandle $sub_db
    ns_log Notice "CRM update done"


philg@mit.edu