From e79a805299ec734a29ee5bfa77dc74bc1fd208cd Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Tue, 14 Jun 2011 14:02:49 -0400 Subject: [PATCH] Fix LP 797304 and 797307 - asset.uri parsing bugs Per 797304: one would expect asset.uri.label to be populated with the value of 856 $y, however, it was getting populated with 856 $u - perhaps as a result of the ordering of array entries in XPATH() not matching the XPath expression. Instead of including 856 $u in the XPath expression for uri_label, just assign its value to uri_label if uri_label is otherwise NULL. Per 797307: biblio.extract_located_uris() tries to reuse an existing active asset.uri entry rather than create a new row; however, it does not handle the case where there is no public note aka "use restriction" and will end up creating a duplicate row every time the record is reingested. Teach it to handle NULL values properly. Signed-off-by: Dan Scott --- Open-ILS/src/sql/Pg/030.schema.metabib.sql | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql index 1ccbd573ba..7e86d47ba3 100644 --- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql +++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql @@ -853,9 +853,13 @@ BEGIN uri_xml := uris[i]; uri_href := (oils_xpath('//*[@code="u"]/text()',uri_xml))[1]; - uri_label := (oils_xpath('//*[@code="y"]/text()|//*[@code="3"]/text()|//*[@code="u"]/text()',uri_xml))[1]; + uri_label := (oils_xpath('//*[@code="y"]/text()|//*[@code="3"]/text()',uri_xml))[1]; uri_use := (oils_xpath('//*[@code="z"]/text()|//*[@code="2"]/text()|//*[@code="n"]/text()',uri_xml))[1]; - CONTINUE WHEN uri_href IS NULL OR uri_label IS NULL; + + IF uri_label IS NULL THEN + uri_label := uri_href; + END IF; + CONTINUE WHEN uri_href IS NULL; -- Get the distinct list of libraries wanting to use SELECT ARRAY_ACCUM( @@ -875,12 +879,16 @@ BEGIN IF ARRAY_UPPER(uri_owner_list,1) > 0 THEN -- look for a matching uri - SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction = uri_use AND active; - IF NOT FOUND THEN -- create one - INSERT INTO asset.uri (label, href, use_restriction) VALUES (uri_label, uri_href, uri_use); - IF uri_use IS NULL THEN + IF uri_use IS NULL THEN + SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction IS NULL AND active; + IF NOT FOUND THEN -- create one + INSERT INTO asset.uri (label, href, use_restriction) VALUES (uri_label, uri_href, uri_use); SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction IS NULL AND active; - ELSE + END IF; + ELSE + SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction = uri_use AND active; + IF NOT FOUND THEN -- create one + INSERT INTO asset.uri (label, href, use_restriction) VALUES (uri_label, uri_href, uri_use); SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction = uri_use AND active; END IF; END IF; -- 2.11.0