[open-ils-commits] [GIT] Evergreen ILS branch rel_2_1 updated. d66b20e415aebf2b3308f37cb25a6612ac1fcd19
Evergreen Git
git at git.evergreen-ils.org
Sat Jul 28 18:09:19 EDT 2012
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".
The branch, rel_2_1 has been updated
via d66b20e415aebf2b3308f37cb25a6612ac1fcd19 (commit)
via 08ad5769028661d8e8acf396443d346a3fe79ffb (commit)
via e88114f055088b634efd8f0aa3795b71176b1f9a (commit)
via b6e19563b0cfb7da2bfb73d3199b86678e5188ab (commit)
from 43dbf993a9a0a01c2a5a7948750accb2a2727541 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d66b20e415aebf2b3308f37cb25a6612ac1fcd19
Author: Dan Scott <dscott at laurentian.ca>
Date: Fri Jul 27 16:27:29 2012 -0400
Use MARC::Field objects to append new fields
While the deprecated MARC::Record::add_fields() method allows you to add
a list of fields using a list object, append_fields() requires
MARC::Field objects.
Signed-off-by: Dan Scott <dscott at laurentian.ca>
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Conflicts:
Open-ILS/src/sql/Pg/002.schema.config.sql
diff --git a/Open-ILS/src/sql/Pg/002.functions.config.sql b/Open-ILS/src/sql/Pg/002.functions.config.sql
index 327b782..1708d1e 100644
--- a/Open-ILS/src/sql/Pg/002.functions.config.sql
+++ b/Open-ILS/src/sql/Pg/002.functions.config.sql
@@ -465,12 +465,11 @@ if ($schema eq 'biblio') {
$marc->append_fields($new_901);
} elsif ($schema eq 'authority') {
- $marc->append_fields(
- ["901", " ", " ",
- "c" => $_TD->{new}{id},
- "t" => $schema,
- ]
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
);
+ $marc->append_fields($new_901);
} elsif ($schema eq 'serial') {
my $new_901 = MARC::Field->new("901", " ", " ",
"c" => $_TD->{new}{id},
@@ -484,12 +483,11 @@ if ($schema eq 'biblio') {
$marc->append_fields($new_901);
} else {
- $marc->append_fields(
- ["901", " ", " ",
- "c" => $_TD->{new}{id},
- "t" => $schema,
- ]
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
);
+ $marc->append_fields($new_901);
}
my $xml = $marc->as_xml_record();
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 0426af0..bb88a41 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -57,7 +57,7 @@ CREATE TABLE config.upgrade_log (
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0725', :eg_version); -- gmcharlt/denials
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0726', :eg_version); -- denials
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/0726.schema.fix_maintain_901_regex.sql b/Open-ILS/src/sql/Pg/upgrade/0726.schema.fix_maintain_901_regex.sql
new file mode 100644
index 0000000..2cd5c0d
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/0726.schema.fix_maintain_901_regex.sql
@@ -0,0 +1,103 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0726', :eg_version); -- denials
+
+CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$
+use strict;
+use MARC::Record;
+use MARC::File::XML (BinaryEncoding => 'UTF-8');
+use MARC::Charset;
+use Encode;
+use Unicode::Normalize;
+
+MARC::Charset->assume_unicode(1);
+
+my $schema = $_TD->{table_schema};
+my $marc = MARC::Record->new_from_xml($_TD->{new}{marc});
+
+my @old901s = $marc->field('901');
+$marc->delete_fields(@old901s);
+
+if ($schema eq 'biblio') {
+ my $tcn_value = $_TD->{new}{tcn_value};
+
+ # Set TCN value to record ID?
+ my $id_as_tcn = spi_exec_query("
+ SELECT enabled
+ FROM config.global_flag
+ WHERE name = 'cat.bib.use_id_for_tcn'
+ ");
+ if (($id_as_tcn->{processed}) && $id_as_tcn->{rows}[0]->{enabled} eq 't') {
+ $tcn_value = $_TD->{new}{id};
+ }
+
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "a" => $tcn_value,
+ "b" => $_TD->{new}{tcn_source},
+ "c" => $_TD->{new}{id},
+ "t" => $schema
+ );
+
+ if ($_TD->{new}{owner}) {
+ $new_901->add_subfields("o" => $_TD->{new}{owner});
+ }
+
+ if ($_TD->{new}{share_depth}) {
+ $new_901->add_subfields("d" => $_TD->{new}{share_depth});
+ }
+
+ $marc->append_fields($new_901);
+} elsif ($schema eq 'authority') {
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ );
+ $marc->append_fields($new_901);
+} elsif ($schema eq 'serial') {
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ "o" => $_TD->{new}{owning_lib},
+ );
+
+ if ($_TD->{new}{record}) {
+ $new_901->add_subfields("r" => $_TD->{new}{record});
+ }
+
+ $marc->append_fields($new_901);
+} else {
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ );
+ $marc->append_fields($new_901);
+}
+
+my $xml = $marc->as_xml_record();
+$xml =~ s/\n//sgo;
+$xml =~ s/^<\?xml.+\?\s*>//go;
+$xml =~ s/>\s+</></go;
+$xml =~ s/\p{Cc}//go;
+
+# Embed a version of OpenILS::Application::AppUtils->entityize()
+# to avoid having to set PERL5LIB for PostgreSQL as well
+
+# If we are going to convert non-ASCII characters to XML entities,
+# we had better be dealing with a UTF8 string to begin with
+$xml = decode_utf8($xml);
+
+$xml = NFC($xml);
+
+# Convert raw ampersands to entities
+$xml =~ s/&(?!\S+;)/&/gso;
+
+# Convert Unicode characters to entities
+$xml =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
+
+$xml =~ s/[\x00-\x1f]//go;
+$_TD->{new}{marc} = $xml;
+
+return "MODIFY";
+$func$ LANGUAGE PLPERLU;
+
+COMMIT;
commit 08ad5769028661d8e8acf396443d346a3fe79ffb
Author: Galen Charlton <gmc at esilibrary.com>
Date: Fri Jul 27 11:23:46 2012 -0400
lp1028514: fix syntax-o in PL/PERLU version of maintain_901()
Signed-off-by: Galen Charlton <gmc at esilibrary.com>
Signed-off-by: Dan Scott <dscott at laurentian.ca>
Conflicts:
Open-ILS/src/sql/Pg/002.schema.config.sql
diff --git a/Open-ILS/src/sql/Pg/002.functions.config.sql b/Open-ILS/src/sql/Pg/002.functions.config.sql
index 3af62b6..327b782 100644
--- a/Open-ILS/src/sql/Pg/002.functions.config.sql
+++ b/Open-ILS/src/sql/Pg/002.functions.config.sql
@@ -464,14 +464,14 @@ if ($schema eq 'biblio') {
}
$marc->append_fields($new_901);
-} elsif ($schema = 'authority') {
+} elsif ($schema eq 'authority') {
$marc->append_fields(
["901", " ", " ",
"c" => $_TD->{new}{id},
"t" => $schema,
]
);
-} elsif ($schema = 'serial') {
+} elsif ($schema eq 'serial') {
my $new_901 = MARC::Field->new("901", " ", " ",
"c" => $_TD->{new}{id},
"t" => $schema,
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 9ae1a87..0426af0 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -57,7 +57,7 @@ CREATE TABLE config.upgrade_log (
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0722'); -- berick/mrpeters/senator
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0725', :eg_version); -- gmcharlt/denials
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/0725.schema.fix_maintain_901_regex.sql b/Open-ILS/src/sql/Pg/upgrade/0725.schema.fix_maintain_901_regex.sql
new file mode 100644
index 0000000..2b0c206
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/0725.schema.fix_maintain_901_regex.sql
@@ -0,0 +1,105 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0725', :eg_version); -- gmcharlt/denials
+
+CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$
+use strict;
+use MARC::Record;
+use MARC::File::XML (BinaryEncoding => 'UTF-8');
+use MARC::Charset;
+use Encode;
+use Unicode::Normalize;
+
+MARC::Charset->assume_unicode(1);
+
+my $schema = $_TD->{table_schema};
+my $marc = MARC::Record->new_from_xml($_TD->{new}{marc});
+
+my @old901s = $marc->field('901');
+$marc->delete_fields(@old901s);
+
+if ($schema eq 'biblio') {
+ my $tcn_value = $_TD->{new}{tcn_value};
+
+ # Set TCN value to record ID?
+ my $id_as_tcn = spi_exec_query("
+ SELECT enabled
+ FROM config.global_flag
+ WHERE name = 'cat.bib.use_id_for_tcn'
+ ");
+ if (($id_as_tcn->{processed}) && $id_as_tcn->{rows}[0]->{enabled} eq 't') {
+ $tcn_value = $_TD->{new}{id};
+ }
+
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "a" => $tcn_value,
+ "b" => $_TD->{new}{tcn_source},
+ "c" => $_TD->{new}{id},
+ "t" => $schema
+ );
+
+ if ($_TD->{new}{owner}) {
+ $new_901->add_subfields("o" => $_TD->{new}{owner});
+ }
+
+ if ($_TD->{new}{share_depth}) {
+ $new_901->add_subfields("d" => $_TD->{new}{share_depth});
+ }
+
+ $marc->append_fields($new_901);
+} elsif ($schema eq 'authority') {
+ $marc->append_fields(
+ ["901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ ]
+ );
+} elsif ($schema eq 'serial') {
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ "o" => $_TD->{new}{owning_lib},
+ );
+
+ if ($_TD->{new}{record}) {
+ $new_901->add_subfields("r" => $_TD->{new}{record});
+ }
+
+ $marc->append_fields($new_901);
+} else {
+ $marc->append_fields(
+ ["901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ ]
+ );
+}
+
+my $xml = $marc->as_xml_record();
+$xml =~ s/\n//sgo;
+$xml =~ s/^<\?xml.+\?\s*>//go;
+$xml =~ s/>\s+</></go;
+$xml =~ s/\p{Cc}//go;
+
+# Embed a version of OpenILS::Application::AppUtils->entityize()
+# to avoid having to set PERL5LIB for PostgreSQL as well
+
+# If we are going to convert non-ASCII characters to XML entities,
+# we had better be dealing with a UTF8 string to begin with
+$xml = decode_utf8($xml);
+
+$xml = NFC($xml);
+
+# Convert raw ampersands to entities
+$xml =~ s/&(?!\S+;)/&/gso;
+
+# Convert Unicode characters to entities
+$xml =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
+
+$xml =~ s/[\x00-\x1f]//go;
+$_TD->{new}{marc} = $xml;
+
+return "MODIFY";
+$func$ LANGUAGE PLPERLU;
+
+COMMIT;
commit e88114f055088b634efd8f0aa3795b71176b1f9a
Author: Dan Scott <dscott at laurentian.ca>
Date: Tue Jul 24 14:14:01 2012 -0400
Switch to a PLPERLU maintain_901() trigger function
We've been burned by regexes that fail to grok XML properly numerous
times now. Standardizing on something that actually understands MARC
seems like a good idea.
Signed-off-by: Dan Scott <dscott at laurentian.ca>
Signed-off-by: Mike Rylander <mrylander at gmail.com>
diff --git a/Open-ILS/src/sql/Pg/002.functions.config.sql b/Open-ILS/src/sql/Pg/002.functions.config.sql
index 19d8696..3af62b6 100644
--- a/Open-ILS/src/sql/Pg/002.functions.config.sql
+++ b/Open-ILS/src/sql/Pg/002.functions.config.sql
@@ -420,67 +420,104 @@ CREATE OR REPLACE FUNCTION oils_json_to_text( TEXT ) RETURNS TEXT AS $f$
$f$ LANGUAGE PLPERLU;
CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$
-DECLARE
- use_id_for_tcn BOOLEAN;
-BEGIN
- -- Remove any existing 901 fields before we insert the authoritative one
- NEW.marc := REGEXP_REPLACE(NEW.marc, E'<datafield[^>]*?tag="901".+?</datafield>', '', 'g');
+use strict;
+use MARC::Record;
+use MARC::File::XML (BinaryEncoding => 'UTF-8');
+use MARC::Charset;
+use Encode;
+use Unicode::Normalize;
- IF TG_TABLE_SCHEMA = 'biblio' THEN
- -- Set TCN value to record ID?
- SELECT enabled FROM config.global_flag INTO use_id_for_tcn
- WHERE name = 'cat.bib.use_id_for_tcn';
+MARC::Charset->assume_unicode(1);
- IF use_id_for_tcn = 't' THEN
- NEW.tcn_value := NEW.id;
- END IF;
+my $schema = $_TD->{table_schema};
+my $marc = MARC::Record->new_from_xml($_TD->{new}{marc});
+
+my @old901s = $marc->field('901');
+$marc->delete_fields(@old901s);
+
+if ($schema eq 'biblio') {
+ my $tcn_value = $_TD->{new}{tcn_value};
+
+ # Set TCN value to record ID?
+ my $id_as_tcn = spi_exec_query("
+ SELECT enabled
+ FROM config.global_flag
+ WHERE name = 'cat.bib.use_id_for_tcn'
+ ");
+ if (($id_as_tcn->{processed}) && $id_as_tcn->{rows}[0]->{enabled} eq 't') {
+ $tcn_value = $_TD->{new}{id};
+ }
- NEW.marc := REGEXP_REPLACE(
- NEW.marc,
- E'(</(?:[^:>]*?:)?record>)',
- E'<datafield tag="901" ind1=" " ind2=" ">' ||
- '<subfield code="a">' || REPLACE(evergreen.xml_escape(NEW.tcn_value), E'\\', E'\\\\') || E'</subfield>' ||
- '<subfield code="b">' || REPLACE(evergreen.xml_escape(NEW.tcn_source), E'\\', E'\\\\') || E'</subfield>' ||
- '<subfield code="c">' || NEW.id || E'</subfield>' ||
- '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
- CASE WHEN NEW.owner IS NOT NULL THEN '<subfield code="o">' || NEW.owner || E'</subfield>' ELSE '' END ||
- CASE WHEN NEW.share_depth IS NOT NULL THEN '<subfield code="d">' || NEW.share_depth || E'</subfield>' ELSE '' END ||
- E'</datafield>\\1'
- );
- ELSIF TG_TABLE_SCHEMA = 'authority' THEN
- NEW.marc := REGEXP_REPLACE(
- NEW.marc,
- E'(</(?:[^:>]*?:)?record>)',
- E'<datafield tag="901" ind1=" " ind2=" ">' ||
- '<subfield code="c">' || NEW.id || E'</subfield>' ||
- '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
- E'</datafield>\\1'
- );
- ELSIF TG_TABLE_SCHEMA = 'serial' THEN
- NEW.marc := REGEXP_REPLACE(
- NEW.marc,
- E'(</(?:[^:>]*?:)?record>)',
- E'<datafield tag="901" ind1=" " ind2=" ">' ||
- '<subfield code="c">' || NEW.id || E'</subfield>' ||
- '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
- '<subfield code="o">' || NEW.owning_lib || E'</subfield>' ||
- CASE WHEN NEW.record IS NOT NULL THEN '<subfield code="r">' || NEW.record || E'</subfield>' ELSE '' END ||
- E'</datafield>\\1'
- );
- ELSE
- NEW.marc := REGEXP_REPLACE(
- NEW.marc,
- E'(</(?:[^:>]*?:)?record>)',
- E'<datafield tag="901" ind1=" " ind2=" ">' ||
- '<subfield code="c">' || NEW.id || E'</subfield>' ||
- '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
- E'</datafield>\\1'
- );
- END IF;
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "a" => $tcn_value,
+ "b" => $_TD->{new}{tcn_source},
+ "c" => $_TD->{new}{id},
+ "t" => $schema
+ );
- RETURN NEW;
-END;
-$func$ LANGUAGE PLPGSQL;
+ if ($_TD->{new}{owner}) {
+ $new_901->add_subfields("o" => $_TD->{new}{owner});
+ }
+
+ if ($_TD->{new}{share_depth}) {
+ $new_901->add_subfields("d" => $_TD->{new}{share_depth});
+ }
+
+ $marc->append_fields($new_901);
+} elsif ($schema = 'authority') {
+ $marc->append_fields(
+ ["901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ ]
+ );
+} elsif ($schema = 'serial') {
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ "o" => $_TD->{new}{owning_lib},
+ );
+
+ if ($_TD->{new}{record}) {
+ $new_901->add_subfields("r" => $_TD->{new}{record});
+ }
+
+ $marc->append_fields($new_901);
+} else {
+ $marc->append_fields(
+ ["901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ ]
+ );
+}
+
+my $xml = $marc->as_xml_record();
+$xml =~ s/\n//sgo;
+$xml =~ s/^<\?xml.+\?\s*>//go;
+$xml =~ s/>\s+</></go;
+$xml =~ s/\p{Cc}//go;
+
+# Embed a version of OpenILS::Application::AppUtils->entityize()
+# to avoid having to set PERL5LIB for PostgreSQL as well
+
+# If we are going to convert non-ASCII characters to XML entities,
+# we had better be dealing with a UTF8 string to begin with
+$xml = decode_utf8($xml);
+
+$xml = NFC($xml);
+
+# Convert raw ampersands to entities
+$xml =~ s/&(?!\S+;)/&/gso;
+
+# Convert Unicode characters to entities
+$xml =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
+
+$xml =~ s/[\x00-\x1f]//go;
+$_TD->{new}{marc} = $xml;
+
+return "MODIFY";
+$func$ LANGUAGE PLPERLU;
CREATE OR REPLACE FUNCTION evergreen.force_unicode_normal_form(string TEXT, form TEXT) RETURNS TEXT AS $func$
use Unicode::Normalize 'normalize';
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_maintain_901_regex.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_maintain_901_regex.sql
index 607e3a7..334caeb 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_maintain_901_regex.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_maintain_901_regex.sql
@@ -1,68 +1,99 @@
-BEGIN;
+CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$
+use strict;
+use MARC::Record;
+use MARC::File::XML (BinaryEncoding => 'UTF-8');
+use MARC::Charset;
+use Encode;
+use Unicode::Normalize;
-SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+MARC::Charset->assume_unicode(1);
-CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$
-DECLARE
- use_id_for_tcn BOOLEAN;
-BEGIN
- -- Remove any existing 901 fields before we insert the authoritative one
- NEW.marc := REGEXP_REPLACE(NEW.marc, E'<datafield[^>]*?tag="901".+?</datafield>', '', 'g');
-
- IF TG_TABLE_SCHEMA = 'biblio' THEN
- -- Set TCN value to record ID?
- SELECT enabled FROM config.global_flag INTO use_id_for_tcn
- WHERE name = 'cat.bib.use_id_for_tcn';
-
- IF use_id_for_tcn = 't' THEN
- NEW.tcn_value := NEW.id;
- END IF;
-
- NEW.marc := REGEXP_REPLACE(
- NEW.marc,
- E'(</(?:[^:>]*?:)?record>)',
- E'<datafield tag="901" ind1=" " ind2=" ">' ||
- '<subfield code="a">' || REPLACE(evergreen.xml_escape(NEW.tcn_value), E'\\', E'\\\\') || E'</subfield>' ||
- '<subfield code="b">' || REPLACE(evergreen.xml_escape(NEW.tcn_source), E'\\', E'\\\\') || E'</subfield>' ||
- '<subfield code="c">' || NEW.id || E'</subfield>' ||
- '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
- CASE WHEN NEW.owner IS NOT NULL THEN '<subfield code="o">' || NEW.owner || E'</subfield>' ELSE '' END ||
- CASE WHEN NEW.share_depth IS NOT NULL THEN '<subfield code="d">' || NEW.share_depth || E'</subfield>' ELSE '' END ||
- E'</datafield>\\1'
- );
- ELSIF TG_TABLE_SCHEMA = 'authority' THEN
- NEW.marc := REGEXP_REPLACE(
- NEW.marc,
- E'(</(?:[^:>]*?:)?record>)',
- E'<datafield tag="901" ind1=" " ind2=" ">' ||
- '<subfield code="c">' || NEW.id || E'</subfield>' ||
- '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
- E'</datafield>\\1'
- );
- ELSIF TG_TABLE_SCHEMA = 'serial' THEN
- NEW.marc := REGEXP_REPLACE(
- NEW.marc,
- E'(</(?:[^:>]*?:)?record>)',
- E'<datafield tag="901" ind1=" " ind2=" ">' ||
- '<subfield code="c">' || NEW.id || E'</subfield>' ||
- '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
- '<subfield code="o">' || NEW.owning_lib || E'</subfield>' ||
- CASE WHEN NEW.record IS NOT NULL THEN '<subfield code="r">' || NEW.record || E'</subfield>' ELSE '' END ||
- E'</datafield>\\1'
- );
- ELSE
- NEW.marc := REGEXP_REPLACE(
- NEW.marc,
- E'(</(?:[^:>]*?:)?record>)',
- E'<datafield tag="901" ind1=" " ind2=" ">' ||
- '<subfield code="c">' || NEW.id || E'</subfield>' ||
- '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
- E'</datafield>\\1'
- );
- END IF;
-
- RETURN NEW;
-END;
-$func$ LANGUAGE PLPGSQL;
-
-COMMIT;
+my $schema = $_TD->{table_schema};
+my $marc = MARC::Record->new_from_xml($_TD->{new}{marc});
+
+my @old901s = $marc->field('901');
+$marc->delete_fields(@old901s);
+
+if ($schema eq 'biblio') {
+ my $tcn_value = $_TD->{new}{tcn_value};
+
+ # Set TCN value to record ID?
+ my $id_as_tcn = spi_exec_query("
+ SELECT enabled
+ FROM config.global_flag
+ WHERE name = 'cat.bib.use_id_for_tcn'
+ ");
+ if (($id_as_tcn->{processed}) && $id_as_tcn->{rows}[0]->{enabled} eq 't') {
+ $tcn_value = $_TD->{new}{id};
+ }
+
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "a" => $tcn_value,
+ "b" => $_TD->{new}{tcn_source},
+ "c" => $_TD->{new}{id},
+ "t" => $schema
+ );
+
+ if ($_TD->{new}{owner}) {
+ $new_901->add_subfields("o" => $_TD->{new}{owner});
+ }
+
+ if ($_TD->{new}{share_depth}) {
+ $new_901->add_subfields("d" => $_TD->{new}{share_depth});
+ }
+
+ $marc->append_fields($new_901);
+} elsif ($schema = 'authority') {
+ $marc->append_fields(
+ ["901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ ]
+ );
+} elsif ($schema = 'serial') {
+ my $new_901 = MARC::Field->new("901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ "o" => $_TD->{new}{owning_lib},
+ );
+
+ if ($_TD->{new}{record}) {
+ $new_901->add_subfields("r" => $_TD->{new}{record});
+ }
+
+ $marc->append_fields($new_901);
+} else {
+ $marc->append_fields(
+ ["901", " ", " ",
+ "c" => $_TD->{new}{id},
+ "t" => $schema,
+ ]
+ );
+}
+
+my $xml = $marc->as_xml_record();
+$xml =~ s/\n//sgo;
+$xml =~ s/^<\?xml.+\?\s*>//go;
+$xml =~ s/>\s+</></go;
+$xml =~ s/\p{Cc}//go;
+
+# Embed a version of OpenILS::Application::AppUtils->entityize()
+# to avoid having to set PERL5LIB for PostgreSQL as well
+
+# If we are going to convert non-ASCII characters to XML entities,
+# we had better be dealing with a UTF8 string to begin with
+$xml = decode_utf8($xml);
+
+$xml = NFC($xml);
+
+# Convert raw ampersands to entities
+$xml =~ s/&(?!\S+;)/&/gso;
+
+# Convert Unicode characters to entities
+$xml =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
+
+$xml =~ s/[\x00-\x1f]//go;
+$_TD->{new}{marc} = $xml;
+
+return "MODIFY";
+$func$ LANGUAGE PLPERLU;
commit b6e19563b0cfb7da2bfb73d3199b86678e5188ab
Author: Galen Charlton <gmc at esilibrary.com>
Date: Tue Jul 24 11:51:52 2012 -0400
lp1028514: fix regex replace in maintain_901()
The regex used to insert the 901 field can put the new
field in the wrong location if the MARCXML record being
modified uses namespace prefixes. This patch tightens
the regexp to avoid this problem.
Signed-off-by: Galen Charlton <gmc at esilibrary.com>
Signed-off-by: Dan Scott <dscott at laurentian.ca>
diff --git a/Open-ILS/src/sql/Pg/002.functions.config.sql b/Open-ILS/src/sql/Pg/002.functions.config.sql
index 353c7f2..19d8696 100644
--- a/Open-ILS/src/sql/Pg/002.functions.config.sql
+++ b/Open-ILS/src/sql/Pg/002.functions.config.sql
@@ -437,7 +437,7 @@ BEGIN
NEW.marc := REGEXP_REPLACE(
NEW.marc,
- E'(</(?:[^:]*?:)?record>)',
+ E'(</(?:[^:>]*?:)?record>)',
E'<datafield tag="901" ind1=" " ind2=" ">' ||
'<subfield code="a">' || REPLACE(evergreen.xml_escape(NEW.tcn_value), E'\\', E'\\\\') || E'</subfield>' ||
'<subfield code="b">' || REPLACE(evergreen.xml_escape(NEW.tcn_source), E'\\', E'\\\\') || E'</subfield>' ||
@@ -450,7 +450,7 @@ BEGIN
ELSIF TG_TABLE_SCHEMA = 'authority' THEN
NEW.marc := REGEXP_REPLACE(
NEW.marc,
- E'(</(?:[^:]*?:)?record>)',
+ E'(</(?:[^:>]*?:)?record>)',
E'<datafield tag="901" ind1=" " ind2=" ">' ||
'<subfield code="c">' || NEW.id || E'</subfield>' ||
'<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
@@ -459,7 +459,7 @@ BEGIN
ELSIF TG_TABLE_SCHEMA = 'serial' THEN
NEW.marc := REGEXP_REPLACE(
NEW.marc,
- E'(</(?:[^:]*?:)?record>)',
+ E'(</(?:[^:>]*?:)?record>)',
E'<datafield tag="901" ind1=" " ind2=" ">' ||
'<subfield code="c">' || NEW.id || E'</subfield>' ||
'<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
@@ -470,7 +470,7 @@ BEGIN
ELSE
NEW.marc := REGEXP_REPLACE(
NEW.marc,
- E'(</(?:[^:]*?:)?record>)',
+ E'(</(?:[^:>]*?:)?record>)',
E'<datafield tag="901" ind1=" " ind2=" ">' ||
'<subfield code="c">' || NEW.id || E'</subfield>' ||
'<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_maintain_901_regex.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_maintain_901_regex.sql
new file mode 100644
index 0000000..607e3a7
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_maintain_901_regex.sql
@@ -0,0 +1,68 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$
+DECLARE
+ use_id_for_tcn BOOLEAN;
+BEGIN
+ -- Remove any existing 901 fields before we insert the authoritative one
+ NEW.marc := REGEXP_REPLACE(NEW.marc, E'<datafield[^>]*?tag="901".+?</datafield>', '', 'g');
+
+ IF TG_TABLE_SCHEMA = 'biblio' THEN
+ -- Set TCN value to record ID?
+ SELECT enabled FROM config.global_flag INTO use_id_for_tcn
+ WHERE name = 'cat.bib.use_id_for_tcn';
+
+ IF use_id_for_tcn = 't' THEN
+ NEW.tcn_value := NEW.id;
+ END IF;
+
+ NEW.marc := REGEXP_REPLACE(
+ NEW.marc,
+ E'(</(?:[^:>]*?:)?record>)',
+ E'<datafield tag="901" ind1=" " ind2=" ">' ||
+ '<subfield code="a">' || REPLACE(evergreen.xml_escape(NEW.tcn_value), E'\\', E'\\\\') || E'</subfield>' ||
+ '<subfield code="b">' || REPLACE(evergreen.xml_escape(NEW.tcn_source), E'\\', E'\\\\') || E'</subfield>' ||
+ '<subfield code="c">' || NEW.id || E'</subfield>' ||
+ '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
+ CASE WHEN NEW.owner IS NOT NULL THEN '<subfield code="o">' || NEW.owner || E'</subfield>' ELSE '' END ||
+ CASE WHEN NEW.share_depth IS NOT NULL THEN '<subfield code="d">' || NEW.share_depth || E'</subfield>' ELSE '' END ||
+ E'</datafield>\\1'
+ );
+ ELSIF TG_TABLE_SCHEMA = 'authority' THEN
+ NEW.marc := REGEXP_REPLACE(
+ NEW.marc,
+ E'(</(?:[^:>]*?:)?record>)',
+ E'<datafield tag="901" ind1=" " ind2=" ">' ||
+ '<subfield code="c">' || NEW.id || E'</subfield>' ||
+ '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
+ E'</datafield>\\1'
+ );
+ ELSIF TG_TABLE_SCHEMA = 'serial' THEN
+ NEW.marc := REGEXP_REPLACE(
+ NEW.marc,
+ E'(</(?:[^:>]*?:)?record>)',
+ E'<datafield tag="901" ind1=" " ind2=" ">' ||
+ '<subfield code="c">' || NEW.id || E'</subfield>' ||
+ '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
+ '<subfield code="o">' || NEW.owning_lib || E'</subfield>' ||
+ CASE WHEN NEW.record IS NOT NULL THEN '<subfield code="r">' || NEW.record || E'</subfield>' ELSE '' END ||
+ E'</datafield>\\1'
+ );
+ ELSE
+ NEW.marc := REGEXP_REPLACE(
+ NEW.marc,
+ E'(</(?:[^:>]*?:)?record>)',
+ E'<datafield tag="901" ind1=" " ind2=" ">' ||
+ '<subfield code="c">' || NEW.id || E'</subfield>' ||
+ '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
+ E'</datafield>\\1'
+ );
+ END IF;
+
+ RETURN NEW;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+COMMIT;
-----------------------------------------------------------------------
Summary of changes:
Open-ILS/src/sql/Pg/002.functions.config.sql | 153 ++++++++++++--------
Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +-
.../upgrade/0725.schema.fix_maintain_901_regex.sql | 105 ++++++++++++++
.../upgrade/0726.schema.fix_maintain_901_regex.sql | 103 +++++++++++++
.../upgrade/XXXX.schema.fix_maintain_901_regex.sql | 99 +++++++++++++
5 files changed, 402 insertions(+), 60 deletions(-)
create mode 100644 Open-ILS/src/sql/Pg/upgrade/0725.schema.fix_maintain_901_regex.sql
create mode 100644 Open-ILS/src/sql/Pg/upgrade/0726.schema.fix_maintain_901_regex.sql
create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_maintain_901_regex.sql
hooks/post-receive
--
Evergreen ILS
More information about the open-ils-commits
mailing list