1 package OpenILS::Application::Storage::Publisher::action;
2 use base qw/OpenILS::Application::Storage/;
3 use OpenSRF::Utils::Logger qw/:level/;
4 use OpenSRF::Utils qw/:datetime/;
5 use OpenSRF::AppSession;
6 use OpenSRF::EX qw/:try/;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Utils::PermitHold;
10 use DateTime::Format::ISO8601;
13 my $parser = DateTime::Format::ISO8601->new;
14 my $log = 'OpenSRF::Utils::Logger';
16 sub ou_hold_requests {
21 my $h_table = action::hold_request->table;
22 my $c_table = asset::copy->table;
23 my $o_table = actor::org_unit->table;
28 JOIN $c_table cp ON (cp.id = h.current_copy)
29 JOIN $o_table ou ON (ou.id = cp.circ_lib)
31 AND h.capture_time IS NULL
32 ORDER BY h.request_time
35 my $sth = action::hold_request->db_Main->prepare_cached($SQL);
38 $client->respond($_) for (
41 ->method_lookup('open-ils.storage.direct.action.hold_request.retrieve')
45 } @{ $sth->fetchall_arrayref }
49 __PACKAGE__->register_method(
50 api_name => 'open-ils.storage.action.targeted_hold_request.org_unit',
54 method => 'ou_hold_requests',
61 my $c_t = action::circulation->table;
63 $grace = " - ($grace * (fine_interval))" if ($grace);
68 WHERE stop_fines IS NULL
69 AND due_date < ( CURRENT_TIMESTAMP $grace)
72 my $sth = action::circulation->db_Main->prepare_cached($sql);
75 return ( map { action::circulation->construct($_) } $sth->fetchall_hash );
82 my $grace = shift || '';
84 $client->respond( $_->to_fieldmapper ) for ( overdue_circs($grace) );
89 __PACKAGE__->register_method(
90 api_name => 'open-ils.storage.action.circulation.overdue',
93 method => 'grab_overdue',
102 my ($id) = action::hold_request->db_Main->selectrow_array(<<" SQL", {}, $pl,$cp);
104 FROM action.hold_request h
105 JOIN action.hold_copy_map hm ON (hm.hold = h.id)
106 WHERE h.pickup_lib = ?
107 AND hm.target_copy = ?
108 AND h.capture_time IS NULL
109 ORDER BY h.pickup_lib - (SELECT home_ou FROM actor.usr a WHERE a.id = h.usr), h.selection_depth DESC, h.request_time
114 __PACKAGE__->register_method(
115 api_name => 'open-ils.storage.action.hold_request.nearest_hold',
117 method => 'nearest_hold',
120 sub next_resp_group_id {
124 # XXX This is not replication safe!!!
126 my ($id) = action::survey->db_Main->selectrow_array(<<" SQL");
127 SELECT NEXTVAL('action.survey_response_group_id_seq'::TEXT)
131 __PACKAGE__->register_method(
132 api_name => 'open-ils.storage.action.survey_response.next_group_id',
134 method => 'next_resp_group_id',
137 sub patron_circ_summary {
142 return undef unless ($id);
143 my $c_table = action::circulation->table;
144 my $b_table = money::billing->table;
146 $log->debug("Retrieving patron summary for id $id", DEBUG);
148 my $select = <<" SQL";
149 SELECT COUNT(DISTINCT c.id), SUM( COALESCE(b.amount,0) )
151 LEFT OUTER JOIN $b_table b ON (c.id = b.xact AND b.voided = FALSE)
153 AND c.xact_finish IS NULL
155 c.stop_fines NOT IN ('CLAIMSRETURNED','LOST')
156 OR c.stop_fines IS NULL
160 return action::survey->db_Main->selectrow_arrayref($select, {}, $id);
162 __PACKAGE__->register_method(
163 api_name => 'open-ils.storage.action.circulation.patron_summary',
165 method => 'patron_circ_summary',
168 #XXX Fix stored proc calls
169 sub find_local_surveys {
174 return undef unless ($ou);
175 my $s_table = action::survey->table;
177 my $select = <<" SQL";
180 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
181 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
184 my $sth = action::survey->db_Main->prepare_cached($select);
187 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
191 __PACKAGE__->register_method(
192 api_name => 'open-ils.storage.action.survey.all',
195 method => 'find_local_surveys',
198 #XXX Fix stored proc calls
199 sub find_opac_surveys {
204 return undef unless ($ou);
205 my $s_table = action::survey->table;
207 my $select = <<" SQL";
210 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
211 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
215 my $sth = action::survey->db_Main->prepare_cached($select);
218 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
222 __PACKAGE__->register_method(
223 api_name => 'open-ils.storage.action.survey.opac',
226 method => 'find_opac_surveys',
229 sub find_optional_surveys {
234 return undef unless ($ou);
235 my $s_table = action::survey->table;
237 my $select = <<" SQL";
240 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
241 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
242 AND s.required IS FALSE;
245 my $sth = action::survey->db_Main->prepare_cached($select);
248 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
252 __PACKAGE__->register_method(
253 api_name => 'open-ils.storage.action.survey.optional',
256 method => 'find_optional_surveys',
259 sub find_required_surveys {
264 return undef unless ($ou);
265 my $s_table = action::survey->table;
267 my $select = <<" SQL";
270 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
271 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
272 AND s.required IS TRUE;
275 my $sth = action::survey->db_Main->prepare_cached($select);
278 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
282 __PACKAGE__->register_method(
283 api_name => 'open-ils.storage.action.survey.required',
286 method => 'find_required_surveys',
289 sub find_usr_summary_surveys {
294 return undef unless ($ou);
295 my $s_table = action::survey->table;
297 my $select = <<" SQL";
300 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
301 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
302 AND s.usr_summary IS TRUE;
305 my $sth = action::survey->db_Main->prepare_cached($select);
308 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
312 __PACKAGE__->register_method(
313 api_name => 'open-ils.storage.action.survey.usr_summary',
316 method => 'find_usr_summary_surveys',
329 push @circs, action::circulation->search_where( { id => $circ, stop_fines => undef } );
331 push @circs, overdue_circs($grace);
337 my $due_dt = $parser->parse_datetime( clense_ISO8601( $c->due_date ) );
339 my $due = $due_dt->epoch;
341 my $fine_interval = interval_to_seconds( $c->fine_interval );
343 if ( interval_to_seconds( $c->fine_interval ) >= interval_to_seconds('1d') ) {
344 my $tz_offset_s = 0;;
345 if ($due_dt->strftime('%z') =~ /(-|\+)(\d{2}):?(\d{2})/) {
346 $tz_offset_s = $1 . interval_to_seconds( "${2}h ${3}m");
349 $due -= ($due % $fine_interval) + $tz_offset_s;
350 $now -= ($now % $fine_interval) + $tz_offset_s;
354 "ARG! Overdue circulation ".$c->id.
355 " for item ".$c->target_copy.
356 " (user ".$c->usr.").\n".
357 "\tItem was due on or before: ".localtime($due)."\n");
359 my ($fine) = money::billing->search(
360 xact => $c->id, voided => 'f',
361 { order_by => 'billing_ts DESC', limit => '1' }
366 $last_fine = $parser->parse_datetime( clense_ISO8601( $fine->billing_ts ) )->epoch;
369 $last_fine += $fine_interval * $grace;
372 my $pending_fine_count = int( ($now - $last_fine) / $fine_interval );
373 unless($pending_fine_count) {
374 $client->respond( "\tNo fines to create. " );
375 if ($grace && $now < $due + $fine_interval * $grace) {
376 $client->respond( "Still inside grace period of: ". seconds_to_interval( $fine_interval * $grace)."\n" );
378 $client->respond( "Last fine generated for: ".localtime($last_fine)."\n" );
383 $client->respond( "\t$pending_fine_count pending fine(s)\n" );
385 for my $bill (1 .. $pending_fine_count) {
387 my ($total) = money::billable_transaction_summary->retrieve( $c->id );
389 if ($total && $total->balance_owed > $c->max_fine) {
390 $c->update({stop_fines => 'MAXFINES'});
392 "\tMaximum fine level of ".$c->max_fine.
393 " reached for this circulation.\n".
394 "\tNo more fines will be generated.\n" );
398 my $billing = money::billing->create(
400 note => "Overdue Fine",
401 billing_type => "Overdue materials",
402 amount => ''.$c->recuring_fine,
403 billing_ts => DateTime->from_epoch( epoch => $last_fine + $fine_interval * $bill )->strftime('%FT%T%z')
408 "\t\tCreating fine of ".$billing->amount." for period starting ".
410 $parser->parse_datetime(
411 clense_ISO8601( $billing->billing_ts )
417 $client->respond( "Error processing overdue circulation [".$c->id."]:\n\n$e\n" );
421 __PACKAGE__->register_method(
422 api_name => 'open-ils.storage.action.circulation.overdue.generate_fines',
425 method => 'generate_fines',
430 sub new_hold_copy_targeter {
433 my $check_expire = shift;
434 my $one_hold = shift;
437 $check_expire ||= '12h';
438 $check_expire = interval_to_seconds( $check_expire );
440 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time() - $check_expire);
443 my $expire_threshold = sprintf(
444 '%s-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d-00',
445 $year, $mon, $mday, $hour, $min, $sec
453 $holds = [ action::hold_request->search(id => $one_hold) ];
455 $holds = [ action::hold_request->search_where(
456 { capture_time => undef,
457 fulfillment_time => undef,
458 prev_check_time => { '<=' => $expire_threshold },
460 { order_by => 'selection_depth DESC, request_time,prev_check_time' } ) ];
461 push @$holds, action::hold_request->search(
462 capture_time => undef,
463 fulfillment_time => undef,
464 prev_check_time => undef,
465 { order_by => 'selection_depth DESC, request_time' } );
469 die "Could not retrieve uncaptured hold requests:\n\n$e\n";
473 for my $hold (@$holds) {
475 #action::hold_request->db_Main->begin_work;
476 if ($self->method_lookup('open-ils.storage.transaction.current')->run) {
477 $log->debug("Cleaning up after previous transaction\n");
478 $self->method_lookup('open-ils.storage.transaction.rollback')->run;
480 $self->method_lookup('open-ils.storage.transaction.begin')->run( $client );
481 $log->info("Processing hold ".$hold->id."...\n");
483 action::hold_copy_map->search( { hold => $hold->id } )->delete_all;
487 # find all the potential copies
488 if ($hold->hold_type eq 'M') {
491 metabib::record_descriptor
493 record => [ map { $_->id } metabib::metarecord
494 ->retrieve($hold->target)
496 item_type => [split '', $hold->holdable_formats]
500 ->method_lookup( 'open-ils.storage.biblio.record_entry.ranged_tree')
501 ->run( $r->id, $hold->usr->home_ou->id, $hold->selection_depth );
503 for my $cn ( @{ $rtree->call_numbers } ) {
505 asset::copy->search( id => [map {$_->id} @{ $cn->copies }] );
508 } elsif ($hold->hold_type eq 'T') {
510 ->method_lookup( 'open-ils.storage.biblio.record_entry.ranged_tree')
511 ->run( $hold->target, $hold->usr->home_ou->id, $hold->selection_depth );
514 push @successes, { hold => $hold->id, eligible_copies => 0, error => 'NO_RECORD' };
518 for my $cn ( @{ $rtree->call_numbers } ) {
520 asset::copy->search( id => [map {$_->id} @{ $cn->copies }] );
522 } elsif ($hold->hold_type eq 'V') {
524 ->method_lookup( 'open-ils.storage.asset.call_number.ranged_tree')
525 ->run( $hold->target, $hold->usr->home_ou->id, $hold->selection_depth );
528 asset::copy->search( id => [map {$_->id} @{ $vtree->copies }] );
530 } elsif ($hold->hold_type eq 'C') {
532 $all_copies = [asset::copy->retrieve($hold->target)];
535 # let 'em know we're still working
536 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
538 if (!ref $all_copies || !@$all_copies) {
539 $log->info("\tNo copies available for targeting at all!\n");
540 $self->method_lookup('open-ils.storage.transaction.commit')->run;
541 push @successes, { hold => $hold->id, eligible_copies => 0, error => 'NO_COPIES' };
546 for my $c ( @$all_copies ) {
548 if ( OpenILS::Utils::PermitHold::permit_copy_hold(
549 { title => $c->call_number->record->to_fieldmapper,
550 title_descriptor => $c->call_number->record->record_descriptor->next->to_fieldmapper,
551 patron => $hold->usr->to_fieldmapper,
552 copy => $c->to_fieldmapper,
553 requestor => $hold->requestor->to_fieldmapper,
554 request_lib => $hold->request_lib->to_fieldmapper,
557 my $copy_count = @$copies;
558 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
560 # map the potentials, so that we can pick up checkins
561 $log->debug( "\tMapping ".scalar(@copies)." potential copies for hold ".$hold->id);
562 action::hold_copy_map->create( { hold => $hold->id, target_copy => $_->id } ) for (@copies);
565 for my $c (@$copies) {
566 next if ($c->id == $hold->current_copy);
567 push @good_copies, $c if ($c);
570 $log->debug("\t".scalar(@good_copies)." (non-current) copies available for targeting...");
572 my $old_best = $hold->current_copy;
573 $hold->update({ current_copy => undef });
575 if (!scalar(@good_copies)) {
576 $log->info("\tNo (non-current) copies eligible to fill the hold.");
577 if ( $old_best && grep { $old_best == $_ } @$copies ) {
578 $log->debug("\tPushing current_copy back onto the targeting list");
579 push @good_copies, $old_best;
581 $log->debug("\tcurrent_copy is no longer available for targeting... NEXT HOLD, PLEASE!");
582 $self->method_lookup('open-ils.storage.transaction.commit')->run;
583 push @successes, { hold => $hold->id, eligible_copies => 0, error => 'NO_TARGETS' };
588 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
593 $_->circ_lib == $hold->pickup_lib &&
594 ( $_->status == 0 || $_->status == 7 )
598 $copies = [grep {$_->circ_lib != $hold->pickup_lib } @good_copies];
600 my $best = $self->choose_nearest_copy($hold, $prox_list);
603 $prox_list = $self->create_prox_list( $hold->pickup_lib, $copies );
604 $best = $self->choose_nearest_copy($hold, $prox_list);
607 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
609 # hold wasn't fulfilled, record the fact
611 $log->info("\tHold was not (but should have been) fulfilled by ".$old_best->id);
612 action::unfulfilled_hold_list->create(
613 { hold => ''.$hold->id,
614 current_copy => ''.$old_best->id,
615 circ_lib => ''.$old_best->circ_lib,
620 $hold->update( { current_copy => ''.$best->id } );
621 $log->debug("\tTargeting copy ".$best->id." for hold fulfillment.");
623 $log->debug( "\tThere were no targetable copies for the hold" );
626 $hold->update( { prev_check_time => 'now' } );
627 $log->info("\tUpdating hold [".$hold->id."] with new 'current_copy' [".$best->id."] for hold fulfillment.");
629 $self->method_lookup('open-ils.storage.transaction.commit')->run;
630 $log->info("\tProcessing of hold ".$hold->id." complete.");
634 old_target => ($old_best ? $old_best->id : undef),
635 eligible_copies => $copy_count,
636 target => ($best ? $best->id : undef) };
641 $log->error("Processing of hold failed: $e");
642 $self->method_lookup('open-ils.storage.transaction.rollback')->run;
649 __PACKAGE__->register_method(
650 api_name => 'open-ils.storage.action.hold_request.copy_targeter',
652 method => 'new_hold_copy_targeter',
657 my %cache = (titles => {}, cns => {});
658 sub hold_copy_targeter {
661 my $check_expire = shift;
662 my $one_hold = shift;
664 $self->{user_filter} = OpenSRF::AppSession->create('open-ils.circ');
665 $self->{user_filter}->connect;
666 $self->{client} = $client;
669 $check_expire ||= '12h';
670 $check_expire = interval_to_seconds( $check_expire );
672 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time() - $check_expire);
675 my $expire_threshold = sprintf(
676 '%s-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d-00',
677 $year, $mon, $mday, $hour, $min, $sec
681 $statuses ||= [ config::copy_status->search(holdable => 't') ];
683 $locations ||= [ asset::copy_location->search(holdable => 't') ];
687 %cache = (titles => {}, cns => {});
691 $holds = [ action::hold_request->search(id => $one_hold) ];
693 $holds = [ action::hold_request->search_where(
694 { capture_time => undef,
695 prev_check_time => { '<=' => $expire_threshold },
697 { order_by => 'request_time,prev_check_time' } ) ];
698 push @$holds, action::hold_request->search(
699 capture_time => undef,
700 prev_check_time => undef,
701 { order_by => 'request_time' } );
705 die "Could not retrieve uncaptured hold requests:\n\n$e\n";
708 for my $hold (@$holds) {
710 #action::hold_request->db_Main->begin_work;
711 if ($self->method_lookup('open-ils.storage.transaction.current')->run) {
712 $client->respond("Cleaning up after previous transaction\n");
713 $self->method_lookup('open-ils.storage.transaction.rollback')->run;
715 $self->method_lookup('open-ils.storage.transaction.begin')->run( $client );
716 $client->respond("Processing hold ".$hold->id."...\n");
720 $copies = $self->metarecord_hold_capture($hold) if ($hold->hold_type eq 'M');
721 $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
723 $copies = $self->title_hold_capture($hold) if ($hold->hold_type eq 'T');
724 $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
726 $copies = $self->volume_hold_capture($hold) if ($hold->hold_type eq 'V');
727 $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
729 $copies = $self->copy_hold_capture($hold) if ($hold->hold_type eq 'C');
731 unless (ref $copies || !@$copies) {
732 $client->respond("\tNo copies available for targeting at all!\n");
736 for my $c (@$copies) {
737 next if ( grep {$c->id == $hold->current_copy} @good_copies);
738 push @good_copies, $c if ($c);
741 $client->respond("\t".scalar(@good_copies)." (non-current) copies available for targeting...\n");
743 my $old_best = $hold->current_copy;
744 $hold->update({ current_copy => undef });
746 if (!scalar(@good_copies)) {
747 $client->respond("\tNo (non-current) copies available to fill the hold.\n");
748 if ( $old_best && grep {$c->id == $hold->current_copy} @$copies ) {
749 $client->respond("\tPushing current_copy back onto the targeting list\n");
750 push @good_copies, asset::copy->retrieve( $old_best );
752 $client->respond("\tcurrent_copy is no longer available for targeting... NEXT HOLD, PLEASE!\n");
758 $$prox_list[0] = [grep {$_->circ_lib == $hold->pickup_lib } @good_copies];
759 $copies = [grep {$_->circ_lib != $hold->pickup_lib } @good_copies];
761 my $best = $self->choose_nearest_copy($hold, $prox_list);
764 $prox_list = $self->create_prox_list( $hold->pickup_lib, $copies );
765 $best = $self->choose_nearest_copy($hold, $prox_list);
769 # hold wasn't fulfilled, record the fact
771 $client->respond("\tHold was not (but should have been) fulfilled by ".$old_best->id.".\n");
772 action::unfulfilled_hold_list->create(
773 { hold => ''.$hold->id,
774 current_copy => ''.$old_best->id,
775 circ_lib => ''.$old_best->circ_lib,
780 $hold->update( { current_copy => ''.$best->id } );
781 $client->respond("\tTargeting copy ".$best->id." for hold fulfillment.\n");
784 $hold->update( { prev_check_time => 'now' } );
785 $client->respond("\tUpdating hold ".$hold->id." with new 'current_copy' for hold fulfillment.\n");
787 $client->respond("\tProcessing of hold ".$hold->id." complete.\n");
788 $self->method_lookup('open-ils.storage.transaction.commit')->run;
790 #action::hold_request->dbi_commit;
794 $log->error("Processing of hold failed: $e");
795 $client->respond("\tProcessing of hold failed!.\n\t\t$e\n");
796 $self->method_lookup('open-ils.storage.transaction.rollback')->run;
797 #action::hold_request->dbi_rollback;
801 $self->{user_filter}->disconnect;
802 $self->{user_filter}->finish;
803 delete $$self{user_filter};
806 __PACKAGE__->register_method(
807 api_name => 'open-ils.storage.action.hold_request.copy_targeter',
810 method => 'hold_copy_targeter',
814 sub copy_hold_capture {
819 if (!defined($cps)) {
821 $cps = [ asset::copy->search( id => $hold->target ) ];
824 die "Could not retrieve initial volume list:\n\n$e\n";
828 my @copies = grep { $_->holdable } @$cps;
830 for (my $i = 0; $i < @$cps; $i++) {
831 next unless $$cps[$i];
833 my $cn = $cache{cns}{$copies[$i]->call_number};
834 my $rec = $cache{titles}{$cn->record};
835 $copies[$i] = undef if ($copies[$i] && !grep{ $copies[$i]->status eq $_->id}@$statuses);
836 $copies[$i] = undef if ($copies[$i] && !grep{ $copies[$i]->location eq $_->id}@$locations);
837 $copies[$i] = undef if (
839 !$self->{user_filter}->request(
840 'open-ils.circ.permit_hold',
841 $hold->to_fieldmapper, do {
842 my $cp_fm = $copies[$i]->to_fieldmapper;
843 $cp_fm->circ_lib( $copies[$i]->circ_lib->to_fieldmapper );
844 $cp_fm->location( $copies[$i]->location->to_fieldmapper );
845 $cp_fm->status( $copies[$i]->status->to_fieldmapper );
848 { title => $rec->to_fieldmapper,
849 usr => actor::user->retrieve($hold->usr)->to_fieldmapper,
850 requestor => actor::user->retrieve($hold->requestor)->to_fieldmapper,
853 $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
856 @copies = grep { $_ } @copies;
860 return unless ($count);
862 action::hold_copy_map->search( { hold => $hold->id } )->delete_all;
865 $self->{client}->respond( "\tMapping ".scalar(@copies)." eligable copies for hold ".$hold->id."\n");
866 for my $c (@copies) {
867 push @maps, action::hold_copy_map->create( { hold => $hold->id, target_copy => $c->id } );
869 $self->{client}->respond( "\tA total of ".scalar(@maps)." mapping were created for hold ".$hold->id."\n");
875 sub choose_nearest_copy {
878 my $prox_list = shift;
880 for my $p ( 0 .. int( scalar(@$prox_list) - 1) ) {
881 next unless (ref $$prox_list[$p]);
882 my @capturable = grep { $_->status == 0 } @{ $$prox_list[$p] };
883 next unless (@capturable);
884 return $capturable[rand(scalar(@capturable))];
888 sub create_prox_list {
894 for my $cp (@$copies) {
895 my ($prox) = $self->method_lookup('open-ils.storage.asset.copy.proximity')->run( $cp->id, $lib );
896 $prox_list[$prox] = [] unless defined($prox_list[$prox]);
897 push @{$prox_list[$prox]}, $cp;
902 sub volume_hold_capture {
907 if (!defined($vols)) {
909 $vols = [ asset::call_number->search( id => $hold->target ) ];
910 $cache{cns}{$_->id} = $_ for (@$vols);
913 die "Could not retrieve initial volume list:\n\n$e\n";
917 my @v_ids = map { $_->id } @$vols;
921 $cp_list = [ asset::copy->search( call_number => \@v_ids ) ];
925 warn "Could not retrieve copy list:\n\n$e\n";
928 $self->copy_hold_capture($hold,$cp_list) if (ref $cp_list and @$cp_list);
931 sub title_hold_capture {
936 if (!defined($titles)) {
938 $titles = [ biblio::record_entry->search( id => $hold->target ) ];
939 $cache{titles}{$_->id} = $_ for (@$titles);
942 die "Could not retrieve initial title list:\n\n$e\n";
946 my @t_ids = map { $_->id } @$titles;
949 ($cn_list) = $self->method_lookup('open-ils.storage.direct.asset.call_number.search.record.atomic')->run( \@t_ids );
953 warn "Could not retrieve volume list:\n\n$e\n";
956 $cache{cns}{$_->id} = $_ for (@$cn_list);
958 $self->volume_hold_capture($hold,$cn_list) if (ref $cn_list and @$cn_list);
961 sub metarecord_hold_capture {
967 $titles = [ metabib::metarecord_source_map->search( metarecord => $hold->target) ];
971 die "Could not retrieve initial title list:\n\n$e\n";
975 my @recs = map {$_->record} metabib::record_descriptor->search( record => $titles, item_type => [split '', $hold->holdable_formats] );
977 $titles = [ biblio::record_entry->search( id => \@recs ) ];
981 die "Could not retrieve format-pruned title list:\n\n$e\n";
985 $cache{titles}{$_->id} = $_ for (@$titles);
986 $self->title_hold_capture($hold,$titles) if (ref $titles and @$titles);