From ae9a66066ff3d50e6aa5bb37ad50afdd7e795af2 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 9 Jun 2011 15:21:39 -0400 Subject: [PATCH] Hold notification creation A/T cleanup module New CreateHoldNotification Action/Trigger cleanup module that, when linked to a hold-based event_definition, adds an entry into action.hold_notification for each hold processed. The main user-facing change from this will be that the hold notification time / count in the staff client will now take A/T notices into effect in addition to manually created hold notifications. Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- .../lib/OpenILS/Application/Trigger/Cleanup.pm | 28 ++++++++++++++++++++++ Open-ILS/src/sql/Pg/950.data.seed-values.sql | 13 ++++++++-- .../XXXX.data.hold-notification-cleanup-mod.sql | 24 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.hold-notification-cleanup-mod.sql diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Cleanup.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Cleanup.pm index 495a60a0f8..67e2daf4fa 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Cleanup.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Cleanup.pm @@ -2,6 +2,7 @@ package OpenILS::Application::Trigger::Cleanup; use strict; use warnings; use OpenILS::Utils::CStoreEditor q/:funcs/; use OpenSRF::Utils::Logger qw/:logger/; +use OpenILS::Utils::Fieldmapper; sub fourty_two { return 42 } sub NOOP_True { return 1 } @@ -26,4 +27,31 @@ sub DeleteTempBiblioBucket { return 1; } +# This is really more of an auxillary reactor +sub CreateHoldNotification { + my ($self, $env) = @_; + my $e = new_editor(xact => 1); + my $holds = $env->{target}; + + my $event_def = (ref $env->{event} eq 'ARRAY') ? + $env->{event}->[0]->event_def : # event_def is grouped + $env->{event}->event_def; + + for my $hold (@$holds) { + + my $notify = Fieldmapper::action::hold_notification->new; + $notify->hold($hold->id); + $notify->method($event_def->reactor); + + unless($e->create_action_hold_notification($notify)) { + $e->rollback; + return 0; + } + } + + return 1 if $e->commit; + $e->rollback; + return 0; +} + 1; diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 686471e585..e317202c66 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -6341,9 +6341,18 @@ INSERT INTO action_trigger.environment (event_def, path) VALUES (4, 'lineitems.lineitem_notes'), (4, 'notes'); +INSERT INTO action_trigger.cleanup ( module, description ) VALUES ( + 'CreateHoldNotification', + oils_i18n_gettext( + 'CreateHoldNotification', + 'Creates a hold_notification record for each notified hold', + 'atclean', + 'description' + ) +); -INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, delay, delay_field, group_field, template) - VALUES (5, 'f', 1, 'Hold Ready for Pickup Email Notification', 'hold.available', 'HoldIsAvailable', 'SendEmail', '30 minutes', 'shelf_time', 'usr', +INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, delay, delay_field, group_field, cleanup_success, template) + VALUES (5, 'f', 1, 'Hold Ready for Pickup Email Notification', 'hold.available', 'HoldIsAvailable', 'SendEmail', '30 minutes', 'shelf_time', 'usr', 'CreateHoldNotification', $$ [%- USE date -%] [%- user = target.0.usr -%] diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.hold-notification-cleanup-mod.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.hold-notification-cleanup-mod.sql new file mode 100644 index 0000000000..40da866b55 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.hold-notification-cleanup-mod.sql @@ -0,0 +1,24 @@ +-- Evergreen DB patch XXXX.data.hold-notification-cleanup-mod.sql +BEGIN; + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +INSERT INTO action_trigger.cleanup ( module, description ) VALUES ( + 'CreateHoldNotification', + oils_i18n_gettext( + 'CreateHoldNotification', + 'Creates a hold_notification record for each notified hold', + 'atclean', + 'description' + ) +); + +UPDATE action_trigger.event_definition + SET + cleanup_success = 'CreateHoldNotification' + WHERE + id = 5 -- stock hold-ready email event_def + AND cleanup_success IS NULL; -- don't clobber any existing cleanup mod + +COMMIT; -- 2.11.0