Index: openacs.org-dev/packages/notifications/sql/oracle/notifications-core-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/sql/oracle/notifications-core-create.sql,v diff -u -r1.1 -r1.2 --- openacs.org-dev/packages/notifications/sql/oracle/notifications-core-create.sql 9 Jul 2002 17:35:10 -0000 1.1 +++ openacs.org-dev/packages/notifications/sql/oracle/notifications-core-create.sql 12 Feb 2003 13:16:53 -0000 1.2 @@ -4,7 +4,7 @@ -- @author Ben Adida (ben@openforce.net) -- @version $Id$ -- --- Copyright OpenForce, 2002. +-- Copyright (C) 2000 MIT -- -- GNU GPL v2 -- @@ -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 @@ -144,7 +146,7 @@ -- this is to allow responses to notifications response_id constraint notif_reponse_id_fk references acs_objects (object_id), - notif_subject varchar(100), + notif_subject varchar(1000), notif_text clob, notif_html clob ); Index: openacs.org-dev/packages/notifications/sql/postgresql/notifications-core-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/sql/postgresql/notifications-core-create.sql,v diff -u -r1.1 -r1.2 --- openacs.org-dev/packages/notifications/sql/postgresql/notifications-core-create.sql 9 Jul 2002 17:35:10 -0000 1.1 +++ openacs.org-dev/packages/notifications/sql/postgresql/notifications-core-create.sql 12 Feb 2003 13:17:35 -0000 1.2 @@ -4,7 +4,7 @@ -- @author Ben Adida (ben@openforce.net) -- @version $Id$ -- --- Copyright OpenForce, 2002. +-- Copyright (C) 2000 MIT -- -- GNU GPL v2 -- @@ -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 @@ -164,7 +166,7 @@ response_id integer constraint notif_reponse_id_fk references acs_objects (object_id), - notif_subject varchar(100), + notif_subject varchar(1000), notif_text text, notif_html text ); Index: openacs.org-dev/packages/notifications/tcl/notification-display-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/tcl/notification-display-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs.org-dev/packages/notifications/tcl/notification-display-procs.tcl 9 Jul 2002 17:35:10 -0000 1.1 +++ openacs.org-dev/packages/notifications/tcl/notification-display-procs.tcl 12 Feb 2003 13:18:06 -0000 1.2 @@ -17,7 +17,8 @@ {-url:required} {-user_id ""} } { - Produce a widget for requesting notifications + 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] @@ -33,10 +34,14 @@ set sub_url [unsubscribe_url -request_id $request_id -url $url] set sub_chunk "You have requested notification for $pretty_name. You may unsubscribe." } else { - set sub_url [subscribe_url -type $type -object_id $object_id -url $url -user_id $user_id] + set sub_url [subscribe_url -type $type -object_id $object_id -url $url -user_id $user_id -pretty_name $pretty_name] set sub_chunk "You may request notification for $pretty_name." } + if { [empty_string_p $sub_url] } { + return "" + } + return "\[ $sub_chunk \]" } @@ -45,12 +50,21 @@ {-object_id:required} {-url:required} {-user_id:required} + {-pretty_name} } { + 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]] - set subscribe_url "${root_path}request-new?type_id=$type_id&user_id=$user_id&object_id=$object_id&return_url=[ns_urlencode $url]" + 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 } @@ -59,6 +73,11 @@ {-url:required} } { 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.org-dev/packages/notifications/tcl/notification-email-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/tcl/notification-email-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs.org-dev/packages/notifications/tcl/notification-email-procs.tcl 12 Feb 2003 01:22:50 -0000 1.5 +++ openacs.org-dev/packages/notifications/tcl/notification-email-procs.tcl 12 Feb 2003 13:18:07 -0000 1.6 @@ -97,6 +97,8 @@ # Set the reply to address to the address of the mailer. set extra_headers [ns_set new] ns_set put $extra_headers Reply-To [reply_address -object_id $reply_object_id -type_id $notification_type_id] + ns_set put $extra_headers Precedence bulk + ns_set put $extra_headers Sender "notifications-admin@openacs.org" acs_mail_lite::send \ -to_addr $email \ Index: openacs.org-dev/packages/notifications/tcl/notification-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/tcl/notification-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs.org-dev/packages/notifications/tcl/notification-procs.tcl 9 Jul 2002 17:35:10 -0000 1.1 +++ openacs.org-dev/packages/notifications/tcl/notification-procs.tcl 12 Feb 2003 13:18:07 -0000 1.2 @@ -51,16 +51,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 { @@ -84,6 +84,7 @@ mark that a user has been sent a notification } { # Do the insert +ns_log Notice "DRB: marking notification $notification_id sent for user $user_id" db_dml insert_notification_user_map {} } } Index: openacs.org-dev/packages/notifications/tcl/notification-request-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/tcl/notification-request-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs.org-dev/packages/notifications/tcl/notification-request-procs.tcl 9 Jul 2002 17:35:10 -0000 1.1 +++ openacs.org-dev/packages/notifications/tcl/notification-request-procs.tcl 12 Feb 2003 13:18:07 -0000 1.2 @@ -45,6 +45,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.org-dev/packages/notifications/tcl/notification-request-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/tcl/notification-request-procs.xql,v diff -u -r1.1 -r1.2 --- openacs.org-dev/packages/notifications/tcl/notification-request-procs.xql 9 Jul 2002 17:35:10 -0000 1.1 +++ openacs.org-dev/packages/notifications/tcl/notification-request-procs.xql 12 Feb 2003 13:18:07 -0000 1.2 @@ -12,4 +12,13 @@ + + + select count(*) + from notification_requests + where type_id = :type_id + and object_id = :object_id + + + Index: openacs.org-dev/packages/notifications/tcl/sweep-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/tcl/sweep-init.tcl,v diff -u -r1.5 -r1.6 --- openacs.org-dev/packages/notifications/tcl/sweep-init.tcl 12 Dec 2002 12:44:16 -0000 1.5 +++ openacs.org-dev/packages/notifications/tcl/sweep-init.tcl 12 Feb 2003 13:18:07 -0000 1.6 @@ -8,14 +8,9 @@ } -# Hack for now to test immediate deliveries -# FIXME -# DaveB increase from one minute to 2 days. -# on advice from Cmeeks -# otherwise it cleans out unsent notifications before the daily -# scheduled proc runs +# DRB: The cleanup sweep interval should be made a parameter someday ... -ad_schedule_proc -thread t 172800 notification::sweep::cleanup_notifications +ad_schedule_proc -thread t 900 notification::sweep::cleanup_notifications foreach interval [notification::get_all_intervals] { set n_seconds [lindex $interval 2] @@ -25,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.org-dev/packages/notifications/tcl/sweep-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/tcl/sweep-procs-postgresql.xql,v diff -u -r1.1 -r1.2 --- openacs.org-dev/packages/notifications/tcl/sweep-procs-postgresql.xql 9 Jul 2002 17:35:10 -0000 1.1 +++ openacs.org-dev/packages/notifications/tcl/sweep-procs-postgresql.xql 12 Feb 2003 13:18:07 -0000 1.2 @@ -5,39 +5,33 @@ - select notification_id - from notifications - where 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 notification_id + from notifications + except + select distinct notification_id + from notifications inner join notification_requests using (type_id, object_id) + left outer join notification_user_map using (notification_id, user_id) + where sent_date is null - select notifications.notification_id, - notifications.notif_subject, - notifications.notif_text, - notifications.notif_html, - notification_requests.user_id, - acs_object__name(notifications.object_id) as object_name - 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_requests.interval_id = :interval_id - and notification_user_map.sent_date is null + select notification_id, + notif_subject, + notif_text, + notif_html, + user_id, + type_id, + delivery_method_id, + response_id + from notifications inner join notification_requests using (type_id, object_id) + inner join acs_objects on (notification_requests.request_id = acs_objects.object_id) + left outer join notification_user_map using (notification_id, user_id) + where sent_date is null + and creation_date <= notif_date + and interval_id = :interval_id + order by user_id, type_id Index: openacs.org-dev/packages/notifications/tcl/sweep-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/tcl/sweep-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs.org-dev/packages/notifications/tcl/sweep-procs.tcl 9 Jul 2002 17:35:10 -0000 1.1 +++ openacs.org-dev/packages/notifications/tcl/sweep-procs.tcl 12 Feb 2003 13:18:07 -0000 1.2 @@ -16,9 +16,10 @@ } ad_proc -public cleanup_notifications {} { - Clean up the notifications that are done + 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 @@ -51,14 +52,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 "" } @@ -67,20 +68,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 \ @@ -93,7 +94,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!" } } @@ -103,8 +104,8 @@ # append content to built-up content - ns_log Notice "NOTIF-BATCHED: appending one notif!" - append batched_content "SUBJECT: [ns_set get $notif object_name] - [ns_set get $notif notif_subject]\n[ns_set get $notif notif_text]\n=====================\n" + 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] # Set the vars @@ -120,7 +121,7 @@ # Send it notification::delivery::send -to_user_id [ns_set get $notif user_id] \ -notification_type_id [ns_set get $notif type_id] \ - -subject "\[[ad_system_name] - [ns_set get $notif object_name]\] [ns_set get $notif notif_subject]" \ + -subject [ns_set get $notif notif_subject] \ -content [ns_set get $notif notif_text] \ -reply_object_id [ns_set get $notif response_id] \ -delivery_method_id [ns_set get $notif delivery_method_id] Index: openacs.org-dev/packages/notifications/www/manage.adp =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/notifications/www/manage.adp,v diff -u -r1.2 -r1.3 --- openacs.org-dev/packages/notifications/www/manage.adp 23 Jan 2003 17:56:21 -0000 1.2 +++ openacs.org-dev/packages/notifications/www/manage.adp 12 Feb 2003 13:19:04 -0000 1.3 @@ -9,6 +9,7 @@ Frequency Action +@notifications:rowcount@ Notifications