Index: openacs-4/packages/forums/sql/oracle/forums-forums-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/oracle/forums-forums-create.sql,v diff -u -r1.4 -r1.4.4.1 --- openacs-4/packages/forums/sql/oracle/forums-forums-create.sql 30 Nov 2002 17:34:49 -0000 1.4 +++ openacs-4/packages/forums/sql/oracle/forums-forums-create.sql 25 Dec 2004 01:05:11 -0000 1.4.4.1 @@ -69,6 +69,8 @@ package_id integer constraint forums_package_id_nn not null, + thread_count integer default 0, + approved_thread_count integer default 0, last_post date ); Index: openacs-4/packages/forums/sql/oracle/forums-messages-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/oracle/forums-messages-create.sql,v diff -u -r1.7.4.2 -r1.7.4.3 --- openacs-4/packages/forums/sql/oracle/forums-messages-create.sql 30 Jun 2004 19:47:53 -0000 1.7.4.2 +++ openacs-4/packages/forums/sql/oracle/forums-messages-create.sql 25 Dec 2004 01:05:11 -0000 1.7.4.3 @@ -46,6 +46,8 @@ tree_sortkey raw(240), max_child_sortkey raw(100), last_child_post date, + reply_count integer default 0, + approved_reply_count integer default 0, constraint forums_mess_sk_forum_un unique (tree_sortkey, forum_id) ); Index: openacs-4/packages/forums/sql/oracle/forums-messages-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/oracle/forums-messages-package-create.sql,v diff -u -r1.6.4.1 -r1.6.4.2 --- openacs-4/packages/forums/sql/oracle/forums-messages-package-create.sql 22 Jun 2004 16:53:42 -0000 1.6.4.1 +++ openacs-4/packages/forums/sql/oracle/forums-messages-package-create.sql 25 Dec 2004 01:05:11 -0000 1.6.4.2 @@ -51,6 +51,11 @@ message_id in forums_messages.message_id%TYPE ); + procedure set_state( + message_id in forums_messages.message_id%TYPE, + state in forums_messages.state%TYPE + ); + function name ( message_id in forums_messages.message_id%TYPE ) return varchar; @@ -115,8 +120,6 @@ values (v_message_id, forum_id, subject, content, format, user_id, posting_date, parent_id, v_state); - -- DRB: Can't use root_message_id() here because it triggers a "mutating table" error - select tree_sortkey into v_sortkey from forums_messages where message_id = v_message_id; @@ -125,12 +128,38 @@ set last_post = forums_message.new.posting_date where forum_id = forums_message.new.forum_id; - update forums_messages - set last_child_post = forums_message.new.posting_date - where forum_id = forums_message.new.forum_id - and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + -- DRB: Can't use root_message_id() here because it triggers a "mutating table" error + + if parent_id is null then + if v_state = 'approved' then + update forums_forums + set thread_count = thread_count + 1, + approved_thread_count = approved_thread_count + 1 + where forum_id = forums_message.new.forum_id; + else + update forums_forums + set thread_count = thread_count + 1 + where forum_id=forums_message.new.forum_id; + end if; + else + if v_state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + reply_count = reply_count + 1, + last_child_post = current_timestamp + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + else + update forums_messages + set reply_count = reply_count + 1, + last_child_post = current_timestamp + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + end if; + end if; return v_message_id; + end new; function root_message_id ( @@ -203,8 +232,39 @@ message_id in forums_messages.message_id%TYPE ) is + v_cur forums_messages%ROWTYPE; begin - acs_object.del(message_id); + + -- Maintain the forum thread counts + + select * into v_cur + from forums_messages + where message_id = forums_message.del.message_id; + + if v_cur.parent_id is null then + if v_cur.state = 'approved' then + update forums_forums + set thread_count = thread_count - 1, + approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + else + update forums_forums + set thread_count = thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + elsif v_cur.state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count - 1, + reply_count = reply_count - 1 + where message_id = forums_message.root_message_id(v_cur.message_id); + else + update forums_messages + set reply_count = reply_count - 1 + where message_id = forums_message.root_message_id(v_cur.message_id); + end if; + + acs_object.del(message_id); + end del; procedure delete_thread ( @@ -235,7 +295,7 @@ and tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) order by tree_sortkey desc) loop - forums_message.del(v_message.message_id); + acs_object.del(v_message.message_id); end loop; -- delete the message itself @@ -256,6 +316,47 @@ return v_name; end name; + procedure set_state( + message_id in forums_messages.message_id%TYPE, + state in forums_messages.state%TYPE + ) + is + v_cur forums_messages%ROWTYPE; + begin + + select * into v_cur + from forums_messages + where message_id = forums_message.set_state.message_id; + + if v_cur.parent_id is null then + if state = 'approved' and v_cur.state <> 'approved' then + update forums_forums + set approved_thread_count = approved_thread_count + 1 + where forum_id=v_cur.forum_id; + elsif state <> 'approved' and v_cur.state = 'approved' then + update forums_forums + set approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + else + if state = 'approved' and v_cur.state <> 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count + 1 + where message_id = forums_message.root_message_id(v_cur.message_id); + elsif state <> 'approved' and v_cur.state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count - 1 + where message_id = forums_message.root_message_id(v_cur.message_id); + end if; + end if; + + update forums_messages + set state = forums_message.set_state.state + where message_id = forums_message.set_state.message_id; + + end set_state; + end forums_message; / show errors + Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.0.6-1.0.7d.sql'. Fisheye: No comparison available. Pass `N' to diff?