Index: openacs-4/packages/workflow/sql/oracle/workflow-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/oracle/workflow-tables-create.sql,v diff -u -r1.11 -r1.12 --- openacs-4/packages/workflow/sql/oracle/workflow-tables-create.sql 8 Jan 2004 13:23:08 -0000 1.11 +++ openacs-4/packages/workflow/sql/oracle/workflow-tables-create.sql 8 Jan 2004 16:00:40 -0000 1.12 @@ -167,6 +167,10 @@ -- A value of 0 means immediately, null means never. -- Other values mean x amount of time after having become enabled timeout_seconds integer, + child_workflow_id integer + constraint wf_acns_child_workflow_fk + references workflows(workflow_id) + on delete cascade, constraint wf_actions_short_name_un unique (workflow_id, short_name), constraint wf_actions_pretty_name_un @@ -243,38 +247,23 @@ ); -- TODO: Test these -create table workflow_action_children( - child_id integer - constraint wf_action_children_pk - primary key, - action_id integer - constraint wf_action_children_nn - not null - constraint wf_action_children_action_fk - references workflow_actions(action_id) - on delete cascade, - child_workflow integer - constraint wf_action_children_workflow_fk - references workflows(workflow_id) - on delete cascade -); - create table workflow_action_child_role_map( - child_id integer + action_id integer constraint wf_act_child_rl_map_child_fk - references workflow_action_children(child_id), - parent_role integer - constraint wf_act_child_rl_map_prnt_rl_fk - references workflow_roles(role_id), - child_role integer + references workflow_actions(action_id), + child_role_id integer constraint wf_act_child_rl_map_chld_rl_fk references workflow_roles(role_id), + parent_role_id integer + constraint wf_act_child_rl_map_prnt_rl_fk + references workflow_roles(role_id), mapping_type char(40) constraint wf_act_child_rl_map_type_ck check (mapping_type in - ('per_role','per_user')), + ('per_role','per_user')) + default 'per_role', constraint wf_act_chld_rl_map_pk - primary key (child_id, parent_role) + primary key (action_id, child_role_id) ); comment on column workflow_action_child_role_map.mapping_type is ' @@ -283,6 +272,8 @@ If more than one child_role has a mapping_type other than per_role, the cartesian product of these roles will be created. '; + + --------------------------------- -- Workflow level, Finite State Machine Model --------------------------------- Index: openacs-4/packages/workflow/sql/oracle/upgrade/upgrade-1.2-2.0d1.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/oracle/upgrade/upgrade-1.2-2.0d1.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/workflow/sql/oracle/upgrade/upgrade-1.2-2.0d1.sql 8 Jan 2004 13:23:08 -0000 1.3 +++ openacs-4/packages/workflow/sql/oracle/upgrade/upgrade-1.2-2.0d1.sql 8 Jan 2004 16:00:40 -0000 1.4 @@ -74,38 +74,29 @@ -- Adding recursive actions -- TODO: Test these -create table workflow_action_children( - child_id integer - constraint wf_action_children_pk - primary key, - action_id integer - constraint wf_action_children_nn - not null - constraint wf_action_children_action_fk - references workflow_actions(action_id) - on delete cascade, - child_workflow integer - constraint wf_action_children_workflow_fk - references workflows(workflow_id) - on delete cascade -); +alter table workflow_actions add ( + child_workflow_id integer + constraint wf_acns_child_workflow_fk + references workflows(workflow_id) + on delete cascade); create table workflow_action_child_role_map( - child_id integer + action_id integer constraint wf_act_child_rl_map_child_fk - references workflow_action_children(child_id), - parent_role integer - constraint wf_act_child_rl_map_prnt_rl_fk - references workflow_roles(role_id), - child_role integer + references workflow_actions(action_id), + child_role_id integer constraint wf_act_child_rl_map_chld_rl_fk references workflow_roles(role_id), + parent_role_id integer + constraint wf_act_child_rl_map_prnt_rl_fk + references workflow_roles(role_id), mapping_type char(40) constraint wf_act_child_rl_map_type_ck check (mapping_type in - ('per_role','per_user')), + ('per_role','per_user')) + default 'per_role', constraint wf_act_chld_rl_map_pk - primary key (child_id, parent_role) + primary key (action_id, child_role_id) ); comment on column workflow_action_child_role_map.mapping_type is ' Index: openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql,v diff -u -r1.21 -r1.22 --- openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql 8 Jan 2004 13:23:08 -0000 1.21 +++ openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql 8 Jan 2004 16:00:40 -0000 1.22 @@ -178,6 +178,10 @@ -- A value of 0 means immediately, null means never. -- Other values mean x amount of time after having become enabled timeout interval, + child_workflow_id integer + constraint wf_acns_child_workflow_fk + references workflows(workflow_id) + on delete cascade, constraint wf_actions_short_name_un unique (workflow_id, short_name), constraint wf_actions_pretty_name_un @@ -260,38 +264,23 @@ on delete cascade ); -create table workflow_action_children( - child_id integer - constraint wf_action_children_pk - primary key, - action_id integer - constraint wf_action_children_nn - not null - constraint wf_action_children_action_fk - references workflow_actions(action_id) - on delete cascade, - child_workflow integer - constraint wf_action_children_workflow_fk - references workflows(workflow_id) - on delete cascade -); - create table workflow_action_child_role_map( - child_id integer + action_id integer constraint wf_act_child_rl_map_child_fk - references workflow_action_children(child_id), - parent_role integer - constraint wf_act_child_rl_map_prnt_rl_fk - references workflow_roles(role_id), - child_role integer + references workflow_actions(action_id), + child_role_id integer constraint wf_act_child_rl_map_chld_rl_fk references workflow_roles(role_id), + parent_role_id integer + constraint wf_act_child_rl_map_prnt_rl_fk + references workflow_roles(role_id), mapping_type char(40) constraint wf_act_child_rl_map_type_ck check (mapping_type in - ('per_role','per_user')), + ('per_role','per_user')) + default 'per_role', constraint wf_act_chld_rl_map_pk - primary key (child_id, parent_role) + primary key (action_id, child_role_id) ); comment on column workflow_action_child_role_map.mapping_type is ' Index: openacs-4/packages/workflow/sql/postgresql/workflow-tables-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/workflow-tables-drop.sql,v diff -u -r1.8 -r1.9 --- openacs-4/packages/workflow/sql/postgresql/workflow-tables-drop.sql 3 Oct 2003 10:12:46 -0000 1.8 +++ openacs-4/packages/workflow/sql/postgresql/workflow-tables-drop.sql 8 Jan 2004 16:00:40 -0000 1.9 @@ -55,6 +55,7 @@ drop table workflow_fsm_actions; drop table workflow_initial_action; drop table workflow_fsm_states; +drop table workflow_action_child_role_map; drop table workflow_action_callbacks; drop table workflow_action_privileges; drop table workflow_action_allowed_roles; Index: openacs-4/packages/workflow/sql/postgresql/upgrade/upgrade-1.2-2.0d1.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/upgrade/upgrade-1.2-2.0d1.sql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/workflow/sql/postgresql/upgrade/upgrade-1.2-2.0d1.sql 8 Jan 2004 13:23:08 -0000 1.4 +++ openacs-4/packages/workflow/sql/postgresql/upgrade/upgrade-1.2-2.0d1.sql 8 Jan 2004 16:00:41 -0000 1.5 @@ -66,38 +66,29 @@ -- Adding recursive actions -create table workflow_action_children( - child_id integer - constraint wf_action_children_pk - primary key, - action_id integer - constraint wf_action_children_nn - not null - constraint wf_action_children_action_fk - references workflow_actions(action_id) - on delete cascade, - child_workflow integer - constraint wf_action_children_workflow_fk - references workflows(workflow_id) - on delete cascade -); +alter table workflow_actions add + child_workflow_id integer + constraint wf_acns_child_workflow_fk + references workflows(workflow_id) + on delete cascade; create table workflow_action_child_role_map( - child_id integer + action_id integer constraint wf_act_child_rl_map_child_fk - references workflow_action_children(child_id), - parent_role integer - constraint wf_act_child_rl_map_prnt_rl_fk - references workflow_roles(role_id), - child_role integer + references workflow_actions(action_id), + child_role_id integer constraint wf_act_child_rl_map_chld_rl_fk references workflow_roles(role_id), + parent_role_id integer + constraint wf_act_child_rl_map_prnt_rl_fk + references workflow_roles(role_id), mapping_type char(40) constraint wf_act_child_rl_map_type_ck check (mapping_type in - ('per_role','per_user')), + ('per_role','per_user')) + default 'per_role', constraint wf_act_chld_rl_map_pk - primary key (child_id, parent_role) + primary key (action_id, child_role_id) ); comment on column workflow_action_child_role_map.mapping_type is ' Index: openacs-4/packages/workflow/tcl/action-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/action-procs-postgresql.xql,v diff -u -r1.6 -r1.7 --- openacs-4/packages/workflow/tcl/action-procs-postgresql.xql 8 Jan 2004 12:33:21 -0000 1.6 +++ openacs-4/packages/workflow/tcl/action-procs-postgresql.xql 8 Jan 2004 16:00:41 -0000 1.7 @@ -2,17 +2,6 @@ postgresql7.2 - - - insert into workflow_actions - (action_id, workflow_id, sort_order, short_name, pretty_name, pretty_past_tense, - edit_fields, assigned_role, always_enabled_p, description, description_mime_type, timeout) - values (:action_id, :workflow_id, :sort_order, :short_name, :pretty_name, :pretty_past_tense, - :edit_fields, :assigned_role_id, :always_enabled_p, :description, :description_mime_type, - [ad_decode $timeout_seconds "" "null" "interval '$timeout_seconds seconds'"]) - - - timeout @@ -45,7 +34,8 @@ fa.new_state as new_state_id, (select short_name from workflow_fsm_states where state_id = fa.new_state) as new_state, a.description, - a.description_mime_type + a.description_mime_type, + a.child_workflow_id from workflow_actions a left outer join workflow_fsm_actions fa on (a.action_id = fa.action_id) where a.workflow_id = :workflow_id Index: openacs-4/packages/workflow/tcl/action-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/action-procs.tcl,v diff -u -r1.21 -r1.22 --- openacs-4/packages/workflow/tcl/action-procs.tcl 8 Jan 2004 10:55:32 -0000 1.21 +++ openacs-4/packages/workflow/tcl/action-procs.tcl 8 Jan 2004 16:00:41 -0000 1.22 @@ -143,6 +143,8 @@ allowed_roles initial_action_p callbacks + child_workflow_ids + child_role_map @param operation insert, update, delete @@ -223,6 +225,7 @@ always_enabled_p assigned_role timeout_seconds + child_workflow_id } { if { [info exists row($attr)] } { set varname attr_$attr @@ -380,6 +383,35 @@ unset missing_elm(callbacks) } + # Child role map + if { [info exists row(child_role_map)] } { + if { ![exists_and_not_null row(child_workflow_id)] } { + error "You cannot set child_role_map without also setting child_workflow_id." + } + + db_dml delete_callbacks { + delete from workflow_action_child_role_map + where action_id = :action_id + } + + foreach { child_role_short_name spec } $row(child_role_map) { + foreach { parent_role_short_name mapping_type } $spec {} + + set child_role_id [workflow::role::get_id \ + -workflow_id $row(child_workflow_id) \ + -short_name $child_role_short_name] + set parent_role_id [workflow::role::get_id \ + -workflow_id $workflow_id \ + -short_name $parent_role_short_name] + + db_dml insert_child_role_map { + insert into workflow_action_child_role_map (action_id, child_role_id, parent_role_id, mapping_type) + values (:action_id, :child_role_id, :parent_role_id, :mapping_type) + } + } + unset missing_elm(child_role_map) + } + # Check that there are no unknown attributes if { [llength [array names missing_elm]] > 0 } { error "Trying to set illegal action attributes: [join [array names missing_elm] ", "]" @@ -500,7 +532,7 @@ workflow_id, sort_order, short_name, pretty_name, pretty_past_tense, assigned_role (short_name), assigned_role_id, always_enabled_p, initial_action_p, description, - description_mime_type column values for an action. + description_mime_type, child_workflow_id column values for an action. @see workflow::action::get_all_info @see workflow::action::get_all_info_not_cached @@ -1284,6 +1316,9 @@ @author Peter Marklund } { + return [workflow::action::get_all_info_not_cached \ + -workflow_id $workflow_id] + return [util_memoize [list workflow::action::get_all_info_not_cached \ -workflow_id $workflow_id] [workflow::cache_timeout]] } @@ -1368,12 +1403,31 @@ } } + # Build array of child_role_map for all actions + array set child_role_map [list] + db_foreach select_child_role_map { + select m.action_id, + m.child_role_id, + m.parent_role_id, + m.mapping_type, + (select short_name from workflow_roles where role_id = m.child_role_id) as child_role_short_name, + (select short_name from workflow_roles where role_id = m.parent_role_id) as parent_role_short_name + from workflow_action_child_role_map m, + workflow_actions a + where m.action_id = a.action_id + and a.workflow_id = :workflow_id + } { + lappend child_role_map($action_id) $child_role_short_name [list $parent_role_short_name [string trim $mapping_type]] + } + # For each action_id, add to the array of that action the contents of the # sub arrays (callbacks, allowed_roles, allowed_role_ids, privileges) foreach action_id $action_ids { array set one_action $action_data($action_id) - - foreach array_name { privileges enabled_states enabled_state_ids assigned_states assigned_state_ids callbacks allowed_roles allowed_role_ids } { + + foreach array_name { + privileges enabled_states enabled_state_ids assigned_states assigned_state_ids callbacks allowed_roles allowed_role_ids + } { if { [info exists ${array_name}($action_id)] } { set one_action(${array_name}) [set ${array_name}($action_id)] } else { @@ -1395,6 +1449,12 @@ set one_action(callback_ids) [list] } + if { [info exists child_role_map($action_id)] } { + set one_action(child_role_map) $child_role_map($action_id) + } else { + set one_action(child_role_map) [list] + } + set action_data($action_id) [array get one_action] # Have to unset the array as otherwise array set will append to previous values