Index: openacs-4/packages/workflow/sql/oracle/workflow-procedural-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/oracle/workflow-procedural-create.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/workflow/sql/oracle/workflow-procedural-create.sql 12 Feb 2003 14:21:56 -0000 1.1 +++ openacs-4/packages/workflow/sql/oracle/workflow-procedural-create.sql 5 Mar 2003 17:17:18 -0000 1.2 @@ -10,7 +10,75 @@ --------------------------------- -- Workflow level, Generic Model --------------------------------- +create or replace package workflow_case +as + function get_pretty_state( + workflow_short_name in varchar, + object_id in integer + ) return varchar; + + function delete( + delete_case_id in integer + ) return integer; +end workflow_case; +/ +show errors + +create or replace package body workflow_case +as + function get_pretty_state( + workflow_short_name in varchar, + object_id in integer + ) return varchar + is + v_state_pretty varchar(4000); + v_object_id integer; + begin + v_object_id := object_id; + + select s.pretty_name + into v_state_pretty + from workflows w, + workflow_cases c, + workflow_case_fsm cfsm, + workflow_fsm_states s + where w.short_name = workflow_short_name + and c.object_id = v_object_id + and c.workflow_id = w.workflow_id + and cfsm.case_id = c.case_id + and s.state_id = cfsm.current_state; + + return v_state_pretty; + + end get_pretty_state; + + function delete( + delete_case_id in integer + ) return integer + is + begin + for rec in (select cr.item_id + from cr_items cr, workflow_case_log wcl + where cr.item_id = wcl.entry_id + and wcl.case_id = delete_case_id) + loop + delete from workflow_case_log where entry_id = rec.item_id; + content_item.delete(rec.item_id); + end loop; + + -- All workflow data cascades from the case id + delete from workflow_cases + where object_id = delete_case_id; + + return 0; + end delete; + +end workflow_case; +/ +show errors + + create or replace package workflow as function delete( @@ -32,16 +100,25 @@ / show errors --- package bodies create or replace package body workflow as function delete( delete_workflow_id in integer ) return integer is + foo integer; begin + -- Delete all cases first + for rec in (select case_id + from workflow_cases + where workflow_id = delete_workflow_id) + loop + foo := workflow_case.delete(rec.case_id); + end loop; + acs_object.delete(delete_workflow_id); + return 0; end delete; @@ -83,113 +160,95 @@ / show errors -create or replace package workflow_case -as function get_pretty_state( - workflow_short_name in varchar, - object_id in integer - ) return varchar; - -end workflow_case; +create or replace package workflow_case_log_entry +as + function new( + entry_id in integer, + case_id in integer, + action_id in integer, + comment in varchar, + comment_mime_type in varchar, + creation_user in integer, + creation_ip in varchar, + content_type in varchar default 'workflow_case_log_entry' + ) return integer; + +end workflow_case_log_entry; / show errors --- Function for getting the pretty state of a case -create or replace package body workflow_case +create or replace package body workflow_case_log_entry as - function get_pretty_state( - workflow_short_name in varchar, - object_id in integer - ) return varchar - is - v_state_pretty varchar(4000); - v_object_id integer; + function new( + entry_id in integer, + case_id in integer, + action_id in integer, + comment in varchar, + comment_mime_type in varchar, + creation_user in integer, + creation_ip in varchar, + content_type in varchar default 'workflow_case_log_entry' + ) return integer + is + v_name varchar2(4000); -- XXX aufflick fix this + v_action_short_name varchar2(4000); + v_action_pretty_past_tense varchar2(4000); + v_case_object_id integer; + v_item_id integer; + v_revision_id integer; begin - v_object_id := object_id; + select short_name, pretty_past_tense + into v_action_short_name, v_action_pretty_past_tense + from workflow_actions + where action_id = new.action_id; - select s.pretty_name - into v_state_pretty - from workflows w, - workflow_cases c, - workflow_case_fsm cfsm, - workflow_fsm_states s - where w.short_name = workflow_short_name - and c.object_id = v_object_id - and c.workflow_id = w.workflow_id - and cfsm.case_id = c.case_id - and s.state_id = cfsm.current_state; + -- use case object as context_id + select object_id + into v_case_object_id + from workflow_cases + where case_id = new.case_id; - return v_state_pretty; + -- build the unique name + if entry_id is not null then + v_item_id := entry_id; + else + select acs_object_id_seq.nextval into v_item_id from dual; + end if; + v_name := v_action_short_name || ' ' || v_item_id; - end get_pretty_state; + v_item_id := content_item.new ( + item_id => v_item_id, + name => v_name, + parent_id => 0, + title => v_action_pretty_past_tense, + creation_date => sysdate(), + creation_user => creation_user, + context_id => v_case_object_id, + creation_ip => creation_ip, + is_live => 't', + mime_type => comment_mime_type, + text => comment, + storage_type => 'text', + item_subtype => 'content_item', + content_type => content_type + ); -end workflow_case; -/ -show errors + -- insert the row into the single-column entry revision table + v_revision_id := content_item.get_live_revision (v_item_id); --- --create or replace package workflow_activity_log --- --as --- function new( --- case_id in integer, --- action_id in integer, --- comment_format in varchar --- ) return integer; + insert into workflow_case_log_rev (entry_rev_id) + values (v_revision_id); --- end workflow_activity_log; --- / --- show errors + -- insert into workflow-case-log + -- raise_application_error(-20000, 'about to insert ' || v_item_id || ',' || new.case_id || ',' || new.action_id); + insert into workflow_case_log (entry_id, case_id, action_id) + values (v_item_id, new.case_id, new.action_id); --- create or replace package body workflow_activity_log --- as --- function new( --- case_id in integer, --- action_id in integer, --- comment_format in varchar --- ) return integer --- is --- v_item_id cr_items.item_id%TYPE; --- v_revision_id cr_revisions.revision_id%TYPE; --- begin --- v_item_id := content_item.new ( --- name, --- parent_id, --- item_id, --- locale, --- creation_date, --- creation_user, --- context_id, --- creation_ip, --- 'content_item', --- content_type, --- null, --- null, --- null, --- null, --- null --- ); + -- return id of newly created item + return v_item_id; + end new; --- v_revision_id := content_revision.new ( --- title, --- description, --- publish_date, --- mime_type, --- nls_language, --- null, --- v_item_id, --- revision_id, --- creation_date, --- creation_user, --- creation_ip --- ); - --- insert into workflow_case_log --- (entry_id, case_id, action_id, comment_format) --- values (v_revision_id, case_id, action_id, comment_format); - --- content_item.set_live_revision (v_revision_id); - --- end new; - --- end workflow_activity_log; --- / ---show errors - +end workflow_case_log_entry; +/ +show errors +