From a0d2b8817ae38824043674aef7d054d6064ae389 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Wed, 28 Sep 2011 14:28:35 -0400 Subject: [PATCH] Add and use two YAOUS to allow hold targeting on copies at closed OUs One YAOUS completely ignores the closedness of the circ lib of the copy being tested for potential targeting. The other YAOUS ignores the closedness of the circ lib IFF the circ lib of the copy being tested matches the pickup lib of the hold request. Signed-off-by: Lebbeous Fogle-Weekley Signed-off-by: Mike Rylander --- .../Application/Storage/Publisher/action.pm | 57 ++++++++++++++++++- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 17 ++++++ .../XXXX.data.YAOUS-target-when-closed.sql | 24 ++++++++ 3 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.YAOUS-target-when-closed.sql diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm index eff589c35b..fb58c35407 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm @@ -2,7 +2,7 @@ package OpenILS::Application::Storage::Publisher::action; use parent qw/OpenILS::Application::Storage::Publisher/; use strict; use warnings; -use OpenSRF::Utils::Logger qw/:level/; +use OpenSRF::Utils::Logger qw/:level :logger/; use OpenSRF::Utils qw/:datetime/; use OpenSRF::Utils::JSON; use OpenSRF::AppSession; @@ -23,6 +23,24 @@ sub isTrue { return 0; } +sub ou_ancestor_setting_value_or_cache { + # cache should be specific to setting + my ($actor, $org_id, $setting, $cache) = @_; + + if (not exists $cache->{$org_id}) { + my $r = $actor->request( + 'open-ils.actor.ou_setting.ancestor_default', $org_id, $setting + )->gather(1); + + if ($r) { + $cache->{$org_id} = $r->{value}; + } else { + $cache->{$org_id} = undef; + } + } + return $cache->{$org_id}; +} + my $parser = DateTime::Format::ISO8601->new; my $log = 'OpenSRF::Utils::Logger'; @@ -1108,6 +1126,9 @@ sub new_hold_copy_targeter { my @successes; my $actor = OpenSRF::AppSession->create('open-ils.actor'); + my $target_when_closed = {}; + my $target_when_closed_if_at_pickup_lib = {}; + for my $hold (@$holds) { try { #start a transaction if needed @@ -1274,8 +1295,38 @@ sub new_hold_copy_targeter { # current target next if ($c->id eq $hold->current_copy); - # circ lib is closed - next if ( grep { ''.$_->org_unit eq ''.$c->circ_lib } @closed ); + # skip on circ lib is closed IFF we care + my $ignore_closing; + + if (''.$hold->pickup_lib eq ''.$c->circ_lib) { + $ignore_closing = ou_ancestor_setting_value_or_cache( + $actor, + ''.$c->circ_lib, + 'circ.holds.target_when_closed_if_at_pickup_lib', + $target_when_closed_if_at_pickup_lib + ) || 0; + } + if (not $ignore_closing) { # one more chance to find a reason + # to ignore OU closedness. + $ignore_closing = ou_ancestor_setting_value_or_cache( + $actor, + ''.$c->circ_lib, + 'circ.holds.target_when_closed', + $target_when_closed + ) || 0; + } + +# $logger->info( +# "For hold " . $hold->id . " and copy with circ_lib " . +# $c->circ_lib . " we " . +# ($ignore_closing ? "ignore" : "respect") +# . " closed dates" +# ); + + next if ( + (not $ignore_closing) and + (grep { ''.$_->org_unit eq ''.$c->circ_lib } @closed) + ); # target of another hold next if (action::hold_request diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 9ea1baad09..686471e585 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -4456,6 +4456,23 @@ INSERT into config.org_unit_setting_type 'If unset, the OPAC (only when wrapped in the staff client!) will default to showing you your ten most recent searches on the left side of the results and record details pages. If you actually don''t want to see this feature at all, set this value to zero at the top of your organizational tree.', 'coust', 'description'), 'integer', null) +,( 'circ.holds.target_when_closed', 'circ', + oils_i18n_gettext('circ.holds.target_when_closed', + 'Target copies for a hold even if copy''s circ lib is closed', + 'coust', 'label'), + oils_i18n_gettext('circ.holds.target_when_closed', + 'If this setting is true at a given org unit or one of its ancestors, the hold targeter will target copies from this org unit even if the org unit is closed (according to the actor.org_unit.closed_date table).', + 'coust', 'description'), + 'bool', null) +,( 'circ.holds.target_when_closed_if_at_pickup_lib', 'circ', + oils_i18n_gettext('circ.holds.target_when_closed_if_at_pickup_lib', + 'Target copies for a hold even if copy''s circ lib is closed IF the circ lib is the hold''s pickup lib', + 'coust', 'label'), + oils_i18n_gettext('circ.holds.target_when_closed_if_at_pickup_lib', + 'If this setting is true at a given org unit or one of its ancestors, the hold targeter will target copies from this org unit even if the org unit is closed (according to the actor.org_unit.closed_date table) IF AND ONLY IF the copy''s circ lib is the same as the hold''s pickup lib.', + 'coust', 'description'), + 'bool', null) + ,( 'opac.staff.jump_to_details_on_single_hit', 'opac', oils_i18n_gettext('opac.staff.jump_to_details_on_single_hit', diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.YAOUS-target-when-closed.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.YAOUS-target-when-closed.sql new file mode 100644 index 0000000000..0ab7a08eab --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.YAOUS-target-when-closed.sql @@ -0,0 +1,24 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +INSERT into config.org_unit_setting_type (name, grp, label, description, datatype) VALUES +( 'circ.holds.target_when_closed', 'circ', + oils_i18n_gettext('circ.holds.target_when_closed', + 'Target copies for a hold even if copy''s circ lib is closed', + 'coust', 'label'), + oils_i18n_gettext('circ.holds.target_when_closed', + 'If this setting is true at a given org unit or one of its ancestors, the hold targeter will target copies from this org unit even if the org unit is closed (according to the actor.org_unit.closed_date table).', + 'coust', 'description'), + 'bool'), +( 'circ.holds.target_when_closed_if_at_pickup_lib', 'circ', + oils_i18n_gettext('circ.holds.target_when_closed_if_at_pickup_lib', + 'Target copies for a hold even if copy''s circ lib is closed IF the circ lib is the hold''s pickup lib', + 'coust', 'label'), + oils_i18n_gettext('circ.holds.target_when_closed_if_at_pickup_lib', + 'If this setting is true at a given org unit or one of its ancestors, the hold targeter will target copies from this org unit even if the org unit is closed (according to the actor.org_unit.closed_date table) IF AND ONLY IF the copy''s circ lib is the same as the hold''s pickup lib.', + 'coust', 'description'), + 'bool') +; + +COMMIT; -- 2.43.2