From: erickson Date: Wed, 11 Oct 2006 14:13:03 +0000 (+0000) Subject: creating a one-off cstore connection for creating the hold notification X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=582bf382e2ffb48a4d882ca196c70412ca18d55e;p=Evergreen.git creating a one-off cstore connection for creating the hold notification in the db since the existing session may time out if the notification email takes too long to deliver git-svn-id: svn://svn.open-ils.org/ILS/trunk@6440 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index 7dcccc3da8..a6b9655e43 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -206,7 +206,6 @@ sub run_method { $conn->respond_complete(circ_events($circulator)); unless($circulator->bail_out) { - $logger->info("circulator: running delayed hold notify process"); $circulator->do_hold_notify($circulator->notify_hold) if $circulator->notify_hold; } @@ -1553,8 +1552,12 @@ sub attempt_checkin_hold_capture { sub do_hold_notify { my( $self, $holdid ) = @_; + $logger->info("circulator: running delayed hold notify process"); + my $notifier = OpenILS::Application::Circ::HoldNotify->new( - editor => $self->editor, hold_id => $holdid ); + hold_id => $holdid, editor => new_editor(requestor=>$self->editor->requestor)); + + $logger->debug("circulator: built hold notifier"); if(!$notifier->event) { @@ -1563,7 +1566,6 @@ sub do_hold_notify { my $stat = $notifier->send_email_notify; if( $stat == '1' ) { $logger->info("ciculator: hold notify succeeded for hold $holdid"); - $self->editor->commit; return; } @@ -1572,8 +1574,6 @@ sub do_hold_notify { } else { $logger->info("ciculator: Not sending hold notification since the patron has no email address"); } - - $self->editor->rollback; } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/HoldNotify.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/HoldNotify.pm index 2f5c0eb649..75b7ab14c1 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/HoldNotify.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/HoldNotify.pm @@ -42,13 +42,13 @@ __PACKAGE__->register_method( sub send_email_notify_pub { my( $self, $conn, $auth, $hold_id ) = @_; - my $e = new_editor(authtoken => $auth, xact =>1); + my $e = new_editor(authtoken => $auth); return $e->event unless $e->checkauth; return $e->event unless $e->allowed('CREATE_HOLD_NOTIFICATION'); my $notifier = __PACKAGE__->new(editor=> $e, hold_id => $hold_id); return $notifier->event if $notifier->event; my $stat = $notifier->send_email_notify; - $e->commit if $stat == '1'; +# $e->commit if $stat == '1'; return $stat; } @@ -102,7 +102,9 @@ sub new { my( $class, %args ) = @_; $class = ref($class) || $class; my $self = bless( {}, $class ); - $self->editor( ($args{editor}) ? $args{editor} : new_editor()); + $self->editor($args{editor}); + $logger->debug("circulator: creating new hold-notifier with requestor ". + $self->editor->requestor->id); $self->fetch_data($args{hold_id}); return $self; } @@ -143,18 +145,24 @@ sub send_email_notify { return 0; } - $logger->info("hold_notify: fleshed template: $str"); + return 0 unless $self->send_email($str); - $self->send_email($str); + # ------------------------------------------------------------------ + # If the hold email takes too long to send, the existing editor + # transaction may have timed out. Create a one-off editor to write + # the notification to the DB. + # ------------------------------------------------------------------ + my $we = new_editor(xact=>1, requestor=>$self->editor->requestor); my $notify = Fieldmapper::action::hold_notification->new; $notify->hold($self->hold->id); - $notify->notify_staff($self->editor->requestor->id); + $notify->notify_staff($we->requestor->id); $notify->notify_time('now'); $notify->method('email'); - $self->editor->create_action_hold_notification($notify) - or return $self->editor->event; + $we->create_action_hold_notification($notify) + or return $we->die_event; + $we->commit; return 1; } @@ -200,6 +208,8 @@ sub fetch_data { my $holdid = shift; my $e = $self->editor; + $logger->debug("circulator: fetching hold notify data"); + $self->hold($e->retrieve_action_hold_request($holdid)) or return $self->event($e->event); $self->copy($e->retrieve_asset_copy($self->hold->current_copy)) or return $self->event($e->event); $self->volume($e->retrieve_asset_call_number($self->copy->call_number)) or return $self->event($e->event);