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;
12 my $parser = DateTime::Format::ISO8601->new;
13 my $log = 'OpenSRF::Utils::Logger';
18 my $c_t = action::circulation->table;
20 $grace = " - ($grace * (fine_interval))" if ($grace);
25 WHERE stop_fines IS NULL
26 AND due_date < ( CURRENT_TIMESTAMP $grace)
29 my $sth = action::circulation->db_Main->prepare_cached($sql);
32 return ( map { action::circulation->construct($_) } $sth->fetchall_hash );
39 my $grace = shift || '';
41 $client->respond( $_->to_fieldmapper ) for ( overdue_circs($grace) );
46 __PACKAGE__->register_method(
47 api_name => 'open-ils.storage.action.circulation.overdue',
50 method => 'grab_overdue',
59 my ($id) = action::hold_request->db_Main->selectrow_array(<<" SQL", {}, $pl,$cp);
61 FROM action.hold_request h
62 JOIN action.hold_copy_map hm ON (hm.hold = h.id)
63 WHERE h.pickup_lib = ?
64 AND hm.target_copy = ?
65 AND h.capture_time IS NULL
66 ORDER BY h.selection_depth DESC, h.pickup_lib - (SELECT home_ou FROM actor.usr a WHERE a.id = h.usr), h.request_time
71 __PACKAGE__->register_method(
72 api_name => 'open-ils.storage.action.hold_request.nearest_hold',
74 method => 'nearest_hold',
77 sub next_resp_group_id {
81 # XXX This is not replication safe!!!
83 my ($id) = action::survey->db_Main->selectrow_array(<<" SQL");
84 SELECT NEXTVAL('action.survey_response_group_id_seq'::TEXT)
88 __PACKAGE__->register_method(
89 api_name => 'open-ils.storage.action.survey_response.next_group_id',
91 method => 'next_resp_group_id',
94 sub patron_circ_summary {
99 return undef unless ($id);
100 my $c_table = action::circulation->table;
101 my $b_table = money::billing->table;
103 $log->debug("Retrieving patron summary for id $id", DEBUG);
105 my $select = <<" SQL";
106 SELECT COUNT(DISTINCT c.id), SUM( COALESCE(b.amount,0) )
108 LEFT OUTER JOIN $b_table b ON (c.id = b.xact AND b.voided = FALSE)
110 AND c.xact_finish IS NULL
112 c.stop_fines NOT IN ('CLAIMSRETURNED','LOST')
113 OR c.stop_fines IS NULL
117 return action::survey->db_Main->selectrow_arrayref($select, {}, $id);
119 __PACKAGE__->register_method(
120 api_name => 'open-ils.storage.action.circulation.patron_summary',
122 method => 'patron_circ_summary',
125 #XXX Fix stored proc calls
126 sub find_local_surveys {
131 return undef unless ($ou);
132 my $s_table = action::survey->table;
134 my $select = <<" SQL";
137 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
138 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
141 my $sth = action::survey->db_Main->prepare_cached($select);
144 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
148 __PACKAGE__->register_method(
149 api_name => 'open-ils.storage.action.survey.all',
152 method => 'find_local_surveys',
155 #XXX Fix stored proc calls
156 sub find_opac_surveys {
161 return undef unless ($ou);
162 my $s_table = action::survey->table;
164 my $select = <<" SQL";
167 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
168 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
172 my $sth = action::survey->db_Main->prepare_cached($select);
175 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
179 __PACKAGE__->register_method(
180 api_name => 'open-ils.storage.action.survey.opac',
183 method => 'find_opac_surveys',
186 sub find_optional_surveys {
191 return undef unless ($ou);
192 my $s_table = action::survey->table;
194 my $select = <<" SQL";
197 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
198 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
199 AND s.required IS FALSE;
202 my $sth = action::survey->db_Main->prepare_cached($select);
205 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
209 __PACKAGE__->register_method(
210 api_name => 'open-ils.storage.action.survey.optional',
213 method => 'find_optional_surveys',
216 sub find_required_surveys {
221 return undef unless ($ou);
222 my $s_table = action::survey->table;
224 my $select = <<" SQL";
227 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
228 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
229 AND s.required IS TRUE;
232 my $sth = action::survey->db_Main->prepare_cached($select);
235 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
239 __PACKAGE__->register_method(
240 api_name => 'open-ils.storage.action.survey.required',
243 method => 'find_required_surveys',
246 sub find_usr_summary_surveys {
251 return undef unless ($ou);
252 my $s_table = action::survey->table;
254 my $select = <<" SQL";
257 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
258 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
259 AND s.usr_summary IS TRUE;
262 my $sth = action::survey->db_Main->prepare_cached($select);
265 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
269 __PACKAGE__->register_method(
270 api_name => 'open-ils.storage.action.survey.usr_summary',
273 method => 'find_usr_summary_surveys',
286 push @circs, action::circulation->search_where( { id => $circ, stop_fines => undef } );
288 push @circs, overdue_circs($grace);
294 my $due_dt = $parser->parse_datetime( clense_ISO8601( $c->due_date ) );
296 my $due = $due_dt->epoch;
298 my $fine_interval = interval_to_seconds( $c->fine_interval );
300 if ( interval_to_seconds( $c->fine_interval ) >= interval_to_seconds('1d') ) {
301 my $tz_offset_s = 0;;
302 if ($due_dt->strftime('%z') =~ /(-|\+)(\d{2}):?(\d{2})/) {
303 $tz_offset_s = $1 . interval_to_seconds( "${2}h ${3}m");
306 $due -= ($due % $fine_interval) + $tz_offset_s;
307 $now -= ($now % $fine_interval) + $tz_offset_s;
311 "ARG! Overdue circulation ".$c->id.
312 " for item ".$c->target_copy.
313 " (user ".$c->usr.").\n".
314 "\tItem was due on or before: ".localtime($due)."\n");
316 my ($fine) = money::billing->search(
317 xact => $c->id, voided => 'f',
318 { order_by => 'billing_ts DESC', limit => '1' }
323 $last_fine = $parser->parse_datetime( clense_ISO8601( $fine->billing_ts ) )->epoch;
326 $last_fine += $fine_interval * $grace;
329 my $pending_fine_count = int( ($now - $last_fine) / $fine_interval );
330 unless($pending_fine_count) {
331 $client->respond( "\tNo fines to create. " );
332 if ($grace && $now < $due + $fine_interval * $grace) {
333 $client->respond( "Still inside grace period of: ". seconds_to_interval( $fine_interval * $grace)."\n" );
335 $client->respond( "Last fine generated for: ".localtime($last_fine)."\n" );
340 $client->respond( "\t$pending_fine_count pending fine(s)\n" );
342 for my $bill (1 .. $pending_fine_count) {
344 my ($total) = money::billable_transaction_summary->retrieve( $c->id );
346 if ($total && $total->balance_owed > $c->max_fine) {
347 $c->update({stop_fines => 'MAXFINES'});
349 "\tMaximum fine level of ".$c->max_fine.
350 " reached for this circulation.\n".
351 "\tNo more fines will be generated.\n" );
355 my $billing = money::billing->create(
357 note => "Overdue Fine",
358 billing_type => "Overdue materials",
359 amount => ''.$c->recuring_fine,
360 billing_ts => DateTime->from_epoch( epoch => $last_fine + $fine_interval * $bill )->strftime('%FT%T%z')
365 "\t\tCreating fine of ".$billing->amount." for period starting ".
367 $parser->parse_datetime(
368 clense_ISO8601( $billing->billing_ts )
374 $client->respond( "Error processing overdue circulation [".$c->id."]:\n\n$e\n" );
378 __PACKAGE__->register_method(
379 api_name => 'open-ils.storage.action.circulation.overdue.generate_fines',
382 method => 'generate_fines',
387 sub new_hold_copy_targeter {
390 my $check_expire = shift;
391 my $one_hold = shift;
394 $check_expire ||= '12h';
395 $check_expire = interval_to_seconds( $check_expire );
397 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time() - $check_expire);
400 my $expire_threshold = sprintf(
401 '%s-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d-00',
402 $year, $mon, $mday, $hour, $min, $sec
410 $holds = [ action::hold_request->search(id => $one_hold) ];
412 $holds = [ action::hold_request->search_where(
413 { capture_time => undef,
414 fulfillment_time => undef,
415 prev_check_time => { '<=' => $expire_threshold },
417 { order_by => 'selection_depth DESC, request_time,prev_check_time' } ) ];
418 push @$holds, action::hold_request->search(
419 capture_time => undef,
420 fulfillment_time => undef,
421 prev_check_time => undef,
422 { order_by => 'selection_depth DESC, request_time' } );
426 die "Could not retrieve uncaptured hold requests:\n\n$e\n";
430 for my $hold (@$holds) {
432 #action::hold_request->db_Main->begin_work;
433 if ($self->method_lookup('open-ils.storage.transaction.current')->run) {
434 $log->debug("Cleaning up after previous transaction\n");
435 $self->method_lookup('open-ils.storage.transaction.rollback')->run;
437 $self->method_lookup('open-ils.storage.transaction.begin')->run( $client );
438 $log->info("Processing hold ".$hold->id."...\n");
440 action::hold_copy_map->search( { hold => $hold->id } )->delete_all;
444 # find all the potential copies
445 if ($hold->hold_type eq 'M') {
448 metabib::record_descriptor
450 record => [ map { $_->id } metabib::metarecord
451 ->retrieve($hold->target)
453 item_type => [split '', $hold->holdable_formats]
457 ->method_lookup( 'open-ils.storage.biblio.record_entry.ranged_tree')
458 ->run( $r->id, $hold->request_lib->id, $hold->selection_depth );
460 for my $cn ( @{ $rtree->call_numbers } ) {
462 asset::copy->search( id => [map {$_->id} @{ $cn->copies }] );
465 } elsif ($hold->hold_type eq 'T') {
467 ->method_lookup( 'open-ils.storage.biblio.record_entry.ranged_tree')
468 ->run( $hold->target, $hold->request_lib->id, $hold->selection_depth );
471 push @successes, { hold => $hold->id, eligible_copies => 0, error => 'NO_RECORD' };
475 for my $cn ( @{ $rtree->call_numbers } ) {
477 asset::copy->search( id => [map {$_->id} @{ $cn->copies }] );
479 } elsif ($hold->hold_type eq 'V') {
481 ->method_lookup( 'open-ils.storage.asset.call_number.ranged_tree')
482 ->run( $hold->target, $hold->request_lib->id, $hold->selection_depth );
485 asset::copy->search( id => [map {$_->id} @{ $vtree->copies }] );
487 } elsif ($hold->hold_type eq 'C') {
489 $all_copies = [asset::copy->retrieve($hold->target)];
492 # let 'em know we're still working
493 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
495 if (!ref $all_copies || !@$all_copies) {
496 $log->info("\tNo copies available for targeting at all!\n");
497 $self->method_lookup('open-ils.storage.transaction.commit')->run;
498 push @successes, { hold => $hold->id, eligible_copies => 0, error => 'NO_COPIES' };
503 for my $c ( @$all_copies ) {
505 if ( OpenILS::Utils::PermitHold::permit_copy_hold(
506 { title => $c->call_number->record->to_fieldmapper,
507 title_descriptor => $c->call_number->record->record_descriptor->next->to_fieldmapper,
508 patron => $hold->usr->to_fieldmapper,
509 copy => $c->to_fieldmapper,
510 requestor => $hold->requestor->to_fieldmapper,
511 request_lib => $hold->request_lib->to_fieldmapper,
514 my $copy_count = @$copies;
515 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
517 # map the potentials, so that we can pick up checkins
518 $log->debug( "\tMapping ".scalar(@copies)." potential copies for hold ".$hold->id);
519 action::hold_copy_map->create( { hold => $hold->id, target_copy => $_->id } ) for (@copies);
522 for my $c (@$copies) {
523 next if ($c->id == $hold->current_copy);
524 push @good_copies, $c if ($c);
527 $log->debug("\t".scalar(@good_copies)." (non-current) copies available for targeting...");
529 my $old_best = $hold->current_copy;
530 $hold->update({ current_copy => undef });
532 if (!scalar(@good_copies)) {
533 $log->info("\tNo (non-current) copies eligible to fill the hold.");
534 if ( $old_best && grep { $old_best == $_ } @$copies ) {
535 $log->debug("\tPushing current_copy back onto the targeting list");
536 push @good_copies, $old_best;
538 $log->debug("\tcurrent_copy is no longer available for targeting... NEXT HOLD, PLEASE!");
539 $self->method_lookup('open-ils.storage.transaction.commit')->run;
540 push @successes, { hold => $hold->id, eligible_copies => 0, error => 'NO_TARGETS' };
545 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
550 $_->circ_lib == $hold->pickup_lib &&
551 ( $_->status == 0 || $_->status == 7 )
555 $copies = [grep {$_->circ_lib != $hold->pickup_lib } @good_copies];
557 my $best = $self->choose_nearest_copy($hold, $prox_list);
560 $prox_list = $self->create_prox_list( $hold->pickup_lib, $copies );
561 $best = $self->choose_nearest_copy($hold, $prox_list);
564 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
566 # hold wasn't fulfilled, record the fact
568 $log->info("\tHold was not (but should have been) fulfilled by ".$old_best->id);
569 action::unfulfilled_hold_list->create(
570 { hold => ''.$hold->id,
571 current_copy => ''.$old_best->id,
572 circ_lib => ''.$old_best->circ_lib,
577 $hold->update( { current_copy => ''.$best->id } );
578 $log->debug("\tTargeting copy ".$best->id." for hold fulfillment.");
580 $log->debug( "\tThere were no targetable copies for the hold" );
583 $hold->update( { prev_check_time => 'now' } );
584 $log->info("\tUpdating hold [".$hold->id."] with new 'current_copy' [".$best->id."] for hold fulfillment.");
586 $self->method_lookup('open-ils.storage.transaction.commit')->run;
587 $log->info("\tProcessing of hold ".$hold->id." complete.");
591 old_target => ($old_best ? $old_best->id : undef),
592 eligible_copies => $copy_count,
593 target => ($best ? $best->id : undef) };
598 $log->error("Processing of hold failed: $e");
599 $self->method_lookup('open-ils.storage.transaction.rollback')->run;
606 __PACKAGE__->register_method(
607 api_name => 'open-ils.storage.action.hold_request.copy_targeter',
609 method => 'new_hold_copy_targeter',
614 my %cache = (titles => {}, cns => {});
615 sub hold_copy_targeter {
618 my $check_expire = shift;
619 my $one_hold = shift;
621 $self->{user_filter} = OpenSRF::AppSession->create('open-ils.circ');
622 $self->{user_filter}->connect;
623 $self->{client} = $client;
626 $check_expire ||= '12h';
627 $check_expire = interval_to_seconds( $check_expire );
629 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time() - $check_expire);
632 my $expire_threshold = sprintf(
633 '%s-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d-00',
634 $year, $mon, $mday, $hour, $min, $sec
638 $statuses ||= [ config::copy_status->search(holdable => 't') ];
640 $locations ||= [ asset::copy_location->search(holdable => 't') ];
644 %cache = (titles => {}, cns => {});
648 $holds = [ action::hold_request->search(id => $one_hold) ];
650 $holds = [ action::hold_request->search_where(
651 { capture_time => undef,
652 prev_check_time => { '<=' => $expire_threshold },
654 { order_by => 'request_time,prev_check_time' } ) ];
655 push @$holds, action::hold_request->search(
656 capture_time => undef,
657 prev_check_time => undef,
658 { order_by => 'request_time' } );
662 die "Could not retrieve uncaptured hold requests:\n\n$e\n";
665 for my $hold (@$holds) {
667 #action::hold_request->db_Main->begin_work;
668 if ($self->method_lookup('open-ils.storage.transaction.current')->run) {
669 $client->respond("Cleaning up after previous transaction\n");
670 $self->method_lookup('open-ils.storage.transaction.rollback')->run;
672 $self->method_lookup('open-ils.storage.transaction.begin')->run( $client );
673 $client->respond("Processing hold ".$hold->id."...\n");
677 $copies = $self->metarecord_hold_capture($hold) if ($hold->hold_type eq 'M');
678 $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
680 $copies = $self->title_hold_capture($hold) if ($hold->hold_type eq 'T');
681 $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
683 $copies = $self->volume_hold_capture($hold) if ($hold->hold_type eq 'V');
684 $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
686 $copies = $self->copy_hold_capture($hold) if ($hold->hold_type eq 'C');
688 unless (ref $copies || !@$copies) {
689 $client->respond("\tNo copies available for targeting at all!\n");
693 for my $c (@$copies) {
694 next if ( grep {$c->id == $hold->current_copy} @good_copies);
695 push @good_copies, $c if ($c);
698 $client->respond("\t".scalar(@good_copies)." (non-current) copies available for targeting...\n");
700 my $old_best = $hold->current_copy;
701 $hold->update({ current_copy => undef });
703 if (!scalar(@good_copies)) {
704 $client->respond("\tNo (non-current) copies available to fill the hold.\n");
705 if ( $old_best && grep {$c->id == $hold->current_copy} @$copies ) {
706 $client->respond("\tPushing current_copy back onto the targeting list\n");
707 push @good_copies, asset::copy->retrieve( $old_best );
709 $client->respond("\tcurrent_copy is no longer available for targeting... NEXT HOLD, PLEASE!\n");
715 $$prox_list[0] = [grep {$_->circ_lib == $hold->pickup_lib } @good_copies];
716 $copies = [grep {$_->circ_lib != $hold->pickup_lib } @good_copies];
718 my $best = $self->choose_nearest_copy($hold, $prox_list);
721 $prox_list = $self->create_prox_list( $hold->pickup_lib, $copies );
722 $best = $self->choose_nearest_copy($hold, $prox_list);
726 # hold wasn't fulfilled, record the fact
728 $client->respond("\tHold was not (but should have been) fulfilled by ".$old_best->id.".\n");
729 action::unfulfilled_hold_list->create(
730 { hold => ''.$hold->id,
731 current_copy => ''.$old_best->id,
732 circ_lib => ''.$old_best->circ_lib,
737 $hold->update( { current_copy => ''.$best->id } );
738 $client->respond("\tTargeting copy ".$best->id." for hold fulfillment.\n");
741 $hold->update( { prev_check_time => 'now' } );
742 $client->respond("\tUpdating hold ".$hold->id." with new 'current_copy' for hold fulfillment.\n");
744 $client->respond("\tProcessing of hold ".$hold->id." complete.\n");
745 $self->method_lookup('open-ils.storage.transaction.commit')->run;
747 #action::hold_request->dbi_commit;
751 $log->error("Processing of hold failed: $e");
752 $client->respond("\tProcessing of hold failed!.\n\t\t$e\n");
753 $self->method_lookup('open-ils.storage.transaction.rollback')->run;
754 #action::hold_request->dbi_rollback;
758 $self->{user_filter}->disconnect;
759 $self->{user_filter}->finish;
760 delete $$self{user_filter};
763 __PACKAGE__->register_method(
764 api_name => 'open-ils.storage.action.hold_request.copy_targeter',
767 method => 'hold_copy_targeter',
771 sub copy_hold_capture {
776 if (!defined($cps)) {
778 $cps = [ asset::copy->search( id => $hold->target ) ];
781 die "Could not retrieve initial volume list:\n\n$e\n";
785 my @copies = grep { $_->holdable } @$cps;
787 for (my $i = 0; $i < @$cps; $i++) {
788 next unless $$cps[$i];
790 my $cn = $cache{cns}{$copies[$i]->call_number};
791 my $rec = $cache{titles}{$cn->record};
792 $copies[$i] = undef if ($copies[$i] && !grep{ $copies[$i]->status eq $_->id}@$statuses);
793 $copies[$i] = undef if ($copies[$i] && !grep{ $copies[$i]->location eq $_->id}@$locations);
794 $copies[$i] = undef if (
796 !$self->{user_filter}->request(
797 'open-ils.circ.permit_hold',
798 $hold->to_fieldmapper, do {
799 my $cp_fm = $copies[$i]->to_fieldmapper;
800 $cp_fm->circ_lib( $copies[$i]->circ_lib->to_fieldmapper );
801 $cp_fm->location( $copies[$i]->location->to_fieldmapper );
802 $cp_fm->status( $copies[$i]->status->to_fieldmapper );
805 { title => $rec->to_fieldmapper,
806 usr => actor::user->retrieve($hold->usr)->to_fieldmapper,
807 requestor => actor::user->retrieve($hold->requestor)->to_fieldmapper,
810 $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
813 @copies = grep { $_ } @copies;
817 return unless ($count);
819 action::hold_copy_map->search( { hold => $hold->id } )->delete_all;
822 $self->{client}->respond( "\tMapping ".scalar(@copies)." eligable copies for hold ".$hold->id."\n");
823 for my $c (@copies) {
824 push @maps, action::hold_copy_map->create( { hold => $hold->id, target_copy => $c->id } );
826 $self->{client}->respond( "\tA total of ".scalar(@maps)." mapping were created for hold ".$hold->id."\n");
832 sub choose_nearest_copy {
835 my $prox_list = shift;
837 for my $p ( 0 .. int( scalar(@$prox_list) - 1) ) {
838 next unless (ref $$prox_list[$p]);
839 my @capturable = grep { $_->status == 0 } @{ $$prox_list[$p] };
840 next unless (@capturable);
841 return $capturable[rand(scalar(@capturable))];
845 sub create_prox_list {
851 for my $cp (@$copies) {
852 my ($prox) = $self->method_lookup('open-ils.storage.asset.copy.proximity')->run( $cp->id, $lib );
853 $prox_list[$prox] = [] unless defined($prox_list[$prox]);
854 push @{$prox_list[$prox]}, $cp;
859 sub volume_hold_capture {
864 if (!defined($vols)) {
866 $vols = [ asset::call_number->search( id => $hold->target ) ];
867 $cache{cns}{$_->id} = $_ for (@$vols);
870 die "Could not retrieve initial volume list:\n\n$e\n";
874 my @v_ids = map { $_->id } @$vols;
878 $cp_list = [ asset::copy->search( call_number => \@v_ids ) ];
882 warn "Could not retrieve copy list:\n\n$e\n";
885 $self->copy_hold_capture($hold,$cp_list) if (ref $cp_list and @$cp_list);
888 sub title_hold_capture {
893 if (!defined($titles)) {
895 $titles = [ biblio::record_entry->search( id => $hold->target ) ];
896 $cache{titles}{$_->id} = $_ for (@$titles);
899 die "Could not retrieve initial title list:\n\n$e\n";
903 my @t_ids = map { $_->id } @$titles;
906 ($cn_list) = $self->method_lookup('open-ils.storage.direct.asset.call_number.search.record.atomic')->run( \@t_ids );
910 warn "Could not retrieve volume list:\n\n$e\n";
913 $cache{cns}{$_->id} = $_ for (@$cn_list);
915 $self->volume_hold_capture($hold,$cn_list) if (ref $cn_list and @$cn_list);
918 sub metarecord_hold_capture {
924 $titles = [ metabib::metarecord_source_map->search( metarecord => $hold->target) ];
928 die "Could not retrieve initial title list:\n\n$e\n";
932 my @recs = map {$_->record} metabib::record_descriptor->search( record => $titles, item_type => [split '', $hold->holdable_formats] );
934 $titles = [ biblio::record_entry->search( id => \@recs ) ];
938 die "Could not retrieve format-pruned title list:\n\n$e\n";
942 $cache{titles}{$_->id} = $_ for (@$titles);
943 $self->title_hold_capture($hold,$titles) if (ref $titles and @$titles);