workflow::role::edit (public)
workflow::role::edit [ -operation operation ] [ -role_id role_id ] \ [ -workflow_id workflow_id ] [ -array array ] [ -internal ] \ [ -no_complain ] [ -handlers handlers ]
Defined in packages/workflow/tcl/role-procs.tcl
Edit a workflow role. Attributes of the array are: short_name pretty_name sort_order callbacks.
- Switches:
- -operation (optional, defaults to
"update"
)- insert, update, delete
- -role_id (optional)
- For update/delete: The role to update or delete. For insert: Optionally specify a pre-generated role_id for the role.
- -workflow_id (optional)
- For update/delete: Optionally specify the workflow_id. If not specified, we will execute a query to find it. For insert: The workflow_id of the new role.
- -array (optional)
- For insert/update: Name of an array in the caller's namespace with attributes to insert/update.
- -internal (optional, boolean)
- Set this flag if you're calling this proc from within the corresponding proc for a particular workflow model. Will cause this proc to not flush the cache or call workflow::definition_changed_handler, which the caller must then do.
- -no_complain (optional, boolean)
- Silently ignore extra attributes that we don't know how to handle.
- -handlers (optional)
- Returns:
- role_id
- Authors:
- Peter Marklund
- Lars Pind <lars@collaboraid.biz>
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: switch $operation { update - delete { if { $role_id eq "" } { error "You must specify the role_id of the role to $operation." } } insert {} default { error "Illegal operation '$operation'" } } switch $operation { insert - update { upvar 1 $array row if { ![array exists row] } { error "Array $array does not exist or is not an array" } foreach name [array names row] { set missing_elm($name) 1 } } } switch $operation { insert { if { $workflow_id eq "" } { error "You must supply workflow_id" } # Default sort_order if { (![info exists row(sort_order)] || $row(sort_order) eq "") } { set row(sort_order) [workflow::default_sort_order -workflow_id $workflow_id -table_name "workflow_roles"] } # Default short_name on insert if { ![info exists row(short_name)] } { set row(short_name) {} } } update { if { $workflow_id eq "" } { set workflow_id [workflow::role::get_element -role_id $role_id -element workflow_id] } } } # Parse column values switch $operation { insert - update { set update_clauses [list] set insert_names [list] set insert_values [list] # Handle columns in the workflow_roles table foreach attr { short_name pretty_name sort_order } { if { [info exists row($attr)] } { set varname attr_$attr # Convert the Tcl value to something we can use in the query switch $attr { short_name { if { (![info exists row(pretty_name)] || $row(pretty_name) eq "") } { if { $row(short_name) eq "" } { error "You cannot $operation with an empty short_name without also setting pretty_name" } else { set row(pretty_name) {} } } set $varname [workflow::role::generate_short_name -workflow_id $workflow_id -pretty_name $row(pretty_name) -short_name $row(short_name) -role_id $role_id] } default { set $varname $row($attr) } } # Add the column to the insert/update statement switch $attr { default { lappend update_clauses "$attr = :$varname" lappend insert_names $attr lappend insert_values :$varname } } if { [info exists missing_elm($attr)] } { unset missing_elm($attr) } } } } } db_transaction { # Sort_order switch $operation { insert - update { if { [info exists row(sort_order)] } { workflow::role::update_sort_order -workflow_id $workflow_id -sort_order $row(sort_order) } } } # Do the insert/update/delete switch $operation { insert { if { $role_id eq "" } { set role_id [db_nextval "workflow_roles_seq"] } lappend insert_names role_id lappend insert_values :role_id lappend insert_names workflow_id lappend insert_values :workflow_id db_dml insert_role " insert into workflow_roles ([join $insert_names ", "]) values ([join $insert_values ", "]) " } update { if { [llength $update_clauses] > 0 } { db_dml update_role " update workflow_roles set [join $update_clauses ", "] where role_id = :role_id " } } delete { db_dml delete_role { delete from workflow_roles where role_id = :role_id } } } switch $operation { insert - update { # Callbacks if { [info exists row(callbacks)] } { db_dml delete_callbacks { delete from workflow_role_callbacks where role_id = :role_id } foreach callback_name $row(callbacks) { workflow::role::callback_insert -role_id $role_id -name $callback_name } unset missing_elm(callbacks) } # Check that there are no unknown attributes if { [array size missing_elm] > 0 && !$no_complain } { error "Trying to set illegal role attributes: [join [array names missing_elm] ", "]" } } } if { !$internal_p } { workflow::definition_changed_handler -workflow_id $workflow_id } } return $role_idXQL Not present: PostgreSQL, Oracle Generic XQL file: packages/workflow/tcl/role-procs.xql