use OpenSRF::Utils::Logger qw(:logger);
use OpenILS::Application::AppUtils;
use OpenILS::Utils::CStoreEditor qw/:funcs/;
+use OpenSRF::Utils qw/:datetime/;
# WIP notes:
# avoid 'duplicate key value violates unique constraint "copy_once_per_hold"'
return bless($self, $class);
}
+sub editor {
+ my $self = shift;
+ return $self->{editor};
+}
+
sub init {
my $self = shift;
return $targeter->result;
}
+# Targets all holds whose prev_check_time is older than the provide interval.
+# Also targets all holds that have never been targeted.
+sub target_all {
+ my $self = shift;
+ my @responses;
+ push(@responses, $self->target_hold($_)) for $self->collect_hold_ids;
+ return \@responses;
+}
+
+sub collect_hold_ids {
+ my $self = shift;
+
+ $self->{retarget_interval} ||= '12h';
+
+ my $date = DateTime->now->subtract(
+ seconds => interval_to_seconds($self->{retarget_interval}));
+
+ my $rtime_sort = $self->{newest_first} ? 'DESC' : 'ASC';
+
+ my $query = {
+ select => {ahr => ['id']},
+ from => 'ahr',
+ where => {
+ capture_time => undef,
+ fulfillment_time => undef,
+ frozen => 'f',
+ cancel_time => undef,
+ '-or' => [
+ {prev_check_time => undef},
+ {prev_check_time => {'<=' => $date->strftime('%F %T%z')}}
+ ]
+ },
+ order_by => [
+ {class => 'ahr', field => 'selection_depth', direction => 'DESC'},
+ {class => 'ahr', field => 'request_time', direction => $rtime_sort},
+ {class => 'ahr', field => 'prev_check_time'}
+ ]
+ };
+
+ my $holds = $self->editor->json_query($query);
+
+ return map {$_->{id}} @$holds;
+}
+
# -----------------------------------------------------------------------
# Knows how to target a single hold.
my $hold = $e->retrieve_action_hold_request($hold_id)
or return $self->exit_targeter("No hold found", 1);
- $self->hold($hold);
-
return $self->exit_targeter("Hold is not eligible for targeting")
- if $hold->capture_time || $hold->cancel_time;
+ if $hold->capture_time ||
+ $hold->cancel_time ||
+ $hold->fulfillment_time ||
+ $U->is_true($hold->frozen);
+
+ $self->hold($hold);
return unless $self->handle_expired_hold;
return unless $self->get_hold_copies;