[open-ils-commits] r18960 - in branches/rel_2_0/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Dec 10 09:27:39 EST 2010
Author: miker
Date: 2010-12-10 09:27:37 -0500 (Fri, 10 Dec 2010)
New Revision: 18960
Added:
branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0469.schema.authority-maint-trigger-funcs.sql
Modified:
branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql
branches/rel_2_0/Open-ILS/src/sql/Pg/011.schema.authority.sql
branches/rel_2_0/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
branches/rel_2_0/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql
Log:
Backporting r18957 from trunk:
Fix two bugs:
* Wide Character warning in authority.generate_overlay_template due to the generated template not being UTF-8 encoded internally
* Correctly test the same space-normalization form of the pre- and post-strip records during the application of a replace rule in vandelay.replace_field
This addresses https://bugs.launchpad.net/evergreen/+bug/687996 for 2.0beta5
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-12-10 14:20:58 UTC (rev 18959)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-12-10 14:27:37 UTC (rev 18960)
@@ -70,7 +70,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0468'); -- gmc
+INSERT INTO config.upgrade_log (version) VALUES ('0469'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/011.schema.authority.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/011.schema.authority.sql 2010-12-10 14:20:58 UTC (rev 18959)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/011.schema.authority.sql 2010-12-10 14:27:37 UTC (rev 18960)
@@ -132,6 +132,7 @@
return undef unless ($id); # We need an ID!
my $tmpl = MARC::Record->new();
+ $tmpl->encoding( 'UTF-8' );
my @rule_fields;
for my $field ( $r->field( '1..' ) ) { # Get main entry fields from the authority record
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/012.schema.vandelay.sql 2010-12-10 14:20:58 UTC (rev 18959)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/012.schema.vandelay.sql 2010-12-10 14:27:37 UTC (rev 18960)
@@ -444,10 +444,12 @@
CREATE OR REPLACE FUNCTION vandelay.replace_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$
DECLARE
xml_output TEXT;
+ parsed_target TEXT;
BEGIN
- xml_output := vandelay.strip_field( target_xml, field);
+ parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalized the format of the xml for the IF below
+ xml_output := vandelay.strip_field( parsed_target, field);
- IF xml_output <> target_xml AND field ~ E'~' THEN
+ IF xml_output <> parsed_target AND field ~ E'~' THEN
-- we removed something, and there was a regexp restriction in the field definition, so proceed
xml_output := vandelay.add_field( xml_output, source_xml, field, 1 );
ELSIF field !~ E'~' THEN
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql 2010-12-10 14:20:58 UTC (rev 18959)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql 2010-12-10 14:27:37 UTC (rev 18960)
@@ -31,7 +31,7 @@
-- Highest-numbered individual upgrade script incorporated herein:
-INSERT INTO config.upgrade_log (version) VALUES ('0461');
+INSERT INTO config.upgrade_log (version) VALUES ('0469');
-- Push the auri sequence in case it's out of date
-- Add 2 as the sequence value must be 1 or higher, and seed is -1
@@ -14217,10 +14217,12 @@
CREATE OR REPLACE FUNCTION vandelay.replace_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$
DECLARE
xml_output TEXT;
+ parsed_target TEXT;
BEGIN
- xml_output := vandelay.strip_field( target_xml, field);
+ parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalized the format of the xml for the IF below
+ xml_output := vandelay.strip_field( parsed_target, field);
- IF xml_output <> target_xml AND field ~ E'~' THEN
+ IF xml_output <> parsed_target AND field ~ E'~' THEN
-- we removed something, and there was a regexp restriction in the field definition, so proceed
xml_output := vandelay.add_field( xml_output, source_xml, field, 1 );
ELSIF field !~ E'~' THEN
@@ -16594,6 +16596,7 @@
return undef unless ($id); # We need an ID!
my $tmpl = MARC::Record->new();
+ $tmpl->encoding( 'UTF-8' );
my @rule_fields;
for my $field ( $r->field( '1..' ) ) { # Get main entry fields from the authority record
Copied: branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0469.schema.authority-maint-trigger-funcs.sql (from rev 18957, trunk/Open-ILS/src/sql/Pg/upgrade/0469.schema.authority-maint-trigger-funcs.sql)
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0469.schema.authority-maint-trigger-funcs.sql (rev 0)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0469.schema.authority-maint-trigger-funcs.sql 2010-12-10 14:27:37 UTC (rev 18960)
@@ -0,0 +1,92 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0469'); -- miker
+
+CREATE OR REPLACE FUNCTION authority.generate_overlay_template ( TEXT, BIGINT ) RETURNS TEXT AS $func$
+
+ use MARC::Record;
+ use MARC::File::XML (BinaryEncoding => 'UTF-8');
+
+ my $xml = shift;
+ my $r = MARC::Record->new_from_xml( $xml );
+
+ return undef unless ($r);
+
+ my $id = shift() || $r->subfield( '901' => 'c' );
+ $id =~ s/^\s*(?:\([^)]+\))?\s*(.+)\s*?$/$1/;
+ return undef unless ($id); # We need an ID!
+
+ my $tmpl = MARC::Record->new();
+ $tmpl->encoding( 'UTF-8' );
+
+ my @rule_fields;
+ for my $field ( $r->field( '1..' ) ) { # Get main entry fields from the authority record
+
+ my $tag = $field->tag;
+ my $i1 = $field->indicator(1);
+ my $i2 = $field->indicator(2);
+ my $sf = join '', map { $_->[0] } $field->subfields;
+ my @data = map { @$_ } $field->subfields;
+
+ my @replace_them;
+
+ # Map the authority field to bib fields it can control.
+ if ($tag >= 100 and $tag <= 111) { # names
+ @replace_them = map { $tag + $_ } (0, 300, 500, 600, 700);
+ } elsif ($tag eq '130') { # uniform title
+ @replace_them = qw/130 240 440 730 830/;
+ } elsif ($tag >= 150 and $tag <= 155) { # subjects
+ @replace_them = ($tag + 500);
+ } elsif ($tag >= 180 and $tag <= 185) { # floating subdivisions
+ @replace_them = qw/100 400 600 700 800 110 410 610 710 810 111 411 611 711 811 130 240 440 730 830 650 651 655/;
+ } else {
+ next;
+ }
+
+ # Dummy up the bib-side data
+ $tmpl->append_fields(
+ map {
+ MARC::Field->new( $_, $i1, $i2, @data )
+ } @replace_them
+ );
+
+ # Construct some 'replace' rules
+ push @rule_fields, map { $_ . $sf . '[0~\)' .$id . '$]' } @replace_them;
+ }
+
+ # Insert the replace rules into the template
+ $tmpl->append_fields(
+ MARC::Field->new( '905' => ' ' => ' ' => 'r' => join(',', @rule_fields ) )
+ );
+
+ $xml = $tmpl->as_xml_record;
+ $xml =~ s/^<\?.+?\?>$//mo;
+ $xml =~ s/\n//sgo;
+ $xml =~ s/>\s+</></sgo;
+
+ return $xml;
+
+$func$ LANGUAGE PLPERLU;
+
+CREATE OR REPLACE FUNCTION vandelay.replace_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$
+DECLARE
+ xml_output TEXT;
+ parsed_target TEXT;
+BEGIN
+ parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalized the format of the xml for the IF below
+ xml_output := vandelay.strip_field( parsed_target, field);
+
+ IF xml_output <> parsed_target AND field ~ E'~' THEN
+ -- we removed something, and there was a regexp restriction in the field definition, so proceed
+ xml_output := vandelay.add_field( xml_output, source_xml, field, 1 );
+ ELSIF field !~ E'~' THEN
+ -- No regexp restriction, add the field
+ xml_output := vandelay.add_field( xml_output, source_xml, field, 0 );
+ END IF;
+
+ RETURN xml_output;
+END;
+$_$ LANGUAGE PLPGSQL;
+
+COMMIT;
+
More information about the open-ils-commits
mailing list