[open-ils-commits] [GIT] Evergreen ILS branch master updated. 8b37fc66df5791eb14ca72b962ce04e9b513b447

Evergreen Git git at git.evergreen-ils.org
Tue Sep 26 15:49:34 EDT 2017


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, master has been updated
       via  8b37fc66df5791eb14ca72b962ce04e9b513b447 (commit)
       via  c38866b1a7b1c51490e1baa7114ee48dbe914015 (commit)
      from  39242c16db491d5629bed0af602b547a7b7074ac (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 8b37fc66df5791eb14ca72b962ce04e9b513b447
Author: Galen Charlton <gmc at equinoxinitiative.org>
Date:   Tue Sep 26 16:06:26 2017 -0400

    LP#1714026: stamp schema update
    
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index ff85e0e..6610d59 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -92,7 +92,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1076', :eg_version); -- miker/gmcharlt
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1077', :eg_version); -- csharp/gmcharlt
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.lp1714026_maintain_control_numbers.sql b/Open-ILS/src/sql/Pg/upgrade/1077.schema.lp1714026_maintain_control_numbers.sql
similarity index 98%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.schema.lp1714026_maintain_control_numbers.sql
rename to Open-ILS/src/sql/Pg/upgrade/1077.schema.lp1714026_maintain_control_numbers.sql
index b7720a8..32dcb14 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.lp1714026_maintain_control_numbers.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/1077.schema.lp1714026_maintain_control_numbers.sql
@@ -1,6 +1,6 @@
 BEGIN;
 
-SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('1077', :eg_version); -- csharp/gmcharlt
 
 -- if the "public" version of this function exists, drop it to prevent confusion/trouble
 

commit c38866b1a7b1c51490e1baa7114ee48dbe914015
Author: Chris Sharp <csharp at georgialibraries.org>
Date:   Wed Aug 30 11:08:15 2017 -0400

    LP#1714026 - Schema-qualify maintain_control_numbers function.
    
    On older Evergreen installs, it's possible to have both an
    evergreen.maintain_control_numbers function and a
    public.maintain_control_numbers function.  Let's remove the
    duplicate one and go ahead and assign it a schema to live in,
    shall we?
    
    Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>

diff --git a/Open-ILS/src/sql/Pg/002.functions.config.sql b/Open-ILS/src/sql/Pg/002.functions.config.sql
index 7eaed4c..f0982db 100644
--- a/Open-ILS/src/sql/Pg/002.functions.config.sql
+++ b/Open-ILS/src/sql/Pg/002.functions.config.sql
@@ -462,7 +462,7 @@ use Unicode::Normalize 'normalize';
 return normalize($_[1],$_[0]); # reverse the params
 $func$ LANGUAGE PLPERLU;
 
-CREATE OR REPLACE FUNCTION maintain_control_numbers() RETURNS TRIGGER AS $func$
+CREATE OR REPLACE FUNCTION evergreen.maintain_control_numbers() RETURNS TRIGGER AS $func$
 use strict;
 use MARC::Record;
 use MARC::File::XML (BinaryEncoding => 'UTF-8');
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.lp1714026_maintain_control_numbers.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.lp1714026_maintain_control_numbers.sql
new file mode 100644
index 0000000..b7720a8
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.lp1714026_maintain_control_numbers.sql
@@ -0,0 +1,146 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+-- if the "public" version of this function exists, drop it to prevent confusion/trouble
+
+-- drop triggers that depend on this first
+DROP TRIGGER IF EXISTS c_maintain_control_numbers ON biblio.record_entry;
+DROP TRIGGER IF EXISTS c_maintain_control_numbers ON serial.record_entry;
+DROP TRIGGER IF EXISTS c_maintain_control_numbers ON authority.record_entry;
+
+DROP FUNCTION IF EXISTS public.maintain_control_numbers();
+
+-- create the function within the "evergreen" schema
+
+CREATE OR REPLACE FUNCTION evergreen.maintain_control_numbers() 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 $record = MARC::Record->new_from_xml($_TD->{new}{marc});
+my $schema = $_TD->{table_schema};
+my $rec_id = $_TD->{new}{id};
+
+# Short-circuit if maintaining control numbers per MARC21 spec is not enabled
+my $enable = spi_exec_query("SELECT enabled FROM config.global_flag WHERE name = 'cat.maintain_control_numbers'");
+if (!($enable->{processed}) or $enable->{rows}[0]->{enabled} eq 'f') {
+    return;
+}
+
+# Get the control number identifier from an OU setting based on $_TD->{new}{owner}
+my $ou_cni = 'EVRGRN';
+
+my $owner;
+if ($schema eq 'serial') {
+    $owner = $_TD->{new}{owning_lib};
+} else {
+    # are.owner and bre.owner can be null, so fall back to the consortial setting
+    $owner = $_TD->{new}{owner} || 1;
+}
+
+my $ous_rv = spi_exec_query("SELECT value FROM actor.org_unit_ancestor_setting('cat.marc_control_number_identifier', $owner)");
+if ($ous_rv->{processed}) {
+    $ou_cni = $ous_rv->{rows}[0]->{value};
+    $ou_cni =~ s/"//g; # Stupid VIM syntax highlighting"
+} else {
+    # Fall back to the shortname of the OU if there was no OU setting
+    $ous_rv = spi_exec_query("SELECT shortname FROM actor.org_unit WHERE id = $owner");
+    if ($ous_rv->{processed}) {
+        $ou_cni = $ous_rv->{rows}[0]->{shortname};
+    }
+}
+
+my ($create, $munge) = (0, 0);
+
+my @scns = $record->field('035');
+
+foreach my $id_field ('001', '003') {
+    my $spec_value;
+    my @controls = $record->field($id_field);
+
+    if ($id_field eq '001') {
+        $spec_value = $rec_id;
+    } else {
+        $spec_value = $ou_cni;
+    }
+
+    # Create the 001/003 if none exist
+    if (scalar(@controls) == 1) {
+        # Only one field; check to see if we need to munge it
+        unless (grep $_->data() eq $spec_value, @controls) {
+            $munge = 1;
+        }
+    } else {
+        # Delete the other fields, as with more than 1 001/003 we do not know which 003/001 to match
+        foreach my $control (@controls) {
+            $record->delete_field($control);
+        }
+        $record->insert_fields_ordered(MARC::Field->new($id_field, $spec_value));
+        $create = 1;
+    }
+}
+
+my $cn = $record->field('001')->data();
+# Special handling of OCLC numbers, often found in records that lack 003
+if ($cn =~ /^o(c[nm]|n)\d/) {
+    $cn =~ s/^o(c[nm]|n)0*(\d+)/$2/;
+    $record->field('003')->data('OCoLC');
+    $create = 0;
+}
+
+# Now, if we need to munge the 001, we will first push the existing 001/003
+# into the 035; but if the record did not have one (and one only) 001 and 003
+# to begin with, skip this process
+if ($munge and not $create) {
+
+    my $scn = "(" . $record->field('003')->data() . ")" . $cn;
+
+    # Do not create duplicate 035 fields
+    unless (grep $_->subfield('a') eq $scn, @scns) {
+        $record->insert_fields_ordered(MARC::Field->new('035', '', '', 'a' => $scn));
+    }
+}
+
+# Set the 001/003 and update the MARC
+if ($create or $munge) {
+    $record->field('001')->data($rec_id);
+    $record->field('003')->data($ou_cni);
+
+    my $xml = $record->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
+
+    $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";
+}
+
+return;
+$func$ LANGUAGE PLPERLU;
+
+-- re-create the triggers
+CREATE TRIGGER c_maintain_control_numbers BEFORE INSERT OR UPDATE ON serial.record_entry FOR EACH ROW EXECUTE PROCEDURE evergreen.maintain_control_numbers();
+CREATE TRIGGER c_maintain_control_numbers BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE evergreen.maintain_control_numbers();
+CREATE TRIGGER c_maintain_control_numbers BEFORE INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE evergreen.maintain_control_numbers();
+
+COMMIT;

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/src/sql/Pg/002.functions.config.sql       |    2 +-
 Open-ILS/src/sql/Pg/002.schema.config.sql          |    2 +-
 ....schema.lp1714026_maintain_control_numbers.sql} |   25 +++++++++++++------
 3 files changed, 19 insertions(+), 10 deletions(-)
 copy Open-ILS/src/sql/Pg/upgrade/{0742.schema.maintain_control_number_oclc.sql => 1077.schema.lp1714026_maintain_control_numbers.sql} (76%)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list