From 7b224d1b0357eed7ee57565d01059f0d23625f03 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 4 Jun 2010 20:53:24 +0000 Subject: [PATCH] Experimental implementation: renewal, block, enable. Add sip_renewal (not implemented), correct log message w/ join Patron block message and patron enable This adds code for enable, still experimental. It also adds the client's block message to the patron alert, bracketed by tags. The tags are necessary because enable has to be able to regexp out the block alert message (including user-specified variable text). Remove unused vars. Whitespace cleanup and extra feedback data. Return object on failure, not just 0 Signed-off-by: Joe Atzberger git-svn-id: svn://svn.open-ils.org/ILS/trunk@16598 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Circ/Circulate.pm | 68 ++++++++++------------ Open-ILS/src/perlmods/OpenILS/SIP.pm | 14 ++--- Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm | 59 +++++++++++++++---- .../src/perlmods/OpenILS/SIP/Transaction/Renew.pm | 5 +- 4 files changed, 86 insertions(+), 60 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index 0fd1dd52f..2a9c5859a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -40,12 +40,12 @@ sub initialize { $logger->error( "Missing circ script(s)" ) unless( $p and $c and $d and $f and $m and $pr ); - $scripts{circ_permit_patron} = $p; - $scripts{circ_permit_copy} = $c; - $scripts{circ_duration} = $d; - $scripts{circ_recurring_fines}= $f; - $scripts{circ_max_fines} = $m; - $scripts{circ_permit_renew} = $pr; + $scripts{circ_permit_patron} = $p; + $scripts{circ_permit_copy} = $c; + $scripts{circ_duration} = $d; + $scripts{circ_recurring_fines} = $f; + $scripts{circ_max_fines} = $m; + $scripts{circ_permit_renew} = $pr; $logger->debug( "circulator: Loaded rules scripts for circ: " . @@ -120,15 +120,15 @@ __PACKAGE__->register_method( ); __PACKAGE__->register_method( - method => "run_method", - api_name => "open-ils.circ.checkin.override", - signature => q/@see open-ils.circ.checkin/ + method => "run_method", + api_name => "open-ils.circ.checkin.override", + signature => q/@see open-ils.circ.checkin/ ); __PACKAGE__->register_method( - method => "run_method", - api_name => "open-ils.circ.renew.override", - signature => q/@see open-ils.circ.renew/, + method => "run_method", + api_name => "open-ils.circ.renew.override", + signature => q/@see open-ils.circ.renew/, ); @@ -144,29 +144,28 @@ __PACKAGE__->register_method( NOTES __PACKAGE__->register_method( - method => "run_method", - api_name => "open-ils.circ.checkout.full"); + method => "run_method", + api_name => "open-ils.circ.checkout.full" +); __PACKAGE__->register_method( - method => "run_method", - api_name => "open-ils.circ.checkout.full.override"); - + method => "run_method", + api_name => "open-ils.circ.checkout.full.override" +); __PACKAGE__->register_method( - method => "run_method", - api_name => "open-ils.circ.reservation.pickup"); + method => "run_method", + api_name => "open-ils.circ.reservation.pickup" +); __PACKAGE__->register_method( - method => "run_method", - api_name => "open-ils.circ.reservation.return"); - + method => "run_method", + api_name => "open-ils.circ.reservation.return" +); __PACKAGE__->register_method( - method => "run_method", - api_name => "open-ils.circ.checkout.inspect", - desc => q/ - Returns the circ matrix test result and, on success, the rule set and matrix test object - / + method => "run_method", + api_name => "open-ils.circ.checkout.inspect", + desc => q/Returns the circ matrix test result and, on success, the rule set and matrix test object/ ); - sub run_method { my( $self, $conn, $auth, $args ) = @_; translate_legacy_args($args); @@ -197,7 +196,7 @@ sub run_method { if ($transit) { # yes! unwrap it. my $reservation = $circulator->editor->retrieve_booking_reservation( $transit->reservation ); - my $res_type = $circulator->editor->retrieve_booking_resource_type( $reservation->target_resource_type ); + my $res_type = $circulator->editor->retrieve_booking_resource_type( $reservation->target_resource_type ); if ($U->is_true($res_type->catalog_item)) { # is there a copy to be had here? if (my $copy = $circulator->editor->search_asset_copy({ barcode => $bc, deleted => 'f' })->[0]) { # got a copy @@ -338,7 +337,7 @@ sub run_method { # Log the events my @e = @{$circulator->events}; push( @ee, $_->{textcode} ) for @e; - $logger->info("circulator: bailing out with events: @ee"); + $logger->info("circulator: bailing out with events: " . (join ", ", @ee)); $circulator->editor->rollback; @@ -502,6 +501,7 @@ my @AUTOLOAD_FIELDS = qw/ opac_renewal phone_renewal desk_renewal + sip_renewal retarget matrix_test_result circ_matrix_matchpoint @@ -568,7 +568,7 @@ sub new { # if this is a renewal, default to desk_renewal $self->desk_renewal(1) unless - $self->opac_renewal or $self->phone_renewal; + $self->opac_renewal or $self->phone_renewal or $self->sip_renewal; $self->capture('') unless $self->capture; @@ -2847,10 +2847,6 @@ sub check_checkin_copy_status { my $self = shift; my $copy = $self->copy; - my $islost = 0; - my $ismissing = 0; - my $evt = undef; - my $status = $U->copy_status($copy->status)->id; return undef @@ -3133,7 +3129,7 @@ sub make_trigger_events { my $self = shift; return unless $self->circ; $U->create_events_for_hook('checkout', $self->circ, $self->circ_lib) if $self->is_checkout; - $U->create_events_for_hook('checkin', $self->circ, $self->circ_lib) if $self->is_checkin; + $U->create_events_for_hook('checkin', $self->circ, $self->circ_lib) if $self->is_checkin; $U->create_events_for_hook('renewal', $self->circ, $self->circ_lib) if $self->is_renewal; } diff --git a/Open-ILS/src/perlmods/OpenILS/SIP.pm b/Open-ILS/src/perlmods/OpenILS/SIP.pm index 829556e9e..d02aa2c33 100644 --- a/Open-ILS/src/perlmods/OpenILS/SIP.pm +++ b/Open-ILS/src/perlmods/OpenILS/SIP.pm @@ -26,7 +26,7 @@ my $U = 'OpenILS::Application::AppUtils'; my $editor; my $config; -my $target_encoding; +my $target_encoding; # FIXME: this is configured at the institution level. use Digest::MD5 qw(md5_hex); @@ -176,7 +176,7 @@ sub login { { username => $username, password => md5_hex($seed . md5_hex($password)), - type => 'opac', + type => 'opac', } ); @@ -286,7 +286,7 @@ sub checkout { $xact->item($item); if (!$patron) { - $xact->screen_msg("Invalid Patron"); + $xact->screen_msg("Invalid Patron Barcode '$patron_id'"); return $xact; } @@ -296,7 +296,7 @@ sub checkout { } if( !$item ) { - $xact->screen_msg("Invalid Item"); + $xact->screen_msg("Invalid Item Barcode: '$item_id'"); return $xact; } @@ -316,13 +316,10 @@ sub checkout { $xact->desensitize(!$item->magnetic); if( $xact->ok ) { - #editor()->commit; syslog("LOG_DEBUG", "OILS: OpenILS::Checkout: " . "patron %s checkout %s succeeded", $patron_id, $item_id); - } else { - #editor()->xact_rollback; syslog("LOG_DEBUG", "OILS: OpenILS::Checkout: " . "patron %s checkout %s FAILED, rolling back xact...", $patron_id, $item_id); @@ -364,7 +361,6 @@ sub checkin { #editor()->xact_rollback; syslog('LOG_WARNING', "OILS: Checkin failed"); } - # END TRANSACTION return $xact; } @@ -374,7 +370,7 @@ sub checkin { ## We don't do anything with it. sub end_patron_session { my ($self, $patron_id) = @_; - return (1, 'Thank you for using OpenILS!', ''); + return (1, 'Thank you!', ''); } diff --git a/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm b/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm index c003eb34d..5cfe6b784 100644 --- a/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm +++ b/Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm @@ -78,9 +78,9 @@ sub new { return undef; } - $self->{user} = $user; - $self->{id} = $patron_id; - $self->{editor} = $e; + $self->{user} = $user; + $self->{id} = $patron_id; + $self->{editor} = $e; syslog("LOG_DEBUG", "OILS: new OpenILS Patron(%s): found patron : barred=%s, card:active=%s", $patron_id, $self->{user}->barred, $self->{user}->card->active ); @@ -159,14 +159,14 @@ sub language { # How much more detail do we need to check here? sub charge_ok { my $self = shift; - my $u = $self->{user}; - return (($u->barred eq 'f') and ($u->card->active eq 't')); + my $u = $self->{user}; + return (($u->barred eq 'f') and ($u->card->active eq 't')); } # How much more detail do we need to check here? sub renew_ok { my $self = shift; - return $self->charge_ok; + return $self->charge_ok; } sub recall_ok { @@ -176,13 +176,13 @@ sub recall_ok { sub hold_ok { my $self = shift; - return $self->charge_ok; + return $self->charge_ok; } # return true if the card provided is marked as lost sub card_lost { my $self = shift; - return $self->{user}->card->active eq 'f'; + return $self->{user}->card->active eq 'f'; } sub recall_overdue { @@ -511,6 +511,7 @@ sub unavail_holds { sub block { my ($self, $card_retained, $blocked_card_msg) = @_; + $blocked_card_msg ||= ''; my $e = $self->{editor}; my $u = $self->{user}; @@ -532,8 +533,8 @@ sub block { # retrieve the un-fleshed user object for update $u = $e->retrieve_actor_user($u->id); my $note = OpenILS::SIP::clean_text($u->alert_message) || ""; - $note = "CARD BLOCKED BY SELF-CHECK MACHINE\n$note"; # XXX Config option - + $note = " CARD BLOCKED BY SELF-CHECK MACHINE. $blocked_card_msg\n$note"; # XXX Config option + $note =~ s/\s*$//; # kill trailng whitespace $u->alert_message($note); if( ! $e->update_actor_user($u) ) { @@ -551,9 +552,43 @@ sub block { # Testing purposes only sub enable { - my $self = shift; - # Un-mark card as inactive, grep out the patron alert + my ($self, $card_retained, $blocked_card_msg) = @_; $self->{screen_msg} = "All privileges restored."; + +# Un-mark card as inactive, grep out the patron alert + my $u = $self->{user}; + my $e = $self->{editor} = OpenILS::SIP->reset_editor(); + + syslog('LOG_INFO', "OILS: Unblocking user %s", $u->card->barcode ); + + return $self if $u->card->active eq 't'; + + $u->card->active('t'); + if( ! $e->update_actor_card($u->card) ) { + syslog('LOG_ERR', "OILS: Unblock card update failed: %s", $e->event->{textcode}); + $e->xact_rollback; + return $self; + } + + # retrieve the un-fleshed user object for update + $u = $e->retrieve_actor_user($u->id); + my $note = OpenILS::SIP::clean_text($u->alert_message) || ""; + $note =~ s#.*##; + $note =~ s/^\s*//; # kill leading whitespace + $note =~ s/\s*$//; # kill trailng whitespace + $u->alert_message($note); + + if( ! $e->update_actor_user($u) ) { + syslog('LOG_ERR', "OILS: Unblock: patron alert update failed: %s", $e->event->{textcode}); + $e->xact_rollback; + return $self; + } + + # stay in synch + $self->{user}->alert_message( $note ); + + $e->commit; # commits and resets + $self->{editor} = OpenILS::SIP->reset_editor(); return $self; } diff --git a/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Renew.pm b/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Renew.pm index 1dfb35071..fb2681e1d 100644 --- a/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Renew.pm +++ b/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Renew.pm @@ -36,11 +36,10 @@ sub do_renew { { barcode => $self->item->id, patron_barcode => $self->patron->id }); if( my $code = $U->event_code($resp) ) { - my $txt = $resp->{textcode}; - syslog('LOG_INFO', "OILS: Renewal failed with event $code : $txt"); + syslog('LOG_INFO', "OILS: Renewal failed with event $code : " . $resp->{textcode}); $self->renewal_ok(0); $self->ok(0); - return 0; + return $self; } $self->item->{due_date} = $resp->{payload}->{circ}->due_date; -- 2.11.0