Support script-based circ in nearest_hold()
authorDan Scott <dscott@laurentian.ca>
Mon, 17 Jun 2013 04:38:43 +0000 (00:38 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 19 Jun 2013 19:17:04 +0000 (15:17 -0400)
The nearest_hold() implementation recently changed to pull in the circ
library ID; however, if circulation runs through scripts, the circ
library on the copy object has been fleshed, and the nearest hold
routine gets very confused.

Check to see if we do, in fact, have an object instead of a plain
scalar, and assign the value to a placeholder variable accordingly.

Thanks to Jeff Godin for his great assistance on debugging this!

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Conflicts:
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm

(Just whitespace. Resolved by hand.  --miker)

Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm

index 42e5e84..7acb5fb 100644 (file)
@@ -49,7 +49,7 @@ my %HOLD_SORT_ORDER_BY = (
 
 
 sub isTrue {
-    my $v = shift;
+    my $v = shift || '0';
     return 1 if ($v == 1);
     return 1 if ($v =~ /^t/io);
     return 1 if ($v =~ /^y/io);
@@ -504,14 +504,23 @@ sub nearest_hold {
     my $age = shift() || '0 seconds';
     my $fifo = shift();
 
-    $log->info("deprecated 'fifo' param true, but ignored") if isTrue $fifo;
+    $log->info("deprecated 'fifo' param true, but ignored") if isTrue($fifo);
+
+    # ScriptBuilder fleshes the circ_lib, which confuses things; ensure we
+    # are working with a circ lib ID and not an object
+    my $cp_circ_lib;
+    if (ref $cp->circ_lib) {
+        $cp_circ_lib = $cp->circ_lib->id;
+    } else {
+        $cp_circ_lib = $cp->circ_lib;
+    }
 
     my ($holdsort, $addl_cte, $addl_join) =
         build_hold_sort_clause(get_hold_sort_order($here), $cp, $here);
 
     local $OpenILS::Application::Storage::WRITE = 1;
 
-    my $ids = action::hold_request->db_Main->selectcol_arrayref(<<"    SQL", {}, $cp->circ_lib, $here, $cp->id, $age);
+    my $ids = action::hold_request->db_Main->selectcol_arrayref(<<"    SQL", {}, $cp_circ_lib, $here, $cp->id, $age);
         WITH go_home_interval AS (
             SELECT OILS_JSON_TO_TEXT(
                 (SELECT value FROM actor.org_unit_ancestor_setting(