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 }
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;
(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 -%]
--- /dev/null
+-- 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;