From 3533f1859f3be1a5237dd8aedd45d17bb0e4fdb3 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Thu, 28 Jul 2011 14:29:48 -0400 Subject: [PATCH] LP#790329 org_lasso search is broken Fix the JavaScript error when we attempt to create a feed for the shortname of the org_unit_lasso (lassos have no shortname) - which lets the request hit the backend Perl module, which in turn chokes on a test for OU that only allows two conditions: either all digits is treated as a numeric ID for an org unit, or it is a shortname. Of course, lassos are negative integers, so we have to modify the test slightly to make it happier. There was no depth for org lasso copy counts, and this was handled correctly in the main case by the asset.opac_lasso_record_copy_count() function and its staff variant, but when a copy was not found at a given org_unit in the lasso a request was made for the non-existent depth and the function would error out. Signed-off-by: Dan Scott Signed-off-by: Mike Rylander --- .../Application/Storage/Publisher/metabib.pm | 2 +- Open-ILS/src/sql/Pg/040.schema.asset.sql | 4 +- .../Pg/upgrade/XXXX.lp790329_opac_lasso_counts.sql | 46 ++++++++++++++++++++++ .../XXXX.lp790329_staff_opac_lasso_counts.sql | 42 ++++++++++++++++++++ Open-ILS/web/opac/skin/default/js/result_common.js | 13 +++--- 5 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.lp790329_opac_lasso_counts.sql create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.lp790329_staff_opac_lasso_counts.sql diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm index 613d5f7049..acdc0c23a7 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm @@ -2906,7 +2906,7 @@ sub query_parser_fts { if (my ($filter) = $query->parse_tree->find_filter('site')) { $ou = $filter->args->[0] if (@{$filter->args}); } - $ou = actor::org_unit->search( { shortname => $ou } )->next->id if ($ou and $ou !~ /^\d+$/); + $ou = actor::org_unit->search( { shortname => $ou } )->next->id if ($ou and $ou !~ /^(-)?\d+$/); # gather lasso, as with $ou diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql index ca584a1964..8786fa913d 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -533,7 +533,7 @@ BEGIN GROUP BY 1,2,6; IF NOT FOUND THEN - RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans; + RETURN QUERY SELECT -1, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans; END IF; END LOOP; @@ -595,7 +595,7 @@ BEGIN GROUP BY 1,2,6; IF NOT FOUND THEN - RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans; + RETURN QUERY SELECT -1, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans; END IF; END LOOP; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.lp790329_opac_lasso_counts.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.lp790329_opac_lasso_counts.sql new file mode 100644 index 0000000000..da3241eac1 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.lp790329_opac_lasso_counts.sql @@ -0,0 +1,46 @@ +-- Evergreen DB patch XXXX.lp790329_opac_lasso_counts.sql +-- +-- Resolves an error in calculating copy counts for org lassos +-- Per LP 790329 +-- +BEGIN; + + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +-- FIXME: add/check SQL statements to perform the upgrade +CREATE OR REPLACE FUNCTION asset.opac_lasso_record_copy_count (i_lasso INT, rid BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$ +DECLARE + ans RECORD; + trans INT; +BEGIN + SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = rid; + + FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP + RETURN QUERY + SELECT -1, + ans.id, + COUNT( av.id ), + SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ), + COUNT( av.id ), + trans + FROM + actor.org_unit_descendants(ans.id) d + JOIN asset.opac_visible_copies av ON (av.record = rid AND av.circ_lib = d.id) + JOIN asset.copy cp ON (cp.id = av.copy_id) + GROUP BY 1,2,6; + + IF NOT FOUND THEN + RETURN QUERY SELECT -1, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans; + END IF; + + END LOOP; + + RETURN; +END; +$f$ LANGUAGE PLPGSQL; + + + +COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.lp790329_staff_opac_lasso_counts.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.lp790329_staff_opac_lasso_counts.sql new file mode 100644 index 0000000000..70b81ac232 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.lp790329_staff_opac_lasso_counts.sql @@ -0,0 +1,42 @@ +-- Evergreen DB patch XXXX.lp790329_staff_opac_lasso_counts.sql +-- +-- Staff record copy counts also triggered an SQL error for org lassos +-- Per LP790329 +-- +BEGIN; + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +CREATE OR REPLACE FUNCTION asset.staff_lasso_record_copy_count (i_lasso INT, rid BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$ +DECLARE + ans RECORD; + trans INT; +BEGIN + SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = rid; + + FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP + RETURN QUERY + SELECT -1, + ans.id, + COUNT( cp.id ), + SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ), + COUNT( cp.id ), + trans + FROM + actor.org_unit_descendants(ans.id) d + JOIN asset.copy cp ON (cp.circ_lib = d.id AND NOT cp.deleted) + JOIN asset.call_number cn ON (cn.record = rid AND cn.id = cp.call_number AND NOT cn.deleted) + GROUP BY 1,2,6; + + IF NOT FOUND THEN + RETURN QUERY SELECT -1, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans; + END IF; + + END LOOP; + + RETURN; +END; +$f$ LANGUAGE PLPGSQL; + +COMMIT; diff --git a/Open-ILS/web/opac/skin/default/js/result_common.js b/Open-ILS/web/opac/skin/default/js/result_common.js index 31edb3bec9..c8d510d817 100644 --- a/Open-ILS/web/opac/skin/default/js/result_common.js +++ b/Open-ILS/web/opac/skin/default/js/result_common.js @@ -97,11 +97,14 @@ function resultCollectSearchIds( type, method, handler ) { _debug('Search args: ' + js2JSON(args)); _debug('Raw query: ' + getTerm()); - var atomfeed = "/opac/extras/opensearch/1.1/" + findOrgUnit(args.org_unit).shortname() + "/atom-full/" + getStype() + '?searchTerms=' + getTerm(); - if (args.facets) { atomfeed += ' ' + args.facets; } - if (sort) { atomfeed += '&searchSort=' + sort; } - if (sortdir) { atomfeed += '&searchSortDir=' + sortdir; } - dojo.create('link', {"rel":"alternate", "href":atomfeed, "type":"application/atom+xml"}, dojo.query('head')[0]); + var my_ou = findOrgUnit(args.org_unit); + if (my_ou && my_ou.shortname()) { + var atomfeed = "/opac/extras/opensearch/1.1/" + my_ou.shortname() + "/atom-full/" + getStype() + '?searchTerms=' + getTerm(); + if (args.facets) { atomfeed += ' ' + args.facets; } + if (sort) { atomfeed += '&searchSort=' + sort; } + if (sortdir) { atomfeed += '&searchSortDir=' + sortdir; } + dojo.create('link', {"rel":"alternate", "href":atomfeed, "type":"application/atom+xml"}, dojo.query('head')[0]); + } var req = new Request(method, args, getTerm(), 1); req.callback(handler); -- 2.11.0