From 9f382fe54d0b38987161fb67d2f062b2daf9b07b Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 6 Jan 2006 23:16:54 +0000 Subject: [PATCH] more utility methods scripts can now retrieve hold objects based on "current_copy" other methods to follow git-svn-id: svn://svn.open-ils.org/ILS/trunk@2650 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Actor.pm | 110 ------------------ .../perlmods/OpenILS/Application/AppUtils.pm | 6 +- .../OpenILS/Application/Circ/Circulate.pm | 57 +++++++-- .../OpenILS/Application/Circ/Holds.pm | 12 +- 4 files changed, 65 insertions(+), 120 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index cb80da6af0..f2dfc5343f 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -1314,115 +1314,5 @@ sub get_user_perm_groups { } - - 1; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__END__ - - -some old methods that may be good to keep around for now - -sub _delete_card { - my( $session, $card ) = @_; - - warn "Deleting card with barcode " . $card->barcode() . "\n"; - my $req = $session->request( - "open-ils.storage.direct.actor.card.delete", - $card ); - my $status = $req->gather(1); - if(!defined($status)) { - throw OpenSRF::EX::ERROR - ("Unknown error updating card"); - } -} - - - -# deletes the patron and any attached addresses and cards -__PACKAGE__->register_method( - method => "delete_patron", - api_name => "open-ils.actor.patron.delete", -); - -sub delete_patron { - - my( $self, $client, $patron ) = @_; - my $session = $apputils->start_db_session(); - my $err = undef; - - try { - - $patron->clear_mailing_address(); - $patron->clear_billing_address(); - $patron->ischanged(1); - - _update_patron($session, $patron); - _delete_address($session,$_) for (@{$patron->addresses()}); - _delete_card($session,$_) for (@{$patron->cards()}); - _delete_patron($session,$patron); - $apputils->commit_db_session($session); - - } catch Error with { - my $e = shift; - $err = "-*- Failure deleting user: $e"; - $apputils->rollback_db_session($session); - warn $err; - }; - - if($err) { throw OpenSRF::EX::ERROR ($err); } - warn "Patron Delete complete\n"; - return 1; -} - -sub _delete_patron { - my( $session, $patron ) = @_; - - warn "Deleting patron " . $patron->usrname() . "\n"; - - my $req = $session->request( - "open-ils.storage.direct.actor.user.delete", - $patron ); - my $status = $req->gather(1); - if(!defined($status)) { - throw OpenSRF::EX::ERROR - ("Unknown error updating patron"); - } -} - - diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index 4e8fae8c01..1a3410fa07 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -560,8 +560,8 @@ sub fetch_permission_group_tree { my $self = shift; $logger->debug("Fetching patron profiles"); return $self->simplereq( - 'open-ils.storage', - "open-ils.storage.direct.permission.grp_tree.retrieve.all.atomic"); + 'open-ils.actor', + 'open-ils.actor.groups.tree.retrieve' ); } @@ -580,4 +580,6 @@ sub fetch_patron_circ_summary { return undef; } + + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index f48b4bee73..d96937a957 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -1,16 +1,19 @@ package OpenILS::Application::Circ::Circulate; use base 'OpenSRF::Application'; use strict; use warnings; -use Data::Dumper; use OpenSRF::EX qw(:try); +use Data::Dumper; use OpenSRF::Utils::Logger qw(:logger); use OpenILS::Utils::ScriptRunner; use OpenILS::Application::AppUtils; +use OpenILS::Application::Circ::Holds; my $apputils = "OpenILS::Application::AppUtils"; +my $holdcode = "OpenILS::Application::Circ::Holds"; my %scripts; # - circulation script filenames my $standings; # - cached patron standings my $group_tree; # - cached permission group tree +my $script_libs; # - any additional script libraries # ------------------------------------------------------------------------------ # Load the circ script from the config @@ -27,6 +30,7 @@ sub initialize { my $m = $conf->config_value( @pfx, 'max_fines' ); my $pr = $conf->config_value( @pfx, 'permit_renew' ); my $ph = $conf->config_value( @pfx, 'permit_hold' ); + my $lb = $conf->config_value( @pfx, 'script_lib' ); $logger->error( "Missing circ script(s)" ) unless( $p and $d and $f and $m and $pr and $ph ); @@ -38,6 +42,9 @@ sub initialize { $scripts{circ_renew_permit} = $pr; $scripts{hold_permit} = $ph; + $lb = [ $lb ] unless ref($lb); + $script_libs = $lb; + $logger->debug("Loaded rules scripts for circ: " . "circ permit : $p, circ duration :$d , circ recurring fines : $f, " . "circ max fines : $m, circ renew permit : $pr, permit hold: $ph"); @@ -93,9 +100,25 @@ sub create_circ_env { # ------------------------------------------------------------------------------ sub _doctor_circ_objects { my( $patron, $title, $copy, $summary ) = @_; + + # set the patron standing to the standing name for my $s (@$standings) { - $patron->standing( $s->value) if( $s->id eq $patron->standing); + $patron->standing( $s->value ) if( $s->id eq $patron->standing); + } + + # set the patron ptofile to the profile name + $patron->profile( _patron_get_profile( $patron, $group_tree ) ); +} + +# recurse and find the patron profile name from the tree +sub _patron_get_profile { + my( $patron, $group_tree ) = @_; + return $group_tree->name if ($group_tree->id eq $patron->profile); + for my $child (@{$group_tree->children}) { + my $ret = _patron_get_profile( $patron, $child ); + return $ret if $ret; } + return undef; } @@ -105,7 +128,10 @@ sub _doctor_circ_objects { sub _build_circ_script_runner { my( $patron, $title, $copy, $summary ) = @_; - my $runner = OpenILS::Utils::ScriptRunner->new( type => 'js' ); + $logger->debug("Loading script environment for circulation"); + + my $runner = OpenILS::Utils::ScriptRunner->new( + type => 'js', libs => $script_libs ); $runner->insert( 'patron', $patron ); $runner->insert( 'title', $title ); @@ -119,13 +145,26 @@ sub _build_circ_script_runner { if($summary) { $runner->insert( 'patron_info', {} ); - $runner->insert( 'patron_info.copy_count', $summary->[0] ); + $runner->insert( 'patron_info.items_out', $summary->[0] ); $runner->insert( 'patron_info.fines', $summary->[1] ); } + _add_script_runner_methods( $runner ); return $runner; } +sub _add_script_runner_methods { + my $runner = shift; + + $runner->context->function_set( + 'fetch_hold_by_copy', sub { + my $copyid = shift; + my $hold = $holdcode->fetch_open_hold_by_current_copy($copyid); + $runner->insert( 'hold', $hold ) if $hold; + } + ); +} + # ------------------------------------------------------------------------------ @@ -146,15 +185,19 @@ sub permit_circ { my ( $requestor, $patron, $env, $evt ); # check permisson of the requestor - ( $requestor, $patron, $evt ) = $apputils->checkses_requestor( + ( $requestor, $patron, $evt ) = + $apputils->checkses_requestor( $authtoken, $patronid, 'VIEW_PERMIT_CHECKOUT' ); return $evt if $evt; # fetch and build the circulation environment - ( $env, $evt ) = create_circ_env( barcode => $barcode, - patron => $patron, fetch_patron_circ_summary => 1 ); + ( $env, $evt ) = create_circ_env( + barcode => $barcode, + patron => $patron, + fetch_patron_circ_summary => 1 ); return $evt if $evt; + # run the script my $runner = $env->{runner}; $runner->load($scripts{circ_permit}); $runner->run or throw OpenSRF::EX::ERROR ("Circ Permit Script Died"); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm index 2460c4c3b8..1eea00e29c 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm @@ -18,6 +18,7 @@ package OpenILS::Application::Circ::Holds; use base qw/OpenSRF::Application/; use strict; use warnings; use OpenILS::Application::AppUtils; +use Data::Dumper; use OpenILS::EX; use OpenSRF::EX qw(:try); use OpenILS::Perm; @@ -246,7 +247,6 @@ sub update_hold { $logger->activity('User ' + $requestor->id . ' updating hold ' . $hold->id . ' for user ' . $target->id ); - use Data::Dumper; return $apputils->simplereq( 'open-ils.storage', @@ -446,6 +446,16 @@ sub create_hold_transit { } +sub fetch_open_hold_by_current_copy { + my $class = shift; + my $copyid = shift; + my $hold = $apputils->simplereq( + 'open-ils.storage', + 'open-ils.storage.direct.action.hold_request.search.atomic', + current_copy => $copyid , fulfillment_time => undef ); + return $hold->[0] if ref($hold); + return undef; +} 1; -- 2.43.2