[open-ils-commits] [GIT] Evergreen ILS branch master updated. 5317ba59cace4fd62365fc084addac6a3315fcd0

Evergreen Git git at git.evergreen-ils.org
Tue Aug 9 14:57:31 EDT 2016


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  5317ba59cace4fd62365fc084addac6a3315fcd0 (commit)
       via  8db4cb64bb4741713edc7a364adcd9d0f865ba7d (commit)
      from  983e8f9cf1bbc69fd8a134b987cdc87e4fc8e406 (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 5317ba59cace4fd62365fc084addac6a3315fcd0
Author: Mike Rylander <mrylander at gmail.com>
Date:   Tue Aug 9 14:55:30 2016 -0400

    Stamping upgrade for bib_source-in-901
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 963eb22..0e8b5a2 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -91,7 +91,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 ('0987', :eg_version); -- jboyer/miker
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0988', :eg_version); -- gmcharlt/miker
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.bib_source_in_901.sql b/Open-ILS/src/sql/Pg/upgrade/0988.schema.bib_source_in_901.sql
similarity index 97%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.schema.bib_source_in_901.sql
rename to Open-ILS/src/sql/Pg/upgrade/0988.schema.bib_source_in_901.sql
index 9644936..ca5f379 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.bib_source_in_901.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/0988.schema.bib_source_in_901.sql
@@ -1,6 +1,6 @@
 BEGIN;
 
--- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('0988', :eg_version);
 
 CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$
 use strict;

commit 8db4cb64bb4741713edc7a364adcd9d0f865ba7d
Author: Galen Charlton <gmc at esilibrary.com>
Date:   Wed Aug 26 17:59:37 2015 +0000

    LP#1037553: bibliographic record source now copied to 901$s
    
    If a bibliographic record has a source set, the name of that source
    is now copied to the 901$s whenever the record is created or updated.
    This allows the source to be used for record matching and MARC
    field queries.
    
    To test:
    
    [1] Create or import a bibliographic record and ensure that its
        source is set to a non-null value.
    [2] Inspect the record in MARC format view and verify that its
        901 field now has a subfield $s containing the name of the
        source.
    [3] Use pg_prove to run the pgTAP test added by this patch
        and verify that the test passes.
    
    Signed-off-by: Galen Charlton <gmc at esilibrary.com>
    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 d52c6f9..77876fe 100644
--- a/Open-ILS/src/sql/Pg/002.functions.config.sql
+++ b/Open-ILS/src/sql/Pg/002.functions.config.sql
@@ -395,6 +395,18 @@ if ($schema eq 'biblio') {
         $new_901->add_subfields("d" => $_TD->{new}{share_depth});
     }
 
+    if ($_TD->{new}{source}) {
+        my $plan = spi_prepare('
+            SELECT source
+            FROM config.bib_source
+            WHERE id = $1
+        ', 'INTEGER');
+        my $source_name =
+            spi_exec_prepared($plan, {limit => 1}, $_TD->{new}{source})->{rows}[0]{source};
+        spi_freeplan($plan);
+        $new_901->add_subfields("s" => $source_name) if $source_name;
+    }
+
     $marc->append_fields($new_901);
 } elsif ($schema eq 'authority') {
     my $new_901 = MARC::Field->new("901", " ", " ",
diff --git a/Open-ILS/src/sql/Pg/t/bib_901_field.pg b/Open-ILS/src/sql/Pg/t/bib_901_field.pg
new file mode 100644
index 0000000..e41481c
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/t/bib_901_field.pg
@@ -0,0 +1,21 @@
+BEGIN;
+
+SELECT plan(1);
+
+INSERT INTO config.bib_source(id, source) VALUES (-999, 'fuente bibliográfica');
+INSERT INTO biblio.record_entry (marc, last_xact_id, source)
+VALUES ('<record xmlns="http://www.loc.gov/MARC21/slim"><leader>00531nam a2200157 a 4500</leader></record>', 'test', -999);
+
+SELECT is((
+            SELECT (XPATH(
+                '//marc:datafield[@tag="901"]/marc:subfield[@code="s"]/text()',
+                marc::XML,
+                ARRAY[ARRAY['marc', 'http://www.loc.gov/MARC21/slim']]
+            ))[1]::TEXT
+            FROM biblio.record_entry
+            WHERE id = CURRVAL('biblio.record_entry_id_seq')
+          ),
+          'fuente bibliográfica',
+          'bibliographic source placed in 901$s');
+
+ROLLBACK;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.bib_source_in_901.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.bib_source_in_901.sql
new file mode 100644
index 0000000..9644936
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.bib_source_in_901.sql
@@ -0,0 +1,122 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+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}; 
+        $_TD->{new}{tcn_value} = $tcn_value;
+    }
+
+    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});
+    }
+
+    if ($_TD->{new}{source}) {
+        my $plan = spi_prepare('
+            SELECT source
+            FROM config.bib_source
+            WHERE id = $1
+        ', 'INTEGER');
+        my $source_name =
+            spi_exec_prepared($plan, {limit => 1}, $_TD->{new}{source})->{rows}[0]{source};
+        spi_freeplan($plan);
+        $new_901->add_subfields("s" => $source_name) if $source_name;
+    }
+
+    $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
+
+$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;
+
+\qecho Now running an update to set the 901$s for bibliographic
+\qecho records that have a source set. This may take a while.
+\qecho
+\qecho The update can be cancelled now \qecho and run later
+\qecho using the following SQL statement:
+\qecho
+\qecho UPDATE biblio.record_entry SET id = id WHERE source IS NOT NULL;
+\qecho
+UPDATE biblio.record_entry SET id = id WHERE source IS NOT NULL;
diff --git a/docs/RELEASE_NOTES_NEXT/Cataloging/bib_source_in_901s.txt b/docs/RELEASE_NOTES_NEXT/Cataloging/bib_source_in_901s.txt
new file mode 100644
index 0000000..2199605
--- /dev/null
+++ b/docs/RELEASE_NOTES_NEXT/Cataloging/bib_source_in_901s.txt
@@ -0,0 +1,6 @@
+Bibliographic record source now copied to 901$s
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+If a bibliographic record has a source set, the name of that source
+is now copied to the 901$s whenever the record is created or updated.
+This allows the source to be used for record matching and MARC
+field queries.

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

Summary of changes:
 Open-ILS/src/sql/Pg/002.functions.config.sql       |   12 ++++++
 Open-ILS/src/sql/Pg/002.schema.config.sql          |    2 +-
 Open-ILS/src/sql/Pg/t/bib_901_field.pg             |   21 +++++++++++
 ...r_tcn.sql => 0988.schema.bib_source_in_901.sql} |   36 ++++++++++++-------
 .../Cataloging/bib_source_in_901s.txt              |    6 +++
 5 files changed, 63 insertions(+), 14 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/t/bib_901_field.pg
 copy Open-ILS/src/sql/Pg/upgrade/{0783.schema.enforce_use_id_for_tcn.sql => 0988.schema.bib_source_in_901.sql} (74%)
 create mode 100644 docs/RELEASE_NOTES_NEXT/Cataloging/bib_source_in_901s.txt


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list