return $self->{hold};
}
+sub inside_hard_stall_interval {
+ my ($self) = @_;
+ if (defined $self->{inside_hard_stall_interval}) {
+ $self->log_hold('already looked up hard stalling state: '.$self->{inside_hard_stall_interval});
+ return $self->{inside_hard_stall_interval};
+ }
+
+ my $hard_stall_interval =
+ $self->parent->get_ou_setting(
+ $self->hold->pickup_lib, 'circ.pickup_hold_stalling.hard', $self->editor) || '0 seconds';
+
+ $self->log_hold('hard stalling interval '.$hard_stall_interval);
+
+ my $hold_request_time = $dt_parser->parse_datetime(clean_ISO8601($self->hold->request_time));
+ my $hard_stall_time = $hold_request_time->clone->add(
+ seconds => OpenILS::Utils::DateTime->interval_to_seconds($hard_stall_interval)
+ );
+
+ if (DateTime->compare($hard_stall_time, DateTime->now(time_zone => 'local')) > 0) {
+ $self->{inside_hard_stall_interval} = 1
+ } else {
+ $self->{inside_hard_stall_interval} = 0
+ }
+
+ $self->log_hold('hard stalling state: '.$self->{inside_hard_stall_interval});
+ return $self->{inside_hard_stall_interval};
+}
+
# Debug message
sub message {
my ($self, $message) = @_;
return $self->{recall_copies};
}
+sub in_use_copies {
+ my ($self, $in_use_copies) = @_;
+ $self->{in_use_copies} = $in_use_copies if $in_use_copies;
+ return $self->{in_use_copies};
+}
+
# Maps copy ID's to their hold proximity
sub copy_prox_map {
my ($self, $copy_prox_map) = @_;
my %prox_map;
for my $copy_hash (@{$self->copies}) {
my $prox = $copy_prox_map{$copy_hash->{id}};
+ $copy_hash->{proximity} = $prox;
$prox_map{$prox} ||= [];
my $weight = $self->parent->get_ou_setting(
push(@{$prox_map{$prox}}, $copy_hash) foreach (1 .. $weight);
}
+ # We need to grab the proximity for copies targeted by other holds
+ # that belong to this pickup lib for hard-stalling tests later. We'll
+ # just grab them all in case it's useful later.
+ for my $copy_hash (@{$self->in_use_copies}) {
+ my $prox = $copy_prox_map{$copy_hash->{id}};
+ $copy_hash->{proximity} = $prox;
+ }
+
+ # We also need the proximity for the previous target.
+ if ($self->{valid_previous_copy}) {
+ my $prox = $copy_prox_map{$self->{valid_previous_copy}->{id}};
+ $self->{valid_previous_copy}->{proximity} = $prox;
+ }
+
return $self->{weighted_prox_map} = \%prox_map;
}
sub filter_copies_in_use {
my $self = shift;
+ # Copies that are targeted, but could contribute to pickup lib
+ # hard (foreign) stalling. These are Available-status copies.
+ $self->in_use_copies([grep {$_->{current_copy}} @{$self->copies}]);
+
# A copy with a 'current_copy' value means it's in use by another hold.
$self->copies([
grep {!$_->{current_copy}} @{$self->copies}
sub attempt_to_find_copy {
my $self = shift;
- return undef unless @{$self->copies};
+ $self->log_hold("attempting to find a copy normally");
my $max_loops = $self->parent->get_ou_setting(
$self->hold->pickup_lib,
my $hold = $self->hold;
my %seen;
+ # See if there are in-use (targeted) copies "here".
+ my $have_local_copies = 0;
+ if ($self->inside_hard_stall_interval) { # But only if we're inside the hard age.
+ if (grep { $_->{proximity} <= 0 } @{$self->in_use_copies}) {
+ $have_local_copies = 1;
+ }
+ $self->log_hold("inside hard stall interval and does ".
+ ($have_local_copies ? "" : "not "). "have in-use local copies");
+ }
+
# Pick a copy at random from each tier of the proximity map,
# starting at the lowest proximity and working up, until a
# copy is found that is suitable for targeting.
+ my $no_copies = 1;
for my $prox (sort {$a <=> $b} keys %prox_map) {
my @copies = @{$prox_map{$prox}};
next unless @copies;
+ $no_copies = 0;
+ $have_local_copies = 1 if ($prox <= 0);
+
+ $self->log_hold("inside hard stall interval and does ".
+ ($have_local_copies ? "" : "not "). "have testable local copies")
+ if ($self->inside_hard_stall_interval && $prox > 0);
+
+ if ($have_local_copies and $self->inside_hard_stall_interval) {
+ # Unset valid_previous_copy if it's not local and we have local copies now
+ $self->{valid_previous_copy} = undef if (
+ $self->{valid_previous_copy}
+ and $self->{valid_previous_copy}->{proximity} > 0
+ );
+ last if ($prox > 0); # No point in looking further "out".
+ }
+
my $rand = int(rand(scalar(@copies)));
while (my ($c) = splice(@copies, $rand, 1)) {
}
}
+ if ($no_copies and $have_local_copies and $self->inside_hard_stall_interval) {
+ # Unset valid_previous_copy if it's not local and we have local copies now
+ $self->{valid_previous_copy} = undef if (
+ $self->{valid_previous_copy}
+ and $self->{valid_previous_copy}->{proximity} > 0
+ );
+ }
+
return undef;
}
'Pickup Library Soft stalling interval',
'coust', 'label'),
oils_i18n_gettext('circ.pickup_hold_stalling.soft',
- 'When set for the pickup library, this specifies that only items scanned at the pickup library can be opportunistically captured for this time period. Example "5 days". This setting takes precedence over "Soft stalling interval" (circ.hold_stalling.soft).',
+ 'When set for the pickup library, this specifies that for holds with a request time age smaller than this interval only items scanned at the pickup library can be opportunistically captured. Example "5 days". This setting takes precedence over "Soft stalling interval" (circ.hold_stalling.soft) when the interval is in force.',
'coust', 'description'),
'interval', null)
+,( 'circ.pickup_hold_stalling.hard', 'holds',
+ oils_i18n_gettext('circ.pickup_hold_stalling.hard',
+ 'Pickup Library Hard stalling interval',
+ 'coust','label'),
+ oils_i18n_gettext('circ.pickup_hold_stalling.hard',
+ 'When set for the pickup library, this specifies that no items with a calculated proximity greater than 0 from the pickup library can be directly targeted for this time period if there are local available copies. Example "3 days".',
+ 'coust','description'),
+ 'interval', null)
+
,( 'circ.hold_stalling_hard', 'holds',
oils_i18n_gettext('circ.hold_stalling_hard',
'Hard stalling interval',
( 'circ.pickup_hold_stalling.soft',
'holds',
'Pickup Library Soft stalling interval',
- 'When set for the pickup library, this specifies that only items scanned at the pickup library can be opportunistically captured for this time period. Example "5 days". This setting takes precedence over "Soft stalling interval" (circ.hold_stalling.soft).',
+ 'When set for the pickup library, this specifies that for holds with a request time age smaller than this interval only items scanned at the pickup library can be opportunistically captured. Example "5 days". This setting takes precedence over "Soft stalling interval" (circ.hold_stalling.soft) when the interval is in force.',
+ 'interval',
+ null
+);
+
+INSERT into config.org_unit_setting_type
+( name, grp, label, description, datatype, fm_class ) VALUES
+( 'circ.pickup_hold_stalling.hard',
+ 'holds',
+ 'Pickup Library Hard stalling interval',
+ 'When set for the pickup library, this specifies that no items with a calculated proximity greater than 0 from the pickup library can be directly targeted for this time period if there are local available copies. Example "3 days".',
'interval',
null
);