my $e = new_editor();
- # this monster will grab all "holdable" copies for the given record
+=head old
my $copies = $e->search_asset_copy(
[
{ deleted => 'f', circulate => 't', holdable => 't' },
- { #flesh => 1,
- #flesh_fields => {
- # acp => ['circ_lib']
- #},
- join_filter => {
+ { 'join' => {
acpl => {
field => 'id',
fkey => 'location',
acn => {
field => 'id',
fkey => 'call_number',
- join_filter => {
+ 'join' => {
bre => {
field => 'id',
fkey => 'record',
}
],
);
+=cut
+
+ # this monster will grab the id and circ_lib of all of the "holdable" copies for the given record
+ my $copies = $e->json_query(
+ {
+ select => { acp => ['id', 'circ_lib'] },
+ from => {
+ acp => {
+ acn => {
+ field => 'id',
+ fkey => 'call_number',
+ 'join' => {
+ bre => {
+ field => 'id',
+ filter => { id => $titleid },
+ fkey => 'record'
+ }
+ }
+ },
+ acpl => { field => 'id', filter => { holdable => 't'}, fkey => 'location' },
+ ccs => { field => 'id', filter => { holdable => 't'}, fkey => 'status' }
+ }
+ },
+ where => {
+ '+acp' => { circulate => 't', deleted => 'f', holdable => 't' }
+ }
+ }
+ );
+ return $e->event unless defined $copies;
$logger->info("title possible found ".scalar(@$copies)." potential copies");
return 0 unless @$copies;
my %buckets;
my %hash = map { ($_->to_org => $_->prox) } @$home_prox;
- push( @{$buckets{ $hash{$_->circ_lib} } }, $_ ) for @$copies;
+ push( @{$buckets{ $hash{$_->{circ_lib}} } }, $_->{id} ) for @$copies;
my @keys = sort { $a <=> $b } keys %buckets;
my %buckets2;
my %hash2 = map { ($_->to_org => $_->prox) } @$req_prox;
- push( @{$buckets2{ $hash2{$_->circ_lib} } }, $_ ) for @$copies;
+ push( @{$buckets2{ $hash2{$_->{circ_lib}} } }, $_->{id} ) for @$copies;
my $highest_key = $keys[@keys - 1]; # the farthest prox in the exising buckets
my $new_key = $highest_key - 0.5; # right before the farthest prox
$logger->info("looking at " . scalar(@{$buckets{$key}}). " copies in proximity bucket $key");
- for my $copy (@cps) {
+ for my $copyid (@cps) {
- next if $seen{$copy->id};
- $seen{$copy->id} = 1; # there could be dupes given the merged buckets
- $logger->debug("looking at bucket_key=$key, copy ".$copy->id." : circ_lib = " . $copy->circ_lib);
+ next if $seen{$copyid};
+ $seen{$copyid} = 1; # there could be dupes given the merged buckets
+ my $copy = $e->retrieve_asset_copy($copyid) or return $e->event;
+ $logger->debug("looking at bucket_key=$key, copy $copyid : circ_lib = " . $copy->circ_lib);
unless($title) { # grab the title if we don't already have it
my $vol = $e->retrieve_asset_call_number(
my $method = $self->app.".direct.$type.$action";
if( $action eq 'search' ) {
- $method = "$method.atomic";
+ $method .= '.atomic';
} elsif( $action eq 'batch_retrieve' ) {
$action = 'search';
@arg = ( { id => $arg } );
$method =~ s/batch_retrieve/search/o;
- $method = "$method.atomic";
+ $method .= '.atomic';
} elsif( $action eq 'retrieve_all' ) {
$action = 'search';
$tt =~ s/\./::/og;
my $fmobj = "Fieldmapper::$tt";
@arg = ( { $fmobj->Identity => { '!=' => undef } } );
- $method = "$method.atomic";
+ $method .= '.atomic';
}
$method =~ s/search/id_list/o if $options->{idlist};
- $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
+ $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
# remove any stale events
$self->clear_event;
return undef;
}
- if( $action eq 'search' or $action eq 'batch_retrieve' or $action eq 'retrieve_all') {
+ if( $action eq 'search' ) {
$self->log(I, "$type.$action : returned ".scalar(@$obj). " result(s)");
$self->event(_mk_not_found($type, $arg)) unless @$obj;
}
eval $retrieveallf;
}
+sub json_query {
+ my( $self, $arg, $options ) = @_;
+ $options ||= {};
+ my @arg = ( ref($arg) eq 'ARRAY' ) ? @$arg : ($arg);
+ my $method = $self->app.'.json_query.atomic';
+ $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
+ $self->clear_event;
+ my $obj;
+ my $err;
+
+ try {
+ $obj = $self->request($method, @arg);
+ } catch Error with { $err = shift; };
+
+ if( $err ) {
+ $self->event(
+ OpenILS::Event->new( 'DATABASE_QUERY_FAILED',
+ payload => $arg, debug => "$err" ));
+ return undef;
+ }
+
+ $self->log(I, "json_query : returned ".scalar(@$obj). " result(s)");
+ return $obj;
+}
+
1;