Index: openacs-4/packages/forums/forums.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/forums.info,v
diff -u -r1.49 -r1.50
--- openacs-4/packages/forums/forums.info 10 Nov 2017 17:21:05 -0000 1.49
+++ openacs-4/packages/forums/forums.info 13 Nov 2017 15:22:26 -0000 1.50
@@ -9,7 +9,7 @@
f
t
-
+
OpenACS
Online discussion forums.
2017-08-06
@@ -19,7 +19,7 @@
2
#forums.Forums#
-
+
Index: openacs-4/packages/forums/sql/oracle/forums-reading-info-package-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/oracle/forums-reading-info-package-create.sql,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/forums/sql/oracle/forums-reading-info-package-create.sql 10 Nov 2017 17:21:05 -0000 1.3
+++ openacs-4/packages/forums/sql/oracle/forums-reading-info-package-create.sql 13 Nov 2017 15:22:26 -0000 1.4
@@ -128,13 +128,15 @@
end user_add_msg;
+
-- move message to other thread
procedure move_thread_update (
p_source_message_id in forums_messages.message_id%TYPE,
p_target_message_id in forums_messages.message_id%TYPE
) is
v_target_forum_id forums_forums.forum_id%TYPE;
v_users forums_reading_info%ROWTYPE;
+ v_source_root_message_id forums_messages.message_id%TYPE;
begin
begin
select forum_id into v_target_forum_id from forums_messages where message_id = p_target_message_id;
@@ -143,16 +145,25 @@
v_target_forum_id := null;
end;
-
- for v_users in (select user_id from forums_reading_info fri where root_message_id = p_target_message_id and not exists(select 1 from forums_reading_info where root_message_id = p_source_old_root_message_id and user_id = fri.user_id))
+ select root_message_id from forums_forums
+ where forum_id = (select forum_id from forums_messages
+ where message_id = p_source_message_id) into v_source_root_message_id;
+
+ for v_users in (
+ select user_id from forums_reading_info fri
+ where root_message_id = p_target_message_id
+ and not exists (select 1 from forums_reading_info
+ where root_message_id = v_source_old_root_message_id
+ and user_id = fri.user_id))
loop
-
- delete from forums_reading_info where root_message_id = p_target_message_id and user_id = v_users.user_id;
- -- down the number of threads read in target forum
+ delete from forums_reading_info
+ where root_message_id = p_target_message_id
+ and user_id = v_users.user_id;
end loop;
end move_thread_update;
+
end forum_reading_info;
/
show errors
Index: openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.3.1d3-1.3.1d4.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.3.1d3-1.3.1d4.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.3.1d3-1.3.1d4.sql 13 Nov 2017 15:22:26 -0000 1.1
@@ -0,0 +1,163 @@
+begin;
+
+-- functions
+
+create or replace package forum_reading_info
+as
+-- remove reading_info for thread (upon new message, upon message deletion, or state change)
+ procedure remove_msg (
+ p_message_id in forums_messages.message_id%TYPE
+ );
+
+-- mark_all_read
+ procedure user_add_forum (
+ p_forum_id in forums_forums.forum_id%TYPE,
+ p_user_id in users.user_id%TYPE
+ );
+
+-- mark message read for user
+ procedure user_add_msg (
+ p_root_message_id in forums_messages.message_id%TYPE,
+ p_user_id in users.user_id%TYPE
+ );
+
+-- move message to other thread
+ procedure move_thread_update (
+ p_source_message_id in forums_messages.message_id%TYPE,
+ p_target_message_id in forums_messages.message_id%TYPE
+ );
+
+end forum_reading_info;
+/
+show errors
+
+
+
+create or replace package body forum_reading_info
+as
+-- remove reading_info for thread (upon new message, upon message deletion, or state change)
+ procedure remove_msg (
+ p_message_id in forums_messages.message_id%TYPE
+ )
+ is
+ v_forum_id forums_messages.forum_id%TYPE;
+ cursor c_reading is select user_id from forums_reading_info where root_message_id = p_message_id;
+
+ begin
+
+ --Exception no_data_found if select into hasn't rows
+ begin
+ select forum_id into v_forum_id from forums_messages where message_id = p_message_id;
+ exception
+ when no_data_found then
+ v_forum_id := null;
+ end;
+
+ for v_reading in c_reading
+ loop
+
+ delete from forums_reading_info
+ where root_message_id = p_message_id and
+ user_id = v_reading.user_id;
+
+ end loop;
+
+
+ end remove_msg;
+
+-- mark_all_read:
+
+ procedure user_add_forum (
+ p_forum_id in forums_forums.forum_id%TYPE,
+ p_user_id in users.user_id%TYPE
+ )
+ is
+ v_message forums_messages_approved%ROWTYPE;
+ v_read_p integer;
+ begin
+
+ for v_message in (select message_id
+ from forums_messages_approved
+ where forum_id = p_forum_id
+ and parent_id is null)
+ loop
+ select count(*) into v_read_p from forums_reading_info where user_id = p_user_id and root_message_id = v_message.message_id;
+
+ if v_read_p = 0 then
+ insert into forums_reading_info
+ (root_message_id,user_id,forum_id)
+ values
+ (v_message.message_id,p_user_id,p_forum_id);
+ end if;
+ end loop;
+
+ end user_add_forum;
+
+
+-- mark message read for user
+ procedure user_add_msg (
+ p_root_message_id in forums_messages.message_id%TYPE,
+ p_user_id in users.user_id%TYPE
+ )
+ is
+ v_forum_id integer;
+ v_read_p integer;
+ begin
+ begin
+ select forum_id into v_forum_id from forums_messages where message_id = p_root_message_id;
+ exception
+ when no_data_found then
+ v_forum_id := null;
+ end;
+
+ select count(*) into v_read_p from forums_reading_info where user_id = p_user_id and root_message_id = p_root_message_id;
+
+ if v_read_p = 0 then
+
+ insert into forums_reading_info (root_message_id,user_id,forum_id)
+ values (p_root_message_id,p_user_id,v_forum_id);
+
+ end if;
+
+ end user_add_msg;
+
+-- move message to other thread
+ procedure move_thread_update (
+ p_source_message_id in forums_messages.message_id%TYPE,
+ p_target_message_id in forums_messages.message_id%TYPE
+ ) is
+ v_target_forum_id forums_forums.forum_id%TYPE;
+ v_users forums_reading_info%ROWTYPE;
+ v_source_root_message_id forums_messages.message_id%TYPE;
+ begin
+ begin
+ select forum_id into v_target_forum_id from forums_messages where message_id = p_target_message_id;
+ exception
+ when no_data_found then
+ v_target_forum_id := null;
+ end;
+
+ select root_message_id from forums_forums
+ where forum_id = (select forum_id from forums_messages
+ where message_id = p_source_message_id) into v_source_root_message_id;
+
+ for v_users in (
+ select user_id from forums_reading_info fri
+ where root_message_id = p_target_message_id
+ and not exists (select 1 from forums_reading_info
+ where root_message_id = v_source_old_root_message_id
+ and user_id = fri.user_id))
+ loop
+ delete from forums_reading_info
+ where root_message_id = p_target_message_id
+ and user_id = v_users.user_id;
+ end loop;
+
+ end move_thread_update;
+
+end forum_reading_info;
+/
+show errors
+
+
+end;
Index: openacs-4/packages/forums/sql/postgresql/forums-reading-info-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/postgresql/forums-reading-info-create.sql,v
diff -u -r1.5 -r1.6
--- openacs-4/packages/forums/sql/postgresql/forums-reading-info-create.sql 10 Nov 2017 17:21:05 -0000 1.5
+++ openacs-4/packages/forums/sql/postgresql/forums-reading-info-create.sql 13 Nov 2017 15:22:26 -0000 1.6
@@ -140,13 +140,18 @@
p_target_message_id integer
) RETURNS integer AS $$
DECLARE
+ v_source_root_message_id integer;
BEGIN
+ select root_message_id from forums_forums
+ where forum_id = (select forum_id from forums_messages
+ where message_id = p_source_message_id) into v_source_root_message_id;
+
-- for all users that have read target, but not the source, remove
-- target_info
delete from forums_reading_info i
where root_message_id = p_target_message_id
and not exists (select 1 from forums_reading_info
- where root_message_id = p_source_message_id
+ where root_message_id = v_source_root_message_id
and user_id = i.user_id);
-- for all users that have read source, remove reading info four
@@ -158,4 +163,3 @@
END;
$$ LANGUAGE plpgsql;
-
Index: openacs-4/packages/forums/sql/postgresql/upgrade/upgrade-1.3.1d3-1.3.1d4.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/postgresql/upgrade/upgrade-1.3.1d3-1.3.1d4.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/forums/sql/postgresql/upgrade/upgrade-1.3.1d3-1.3.1d4.sql 13 Nov 2017 15:22:26 -0000 1.1
@@ -0,0 +1,34 @@
+begin;
+
+--
+-- procedure forums_reading_info__move_thread_update/2
+--
+CREATE OR REPLACE FUNCTION forums_reading_info__move_thread_update(
+ p_source_message_id integer,
+ p_target_message_id integer
+) RETURNS integer AS $$
+DECLARE
+ v_source_root_message_id integer;
+BEGIN
+ select root_message_id from forums_forums
+ where forum_id = (select forum_id from forums_messages
+ where message_id = p_source_message_id) into v_source_root_message_id;
+
+ -- for all users that have read target, but not the source, remove
+ -- target_info
+ delete from forums_reading_info i
+ where root_message_id = p_target_message_id
+ and not exists (select 1 from forums_reading_info
+ where root_message_id = v_source_root_message_id
+ and user_id = i.user_id);
+
+ -- for all users that have read source, remove reading info four
+ -- source message since it no longer is root_message_id
+ delete from forums_reading_info
+ where root_message_id = p_source_message_id;
+
+ return 1;
+END;
+$$ LANGUAGE plpgsql;
+
+end;
Index: openacs-4/packages/forums/www/moderate/move-thread-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/www/moderate/move-thread-oracle.xql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/forums/www/moderate/move-thread-oracle.xql 8 Aug 2006 21:26:53 -0000 1.2
+++ openacs-4/packages/forums/www/moderate/move-thread-oracle.xql 13 Nov 2017 15:22:26 -0000 1.3
@@ -51,5 +51,13 @@
where message_id = :message_id
-
+
+
+
+ begin;
+ select forums_reading_info.move_thread_update($message(message_id), :selected_message);
+ end;
+
+
+
Index: openacs-4/packages/forums/www/moderate/move-thread-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/www/moderate/move-thread-postgresql.xql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/forums/www/moderate/move-thread-postgresql.xql 8 Aug 2006 21:26:53 -0000 1.2
+++ openacs-4/packages/forums/www/moderate/move-thread-postgresql.xql 13 Nov 2017 15:22:26 -0000 1.3
@@ -51,5 +51,13 @@
where message_id = :message_id
+
+
+
+ select forums_reading_info__move_thread_update($message(message_id), :selected_message)
+
+
+
+
Index: openacs-4/packages/forums/www/moderate/move-thread.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/www/moderate/move-thread.tcl,v
diff -u -r1.9 -r1.10
--- openacs-4/packages/forums/www/moderate/move-thread.tcl 27 Sep 2017 15:39:40 -0000 1.9
+++ openacs-4/packages/forums/www/moderate/move-thread.tcl 13 Nov 2017 15:22:26 -0000 1.10
@@ -78,6 +78,11 @@
#update the last_child_post final thread and last_child_post initial father thread
db_dml forums::move_thread::update_last_child_post_initial {}
db_dml forums::move_thread::update_last_child_post_final {}
+
+ if { [forum::use_ReadingInfo_p] } {
+ ns_log Notice "moving message $message(message_id) to thread $selected_message"
+ db_exec_plsql forums::move_thread::update_reading_info {}
+ }
# Redirect to the forum
ad_returnredirect "../forum-view?forum_id=$message(forum_id)"