use OpenSRF::AppSession;
use OpenSRF::Utils::Logger qw(:logger);
use OpenSRF::Utils::JSON;
+use OpenSRF::Utils::SettingsClient;
use OpenILS::Utils::DateTime qw/:datetime/;
use OpenILS::Application::AppUtils;
use OpenILS::Utils::CStoreEditor qw/:funcs/;
my $self = {
editor => new_editor(),
ou_setting_cache => {},
+ status_cache_time => 0,
+ status_check_time => 0,
+ targetable_statuses => [0,7],
%args,
};
return bless($self, $class);
hopeless_prone => 't'
});
$self->{hopeless_prone_status_ids} = { map { $_->id => 1} @{ $hopeless_prone } };
+
+ my $sc = OpenSRF::Utils::SettingsClient->new;
+ my $timeout = $sc->config_value(apps => "open-ils.hold-targeter" => app_settings => "status_cache_time") || 300;
+ $self->{status_cache_time} = $timeout;
+ $self->{targetable_statuses} = $self->get_targetable_statuses();
}
}
}
+# Get the list of statuses able to target a hold, i.e. allowed for the
+# current_copy. Default to 0 and 7 if there ia a failure.
+sub get_targetable_statuses {
+ my $self = shift;
+ if (time() > $self->{status_check_time}) {
+ my $e = $self->{editor};
+ $self->{targetable_statuses} = $e->search_config_copy_status({holdable => 't', is_available => 't'},
+ {idlist => 1});
+ unless (ref($self->{targetable_statuses}) eq 'ARRAY' && @{$self->{targetable_statuses}}) {
+ $self->{targetable_statuses} = [0,7];
+ }
+ $self->{status_check_time} = $self->{status_cache_time} + time();
+ }
+ return $self->{targetable_statuses};
+}
+
# -----------------------------------------------------------------------
# Knows how to target a single hold.
# -----------------------------------------------------------------------
# Track checked out copies for later recall
$self->recall_copies([grep {$_->{status} == 1} @{$self->copies}]);
+ my $targetable_statuses = $self->parent->get_targetable_statuses();
$self->copies([
- grep {$_->{status} == 0 || $_->{status} == 7} @{$self->copies}
+ grep {
+ my $c = $_;
+ grep {$c->{status} == $_} @{$targetable_statuses}
+ } @{$self->copies}
]);
return 1;