From c64f8ac32e3141e3bb03c5ec10024a6f27f0b798 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 20 Nov 2008 17:49:29 +0000 Subject: [PATCH] more round 1 penalty overhaul. more to ensue git-svn-id: svn://svn.open-ils.org/ILS/trunk@11286 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/AppUtils.pm | 5 +- .../perlmods/OpenILS/Application/Circ/Circulate.pm | 70 ++++------------------ .../src/perlmods/OpenILS/Application/Circ/Money.pm | 12 +--- 3 files changed, 16 insertions(+), 71 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index d8a5537157..59a5898c59 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -1068,12 +1068,11 @@ sub fetch_user_by_barcode { # --------------------------------------------------------------------- # Updates and returns the patron penalties # --------------------------------------------------------------------- -sub update_patron_penalties { +sub update_patron_penalties_nonblock { my( $self, %args ) = @_; return $self->simplereq( 'open-ils.penalty', - 'open-ils.penalty.patron_penalty.calculate', - { update => 1, %args } + 'open-ils.penalty.patron_penalty.calculate', {background => 1} ); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index d7fb112f36..65d44fb8c3 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -170,9 +170,6 @@ sub run_method { # -------------------------------------------------------------------------- $circulator->is_renewal(1) if $api =~ /renew/; $circulator->is_checkin(1) if $api =~ /checkin/; - $circulator->check_penalty_on_renew(1) if - $circulator->is_renewal and $U->ou_ancestor_setting_value( - $circulator->circ_lib, 'circ.renew.check_penalty', $circulator->editor); if($legacy_script_support and not $circulator->is_checkin) { $circulator->mk_script_runner(); @@ -314,6 +311,7 @@ use OpenSRF::Utils::Logger qw(:logger); use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Application::Circ::ScriptBuilder; use OpenILS::Const qw/:const/; +use OpenILS::Utils::Penalty; my $holdcode = "OpenILS::Application::Circ::Holds"; my $transcode = "OpenILS::Application::Circ::Transit"; @@ -327,7 +325,6 @@ sub DESTROY { } # -------------------------------------------------------------------------- my @AUTOLOAD_FIELDS = qw/ notify_hold - penalty_request remote_hold backdate copy @@ -340,7 +337,6 @@ my @AUTOLOAD_FIELDS = qw/ volume title is_renewal - check_penalty_on_renew is_noncat is_precat request_precat @@ -675,8 +671,7 @@ sub do_permit { $self->run_copy_permit_scripts() unless $self->is_precat or $self->is_noncat; $self->check_item_deposit_events(); - $self->override_events() unless - $self->is_renewal and not $self->check_penalty_on_renew; + $self->override_events(); return if $self->bail_out; if($self->is_precat and not $self->request_precat) { @@ -798,31 +793,6 @@ sub do_copy_checks { } } - -sub send_penalty_request { - my $self = shift; - my $ses = OpenSRF::AppSession->create('open-ils.penalty'); - $self->penalty_request( - $ses->request( - 'open-ils.penalty.patron_penalty.calculate', - { update => 1, - authtoken => $self->editor->authtoken, - patron => $self->patron } ) ); -} - -sub gather_penalty_request { - my $self = shift; - return [] unless $self->penalty_request; - my $data = $self->penalty_request->recv; - if( ref $data ) { - throw $data if UNIVERSAL::isa($data,'Error'); - $data = $data->content; - return $data->{fatal_penalties}; - } - $logger->error("circulator: penalty request returned no data"); - return []; -} - my $LEGACY_CIRC_EVENT_MAP = { 'actor.usr.barred' => 'PATRON_BARRED', 'asset.copy.circulate' => 'COPY_CIRC_NOT_ALLOWED', @@ -857,10 +827,6 @@ sub run_patron_permit_scripts { } else { - $self->send_penalty_request() unless - $self->is_renewal and not $self->check_penalty_on_renew; - - # --------------------------------------------------------------------- # Now run the patron permit script # --------------------------------------------------------------------- $runner->load($self->circ_permit_patron); @@ -869,8 +835,9 @@ sub run_patron_permit_scripts { my $patron_events = $result->{events}; - my $penalties = ($self->is_renewal and not $self->check_penalty_on_renew) ? - [] : $self->gather_penalty_request(); + OpenILS::Utils::Penalty->calculate_penalties($self->editor, undef, $self->patron); + my $mask = ($self->is_renewal) ? 'RENEW' : 'CIRC'; + my $penalties = OpenILS::Utils::penalty->retrieve_penalties($self->editor, $patronid, $mask); push( @allevents, OpenILS::Event->new($_)) for (@$penalties, @$patron_events); } @@ -1205,18 +1172,11 @@ sub do_checkout { $self->handle_checkout_holds(); return if $self->bail_out; - # ------------------------------------------------------------------------------ - # Update the patron penalty info in the DB. Run it for permit-overrides or - # renewals since both of those cases do not require the penalty server to - # run during the permit phase of the checkout - # ------------------------------------------------------------------------------ - if( $self->permit_override or $self->is_renewal ) { - $U->update_patron_penalties( - authtoken => $self->editor->authtoken, - patron => $self->patron, - background => 1, - ); - } + # ------------------------------------------------------------------------------ + # Update the patron penalty info in the DB. Run it for permit-overrides + # since the penalties are not updated during the permit phase + # ------------------------------------------------------------------------------ + $U->update_patron_penalties_nonblock(patronid => $self->patron->id) if $self->permit_override; my $record = $U->record_to_mvr($self->title) unless $self->is_precat; $self->push_events( @@ -1796,15 +1756,7 @@ sub do_checkin { unless @{$self->events}; } - - # ------------------------------------------------------------------------------ - # Update the patron penalty info in the DB - # ------------------------------------------------------------------------------ - $U->update_patron_penalties( - authtoken => $self->editor->authtoken, - patron => $self->patron, - background => 1 ) if $self->is_checkin; - + $U->update_patron_penalties_nonblock(patronid => $self->patron->id) if $self->is_checkin; $self->checkin_flesh_events; return; } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm index c8a1129317..7c5aa6b981 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm @@ -195,10 +195,7 @@ sub make_payments { # ------------------------------------------------------------------------------ # Update the patron penalty info in the DB # ------------------------------------------------------------------------------ - $U->update_patron_penalties( - authtoken => $login, - patronid => $userid, - ); + $U->update_patron_penalties_nonblock(patronid => $userid); $client->respond_complete(1); @@ -405,10 +402,7 @@ sub billing_items_create { # ------------------------------------------------------------------------------ # Update the patron penalty info in the DB # ------------------------------------------------------------------------------ - $U->update_patron_penalties( - authtoken => $login, - patronid => $xact->usr, - ); + $U->update_patron_penalties_nonblock(patronid => $xact->usr); return $billing->id; } @@ -457,7 +451,7 @@ sub void_bill { $e->commit; # update the penalties for each affected user - $U->update_patron_penalties( authtoken => $authtoken, patronid => $_ ) for keys %users; + $U->update_patron_penalties_nonblock(patronid => $_) for keys %users; return 1; } -- 2.11.0