running hold-notify login in a transaction to fetch latest objects
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 19 Jan 2007 16:09:14 +0000 (16:09 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 19 Jan 2007 16:09:14 +0000 (16:09 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_0@6791 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/HoldNotify.pm

index 2774f43..427d08a 100644 (file)
@@ -1594,8 +1594,11 @@ sub do_hold_notify {
 
        $logger->info("circulator: running delayed hold notify process");
 
+#      my $notifier = OpenILS::Application::Circ::HoldNotify->new(
+#              hold_id => $holdid, editor => new_editor(requestor=>$self->editor->requestor));
+
        my $notifier = OpenILS::Application::Circ::HoldNotify->new(
-               hold_id => $holdid, editor => new_editor(requestor=>$self->editor->requestor));
+               hold_id => $holdid, requestor => $self->editor->requestor);
 
        $logger->debug("circulator: built hold notifier");
 
index 5d0e3b3..3f35826 100644 (file)
@@ -45,7 +45,7 @@ sub send_email_notify_pub {
        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);
+       my $notifier = __PACKAGE__->new(requestor => $e->requestor, hold_id => $hold_id);
        return $notifier->event if $notifier->event;
        my $stat = $notifier->send_email_notify;
 #      $e->commit if $stat == '1';
@@ -102,14 +102,13 @@ sub new {
        my( $class, %args ) = @_;
        $class = ref($class) || $class;
        my $self = bless( {}, $class );
-       $self->editor($args{editor});
+       $self->editor( new_editor( xact => 1, requestor => $args{requestor} ));
        $logger->debug("circulator: creating new hold-notifier with requestor ".
                $self->editor->requestor->id);
        $self->fetch_data($args{hold_id});
        return $self;
 }
 
-
 sub send_email_notify {
        my $self = shift;
 
@@ -120,18 +119,21 @@ sub send_email_notify {
        $logger->debug("hold_notify: email enabled setting = $setting");
 
        if( !$setting or $setting ne 'true' ) {
+      $self->editor->rollback;
                $logger->info("hold_notify: not sending hold notify - email notifications disabled");
                return 0;
        }
 
        unless ($U->is_true($self->hold->email_notify)) {
+      $self->editor->rollback;
                $logger->info("hold_notify: not sending hold notification becaue email_notify is false");
                return 0;
        }
 
-       return OpenILS::Event->new('PATRON_NO_EMAIL_ADDRESS')
-               unless $self->patron->email and
-               $self->patron->email =~ /.+\@.+/; # see if it's remotely email-esque
+       unless( $self->patron->email and $self->patron->email =~ /.+\@.+/ ) { # see if it's remotely email-esque
+      $self->editor->rollback;
+          return OpenILS::Event->new('PATRON_NO_EMAIL_ADDRESS');
+   }
 
        $logger->info("hold_notify: attempting email notify on hold ".$self->hold->id);
 
@@ -141,10 +143,14 @@ sub send_email_notify {
        my $str = $self->flesh_template($self->load_template($template));
 
        unless( $str ) {
+      $self->editor->rollback;
                $logger->error("hold_notify: No email notifiy template found - cannot notify");
                return 0;
        }
 
+   my $reqr = $self->editor->requestor;
+   $self->editor->rollback; # we're done with this transaction
+
        return 0 unless $self->send_email($str);
 
        # ------------------------------------------------------------------
@@ -152,7 +158,7 @@ sub send_email_notify {
        # 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 $we = new_editor(xact=>1, requestor=>$reqr);
 
        my $notify = Fieldmapper::action::hold_notification->new;
        $notify->hold($self->hold->id);
@@ -170,6 +176,8 @@ sub send_email_notify {
 sub send_email {
        my( $self, $text ) = @_;
 
+   # !!! $self->editor xact has been rolled back before we get here
+
        my $smtp = $self->settings_client->config_value('email_notify', 'smtp_server');
 
        $logger->info("hold_notify: sending email notice to ".