method => 'grab_overdue',
);
+sub get_hold_sort_order {
+ my ($ou) = @_;
+
+ my $dbh = action::hold_request->db_Main;
+
+ # The purpose of this function is to return column names in a DB-configured
+ # order, so it won't do to add columns here or change column names unless
+ # you also change the expectation of anything calling this function.
+
+ my $row = $dbh->selectrow_hashref(
+ q!
+ SELECT
+ cbho.pprox, cbho.hprox, cbho.aprox, cbho.priority,
+ cbho.cut, cbho.depth, cbho.htime, cbho.rtime
+ FROM config.best_hold_order cbho
+ WHERE id = (
+ SELECT oils_json_to_text(value)::INT
+ FROM actor.org_unit_ancestor_setting('circ.hold_capture_order', ?)
+ )
+ !, undef, $ou
+ ) || {
+ pprox => 1, hprox => 8, aprox => 2, priority => 3,
+ cut => 4, depth => 5, htime => 7, rtime => 6
+ };
+
+ # Return only the keys of our hash, sorted by value,
+ # keys for null values omitted.
+ return grep { defined $row->{$_} } (
+ sort {$row->{$a} cmp $row->{$b}} keys %$row
+ );
+}
+
+sub build_hold_sort_clause {
+ my (@columns) = @_;
+
+ my %HOLD_SORT_EXPRESSIONS = (
+ pprox => 'p.prox',
+ hprox => '',
+ aprox => '',
+ priority => 'pgt.hold_priority',
+ cut => '',
+ depth => 'h.selection_depth',
+ rtime => 'h.request_time',
+ htime => ''
+ );
+
+
+}
+
sub nearest_hold {
my $self = shift;
my $client = shift;
my $age = shift() || '0 seconds';
my $fifo = shift();
- local $OpenILS::Application::Storage::WRITE = 1;
+ if (isTrue($fifo)) {
+ $log->info("deprecated 'fifo' param true, but ignored");
+ }
- my $holdsort = isTrue($fifo) ?
- "pgt.hold_priority, CASE WHEN h.cut_in_line IS TRUE THEN 0 ELSE 1 END, h.request_time, h.selection_depth DESC, COALESCE(hm.proximity, h.prox) " :
- "COALESCE(hm.proximity, h.prox), pgt.hold_priority, CASE WHEN h.cut_in_line IS TRUE THEN 0 ELSE 1 END, h.selection_depth DESC, h.request_time ";
+# my $holdsort = isTrue($fifo) ?
+# "pgt.hold_priority, CASE WHEN h.cut_in_line IS TRUE THEN 0 ELSE 1 END, h.request_time, h.selection_depth DESC, COALESCE(hm.proximity, h.prox) " :
+# "COALESCE(hm.proximity, h.prox), pgt.hold_priority, CASE WHEN h.cut_in_line IS TRUE THEN 0 ELSE 1 END, h.selection_depth DESC, h.request_time ";
+ my $holdsort = build_hold_sort_clause(get_hold_sort_order($here));
+
+ local $OpenILS::Application::Storage::WRITE = 1;
my $ids = action::hold_request->db_Main->selectcol_arrayref(<<" SQL", {}, $here, $cp, $age);
SELECT h.id