Index: openacs-4/packages/notifications/sql/oracle/notifications-core-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/sql/oracle/notifications-core-create.sql,v diff -u -r1.8 -r1.8.2.1 --- openacs-4/packages/notifications/sql/oracle/notifications-core-create.sql 20 Sep 2002 21:18:58 -0000 1.8 +++ openacs-4/packages/notifications/sql/oracle/notifications-core-create.sql 6 Dec 2002 21:03:57 -0000 1.8.2.1 @@ -120,6 +120,8 @@ check (format in ('text', 'html')) ); +create index notification_requests_t_o_idx on notification_requests(type_id, object_id); + -- preferences -- -- for preferences that apply to each request, we're using the Index: openacs-4/packages/notifications/sql/postgresql/notifications-core-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/sql/postgresql/notifications-core-create.sql,v diff -u -r1.7 -r1.7.2.1 --- openacs-4/packages/notifications/sql/postgresql/notifications-core-create.sql 20 Sep 2002 21:18:59 -0000 1.7 +++ openacs-4/packages/notifications/sql/postgresql/notifications-core-create.sql 6 Dec 2002 21:04:09 -0000 1.7.2.1 @@ -53,10 +53,10 @@ references acs_objects (object_id) constraint notif_type_type_id_pk primary key, - sc_impl_id integer not null + sc_impl_id integer not null constraint notif_deliv_meth_impl_id_fk references acs_sc_impls(impl_id), - short_name varchar(100) + short_name varchar(100) constraint notif_type_short_name_nn not null constraint notif_type_short_name_un @@ -136,6 +136,8 @@ check (format in ('text', 'html')) ); +create index notification_requests_t_o_idx on notification_requests(type_id, object_id); + -- preferences -- -- for preferences that apply to each request, we're using the Index: openacs-4/packages/notifications/tcl/notification-display-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-display-procs.tcl,v diff -u -r1.4.2.1 -r1.4.2.2 --- openacs-4/packages/notifications/tcl/notification-display-procs.tcl 30 Oct 2002 21:12:05 -0000 1.4.2.1 +++ openacs-4/packages/notifications/tcl/notification-display-procs.tcl 6 Dec 2002 21:04:19 -0000 1.4.2.2 @@ -20,7 +20,8 @@ {-url:required} {-user_id ""} } { - Produce a widget for requesting notifications of a given type. + Produce a widget for requesting notifications of a given type. If the notifications package has not been + mounted then return the empty string. } { if {[empty_string_p $user_id]} { set user_id [ad_conn user_id] @@ -40,6 +41,10 @@ set sub_chunk "You may request notification for $pretty_name." } + if { [empty_string_p $sub_url] } { + return "" + } + return "\[ $sub_chunk \]" } @@ -50,11 +55,17 @@ {-user_id:required} {-pretty_name} } { - Returns the URL that allows one to subscribe to a notification type on a particular object. + Returns the URL that allows one to subscribe to a notification type on a particular object. If the + notifications package has not been mounted return the empty string. } { set type_id [notification::type::get_type_id -short_name $type] set root_path [apm_package_url_from_key [notification::package_key]] + + if { [empty_string_p $root_path] } { + return "" + } + set subscribe_url "${root_path}request-new?[export_vars { type_id user_id object_id pretty_name {return_url $url} }]" return $subscribe_url @@ -67,6 +78,11 @@ Returns the URL that allows one to unsubscribe from a particular request. } { set root_path [apm_package_url_from_key [notification::package_key]] + + if { [empty_string_p $root_path] } { + return "" + } + set unsubscribe_url "${root_path}request-delete?request_id=$request_id&return_url=[ns_urlencode $url]" return $unsubscribe_url Index: openacs-4/packages/notifications/tcl/notification-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-procs.tcl,v diff -u -r1.3.2.1 -r1.3.2.2 --- openacs-4/packages/notifications/tcl/notification-procs.tcl 30 Oct 2002 21:12:05 -0000 1.3.2.1 +++ openacs-4/packages/notifications/tcl/notification-procs.tcl 6 Dec 2002 21:04:19 -0000 1.3.2.2 @@ -78,16 +78,16 @@ {-notif_text ""} {-notif_html ""} } { - create a new notification + create a new notification if any notification requests exist for the object and type } { - # Set up the vars - set extra_vars [ns_set create] - oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list {notification_id type_id object_id response_id notif_subject notif_text notif_html} + if { [notification::request::request_exists -object_id $object_id -type_id $type_id] } { + # Set up the vars + set extra_vars [ns_set create] + oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list {notification_id type_id object_id response_id notif_subject notif_text notif_html} - # Create the request - set notification_id [package_instantiate_object -extra_vars $extra_vars notification] - - return $notification_id + # Create the request + package_instantiate_object -extra_vars $extra_vars notification + } } ad_proc -public delete { Index: openacs-4/packages/notifications/tcl/notification-request-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-request-procs.tcl,v diff -u -r1.3.2.1 -r1.3.2.2 --- openacs-4/packages/notifications/tcl/notification-request-procs.tcl 30 Oct 2002 21:12:05 -0000 1.3.2.1 +++ openacs-4/packages/notifications/tcl/notification-request-procs.tcl 6 Dec 2002 21:04:19 -0000 1.3.2.2 @@ -52,6 +52,15 @@ return [db_string select_request_id {} -default {}] } + ad_proc -public request_exists { + {-type_id:required} + {-object_id:required} + } { + returns true if at least one request exists for this object and type + } { + return [expr { [db_string request_count {}] > 0 }] + } + ad_proc -public delete { {-request_id:required} } { Index: openacs-4/packages/notifications/tcl/notification-request-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-request-procs.xql,v diff -u -r1.3 -r1.3.2.1 --- openacs-4/packages/notifications/tcl/notification-request-procs.xql 3 Jun 2002 22:27:00 -0000 1.3 +++ openacs-4/packages/notifications/tcl/notification-request-procs.xql 6 Dec 2002 21:04:19 -0000 1.3.2.1 @@ -12,4 +12,13 @@ + + + select count(*) + from notification_requests + where type_id = :type_id + and object_id = :object_id + + + Index: openacs-4/packages/notifications/tcl/sweep-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/sweep-init.tcl,v diff -u -r1.4 -r1.4.2.1 --- openacs-4/packages/notifications/tcl/sweep-init.tcl 10 Sep 2002 22:23:11 -0000 1.4 +++ openacs-4/packages/notifications/tcl/sweep-init.tcl 6 Dec 2002 21:04:19 -0000 1.4.2.1 @@ -8,10 +8,10 @@ } -# Hack for now to test immediate deliveries -# FIXME -ad_schedule_proc -thread t 60 notification::sweep::cleanup_notifications +# DRB: The cleanup sweep interval should be made a parameter someday ... +ad_schedule_proc -thread t 900 notification::sweep::cleanup_notifications + foreach interval [notification::get_all_intervals] { set n_seconds [lindex $interval 2] if {$n_seconds > 0} { @@ -20,7 +20,15 @@ set batched_p 0 } - if {$n_seconds > 0} { + # Send weekly and daily notifications at defined times rather than a week after + # the server was started up, etc etc. Hourly, instant, and exotic custom + # intervals will run relative to the server startup time. + + if { $n_seconds == 24 * 60 * 60 } { + ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 0 0] notification::sweep::sweep_notifications -interval_id [lindex $interval 1] -batched_p $batched_p + } elseif { $n_seconds == 7 * 24 * 60 * 60 } { + ad_schedule_proc -thread t -schedule_proc ns_schedule_weekly [list 0 0 0] notification::sweep::sweep_notifications -interval_id [lindex $interval 1] -batched_p $batched_p + } elseif {$n_seconds > 0} { ad_schedule_proc -thread t $n_seconds notification::sweep::sweep_notifications -interval_id [lindex $interval 1] -batched_p $batched_p } else { ad_schedule_proc -thread t 60 notification::sweep::sweep_notifications -interval_id [lindex $interval 1] -batched_p $batched_p Index: openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/Attic/sweep-procs-oracle.xql,v diff -u -r1.9 -r1.9.2.1 --- openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql 20 Sep 2002 21:19:00 -0000 1.9 +++ openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql 6 Dec 2002 21:04:19 -0000 1.9.2.1 @@ -5,17 +5,15 @@ - select notification_id + select notifications.notification_id from notifications - where sysdate - notif_date > 2 - and not exists (select notifications.notification_id - from notifications, - notification_requests, - notification_user_map - where notifications.type_id = notification_requests.type_id - and notifications.object_id = notification_requests.object_id - and notifications.notification_id = notification_user_map.notification_id(+) - and sent_date is null) + minus + select notifications.notification_id + from notifications, notification_requests, notification_user_map + where notifications.type_id = notification_requests.type_id + and notifications.object_id = notification_requests.object_id + and notifications.notification_id = notification_user_map.notification_id(+) + and sent_date is null @@ -31,14 +29,15 @@ notifications.response_id from notifications, notification_requests, - notification_user_map + notification_user_map, + acs_objects notification_requests_object where notifications.type_id = notification_requests.type_id - and interval_id = :interval_id - and notifications.object_id = notification_requests.object_id - and notifications.notification_id = notification_user_map.notification_id(+) - and sent_date is null - and notifications.notif_date <= - (sysdate - (select n_seconds / 3600 / 24 from notification_intervals where interval_id= :interval_id)) + and interval_id = :interval_id + and notifications.object_id = notification_requests.object_id + and notifications.notification_id = notification_user_map.notification_id(+) + and sent_date is null + and notification_requests_object.object_id = notification_requests.request_id + and notification_requests_object.creation_date <= notifications.notif_date order by notification_requests.user_id, notification_requests.type_id Index: openacs-4/packages/notifications/tcl/sweep-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/Attic/sweep-procs-postgresql.xql,v diff -u -r1.3 -r1.3.2.1 --- openacs-4/packages/notifications/tcl/sweep-procs-postgresql.xql 20 Sep 2002 21:19:00 -0000 1.3 +++ openacs-4/packages/notifications/tcl/sweep-procs-postgresql.xql 6 Dec 2002 21:04:19 -0000 1.3.2.1 @@ -5,19 +5,16 @@ - select notification_id - from notifications - where now() - notif_date > 2 - and not exists (select notifications.notification_id - from notifications - inner join notification_requests - on ( - notifications.type_id = notification_requests.type_id - and notifications.object_id = notification_requests.object_id - ) - left outer join notification_user_map - on (notifications.notification_id = notification_user_map.notification_id) - where notification_user_map.sent_date is null) + select notifications.notification_id + from notifications + except + select distinct notifications.notification_id + from notifications left outer join notification_user_map + on (notifications.notification_id = notification_user_map.notification_id) + inner join notification_requests + on (notifications.type_id = notification_requests.type_id + and notifications.object_id = notification_requests.object_id) + where sent_date is null @@ -36,11 +33,14 @@ on ( notifications.type_id = notification_requests.type_id and notifications.object_id = notification_requests.object_id + and notification_requests.interval_id = :interval_id ) + inner join acs_objects on (notification_requests.request_id = acs_objects.object_id) left outer join notification_user_map on (notifications.notification_id = notification_user_map.notification_id) - where notification_requests.interval_id = :interval_id - and notification_user_map.sent_date is null + where notification_user_map.sent_date is null + and acs_objects.creation_date <= notifications.notif_date + order by notification_requests.user_id, notification_requests.type_id Index: openacs-4/packages/notifications/tcl/sweep-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/sweep-procs.tcl,v diff -u -r1.9.2.1 -r1.9.2.2 --- openacs-4/packages/notifications/tcl/sweep-procs.tcl 30 Oct 2002 21:12:05 -0000 1.9.2.1 +++ openacs-4/packages/notifications/tcl/sweep-procs.tcl 6 Dec 2002 21:04:19 -0000 1.9.2.2 @@ -17,9 +17,10 @@ } ad_proc -public cleanup_notifications {} { - Clean up the notifications that have been sent out. + Clean up the notifications that have been sent out (DRB: inefficiently...). } { # Get the list of the ones to kill + set notification_id_list [db_list select_notification_ids {}] # Kill them @@ -52,14 +53,14 @@ # Batched sending foreach notif $notifications { - ns_log Notice "NOTIF-BATCHED: one notif $notif" + ns_log Debug "NOTIF-BATCHED: one notif $notif" if {$notif != "STOP"} { - ns_log Notice "NOTIF-BATCHED: NOT a stop codon" + ns_log Debug "NOTIF-BATCHED: NOT a stop codon" set user_id [ns_set get $notif user_id] set type_id [ns_set get $notif type_id] } else { - ns_log Notice "NOTIF-BATCHED stop codon!" + ns_log Debug "NOTIF-BATCHED stop codon!" set user_id "" set type_id "" } @@ -68,20 +69,20 @@ # if so, batch up previous stuff and send it if {$notif == "STOP" || $user_id != $prev_user_id || $type_id != $prev_type_id} { - ns_log Notice "NOTIF-BATCHED: batching things up for $prev_user_id" + ns_log Debug "NOTIF-BATCHED: batching things up for $prev_user_id" # If no content, keep going if {![empty_string_p $batched_content]} { - ns_log Notice "NOTIF-BATCHED: content to send!" + ns_log Debug "NOTIF-BATCHED: content to send!" db_transaction { - ns_log Notice "NOTIF-BATCHED: sending content" + ns_log Debug "NOTIF-BATCHED: sending content" notification::delivery::send -to_user_id $prev_user_id \ -notification_type_id $prev_type_id \ -subject "\[[ad_system_name] - Batched Notification\]" \ -content $batched_content \ -delivery_method_id $prev_deliv_method_id - ns_log Notice "NOTIF-BATCHED: marking notifications" + ns_log Debug "NOTIF-BATCHED: marking notifications" foreach not_id $list_of_notification_ids { # Mark it as sent notification::mark_sent \ @@ -94,7 +95,7 @@ set list_of_notification_ids [list] set batched_content "" } else { - ns_log Notice "NOTIF-BATCHED: NO content to send!" + ns_log Debug "NOTIF-BATCHED: NO content to send!" } } @@ -104,7 +105,7 @@ # append content to built-up content - ns_log Notice "NOTIF-BATCHED: appending one notif!" + ns_log Debug "NOTIF-BATCHED: appending one notif!" append batched_content "SUBJECT: [ns_set get $notif notif_subject]\n[ns_set get $notif notif_text]\n=====================\n" lappend list_of_notification_ids [ns_set get $notif notification_id]