From 184e873b9b4fbd2a04b6d241f0181867e0fca7b8 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Sat, 17 Jan 2015 12:26:34 -0500 Subject: [PATCH] General fixes, plus fix Springer "software" item forms 856 z -> y, delete 596 holding codes, springer doi link text Signed-off-by: Dan Scott --- Open-ILS/src/sql/Pg/fix_old_springer.sql | 121 +++++++++++++++++++++ .../src/sql/Pg/update_marc_records_in_database.sql | 18 +++ 2 files changed, 139 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/fix_old_springer.sql diff --git a/Open-ILS/src/sql/Pg/fix_old_springer.sql b/Open-ILS/src/sql/Pg/fix_old_springer.sql new file mode 100644 index 0000000000..cef309fdc9 --- /dev/null +++ b/Open-ILS/src/sql/Pg/fix_old_springer.sql @@ -0,0 +1,121 @@ +CREATE OR REPLACE FUNCTION conifer.cleanup_old_springer(record BIGINT) RETURNS TEXT AS $func$ +use strict; +use MARC::Record; +use MARC::File::XML (BinaryEncoding => 'UTF-8'); +use MARC::Charset; +use Encode; +use Unicode::Normalize; +use LWP::UserAgent; +use JSON::XS; + +MARC::Charset->assume_unicode(1); + +my $q = spi_prepare('SELECT marc FROM biblio.record_entry WHERE id = $1', 'BIGINT'); +my $marc = spi_exec_prepared($q, $_[0])->{rows}->[0]->{marc}; + +my $record = MARC::Record->new_from_xml($marc); + +# Fixing "Software and video game" type +# Set type to book ('a') +my $leader = $record->leader(); +my $newleader = substr $leader, 6, 1, 'a'; +$record->leader($leader); + +# Set form 008/23 to online ('o') +my @fates = $record->field('008'); +foreach my $fate (@fates) { + my $data = $fate->data(); + my $newdata = substr $data, 23, 1, 'o'; + $fate->update($data); +} + +# Add explicit publisher relator code +my @added = $record->field('710'); +foreach my $entry (@added) { + next if $entry->subfield('4'); + if ($entry->subfield('a') =~ 'SpringerLink \(Online service\)') { + $entry->add_subfields('4' => 'pbl'); + } +} + +my @eights = $record->field('856'); +foreach my $ocho (@eights) { + my @ous = $ocho->subfield('9'); + foreach my $ou (@ous) { + if ($ou eq 'WINDSYS' or $ou eq 'OWA') { + $record->delete_field($ocho); + } + if ($ou eq 'OSUL') { + $ocho->update('9' => 'LUSYS'); + } + } + + # Fix URIs that raise SSL cert issues + my $uri = $ocho->subfield('u'); + if ($uri =~ m#^https://librweb#) { + $uri =~ s{^https://librweb}{http://librweb}; + $ocho->update('u' => $uri); + } + + # Provide an indication of the platform + if ($uri =~ m#scholarsportal#) { + $ocho->update('y' => 'Available online / disponible en ligne (ScholarsPortal)'); + $ocho->delete_subfield(code => 'z', match => qr/Available/); + } elsif ($uri =~ m#dx.doi.org/10.1007#) { + $ocho->update('y' => 'Available online / disponible en ligne (Springer)'); + $ocho->delete_subfield(code => 'z', match => qr/Available/); + } elsif ($uri =~ m#myilibrary#) { + $ocho->update('y' => 'Available online / disponible en ligne (MyiLibrary)'); + $ocho->delete_subfield(code => 'z', match => qr/Available/); + } elsif ($uri =~ m#sagepub#) { + $ocho->update('y' => 'Available online / disponible en ligne (Sage)'); + $ocho->delete_subfield(code => 'z', match => qr/Available/); + } +} + +# Do not need access notes anymore +my @access = $record->field('506'); +foreach my $note (@access) { + my @ous = $note->subfield('9'); + foreach my $ou (@ous) { + if ($ou eq 'OWA') { + $record->delete_field($note); + } + } +} + +# Do not need 596 holding fields anymore +my @access = $record->field('596'); +foreach my $note (@access) { + my @ous = $note->subfield('a'); + foreach my $ou (@ous) { + if ($ou eq '1') { + $record->delete_field($note); + } + } +} + +my $xml = $record->as_xml_record(); + +$xml =~ s/\n//sgo; +$xml =~ s/^<\?xml.+\?\s*>//go; +$xml =~ s/>\s+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; + +return $xml; +$func$ LANGUAGE PLPERLU; + + diff --git a/Open-ILS/src/sql/Pg/update_marc_records_in_database.sql b/Open-ILS/src/sql/Pg/update_marc_records_in_database.sql index f077a3b3f0..133dbb1317 100644 --- a/Open-ILS/src/sql/Pg/update_marc_records_in_database.sql +++ b/Open-ILS/src/sql/Pg/update_marc_records_in_database.sql @@ -37,10 +37,16 @@ foreach my $ocho (@eights) { # Provide an indication of the platform if ($uri =~ m#scholarsportal#) { $ocho->update('y' => 'Available online / disponible en ligne (ScholarsPortal)'); + $ocho->delete_subfield(code => 'z', match => qr/Available/); + } elsif ($uri =~ m#dx.doi.org/10.1007#) { + $ocho->update('y' => 'Available online / disponible en ligne (Springer)'); + $ocho->delete_subfield(code => 'z', match => qr/Available/); } elsif ($uri =~ m#myilibrary#) { $ocho->update('y' => 'Available online / disponible en ligne (MyiLibrary)'); + $ocho->delete_subfield(code => 'z', match => qr/Available/); } elsif ($uri =~ m#sagepub#) { $ocho->update('y' => 'Available online / disponible en ligne (Sage)'); + $ocho->delete_subfield(code => 'z', match => qr/Available/); } } @@ -55,6 +61,17 @@ foreach my $note (@access) { } } +# Do not need 596 holding fields anymore +my @access = $record->field('596'); +foreach my $note (@access) { + my @ous = $note->subfield('a'); + foreach my $ou (@ous) { + if ($ou eq '1') { + $record->delete_field($note); + } + } +} + # Update provenance of the records my @provs = $record->field('040'); foreach my $prov (@provs) { @@ -206,3 +223,4 @@ EXCEPTION RETURN next_id; END; $func$ LANGUAGE PLPGSQL; + -- 2.11.0