From: Chris Sharp Date: Fri, 24 Sep 2021 18:50:52 +0000 (-0400) Subject: LP#1901597: Stamp upgrade scripts X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=439b75deada6ccee8995543ed0062a6ce2b9e8f0;p=working%2FEvergreen.git LP#1901597: Stamp upgrade scripts Signed-off-by: Chris Sharp --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 6339ed5ccc..966a2c6d6c 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 ('1298', :eg_version); -- miker / ehardy / csharp +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1299', :eg_version); -- miker / rogan / csharp CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/1299.function.strip_field_multimatch.sql b/Open-ILS/src/sql/Pg/upgrade/1299.function.strip_field_multimatch.sql new file mode 100644 index 0000000000..61929bc51d --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/1299.function.strip_field_multimatch.sql @@ -0,0 +1,72 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('1299', :eg_version); + +CREATE OR REPLACE FUNCTION vandelay.strip_field(xml text, field text) RETURNS text AS $f$ + + use MARC::Record; + use MARC::File::XML (BinaryEncoding => 'UTF-8'); + use MARC::Charset; + use strict; + + MARC::Charset->assume_unicode(1); + + my $xml = shift; + my $r = MARC::Record->new_from_xml( $xml ); + + return $xml unless ($r); + + my $field_spec = shift; + my @field_list = split(',', $field_spec); + + my %fields; + for my $f (@field_list) { + $f =~ s/^\s*//; $f =~ s/\s*$//; + if ($f =~ /^(.{3})(\w*)(?:\[([^]]*)\])?$/) { + my $field = $1; + $field =~ s/\s+//; + my $sf = $2; + $sf =~ s/\s+//; + my $matches = $3; + $matches =~ s/^\s*//; $matches =~ s/\s*$//; + $fields{$field} = { sf => [ split('', $sf) ] }; + if ($matches) { + for my $match (split('&&', $matches)) { + $match =~ s/^\s*//; $match =~ s/\s*$//; + my ($msf,$mre) = split('~', $match); + if (length($msf) > 0 and length($mre) > 0) { + $msf =~ s/^\s*//; $msf =~ s/\s*$//; + $mre =~ s/^\s*//; $mre =~ s/\s*$//; + $fields{$field}{match}{$msf} = qr/$mre/; + } + } + } + } + } + + for my $f ( keys %fields) { + for my $to_field ($r->field( $f )) { + if (exists($fields{$f}{match})) { + my @match_list = grep { $to_field->subfield($_) =~ $fields{$f}{match}{$_} } keys %{$fields{$f}{match}}; + next unless (scalar(@match_list) == scalar(keys %{$fields{$f}{match}})); + } + + if ( @{$fields{$f}{sf}} ) { + $to_field->delete_subfield(code => $fields{$f}{sf}); + } else { + $r->delete_field( $to_field ); + } + } + } + + $xml = $r->as_xml_record; + $xml =~ s/^<\?.+?\?>$//mo; + $xml =~ s/\n//sgo; + $xml =~ s/>\s+ 'UTF-8'); - use MARC::Charset; - use strict; - - MARC::Charset->assume_unicode(1); - - my $xml = shift; - my $r = MARC::Record->new_from_xml( $xml ); - - return $xml unless ($r); - - my $field_spec = shift; - my @field_list = split(',', $field_spec); - - my %fields; - for my $f (@field_list) { - $f =~ s/^\s*//; $f =~ s/\s*$//; - if ($f =~ /^(.{3})(\w*)(?:\[([^]]*)\])?$/) { - my $field = $1; - $field =~ s/\s+//; - my $sf = $2; - $sf =~ s/\s+//; - my $matches = $3; - $matches =~ s/^\s*//; $matches =~ s/\s*$//; - $fields{$field} = { sf => [ split('', $sf) ] }; - if ($matches) { - for my $match (split('&&', $matches)) { - $match =~ s/^\s*//; $match =~ s/\s*$//; - my ($msf,$mre) = split('~', $match); - if (length($msf) > 0 and length($mre) > 0) { - $msf =~ s/^\s*//; $msf =~ s/\s*$//; - $mre =~ s/^\s*//; $mre =~ s/\s*$//; - $fields{$field}{match}{$msf} = qr/$mre/; - } - } - } - } - } - - for my $f ( keys %fields) { - for my $to_field ($r->field( $f )) { - if (exists($fields{$f}{match})) { - my @match_list = grep { $to_field->subfield($_) =~ $fields{$f}{match}{$_} } keys %{$fields{$f}{match}}; - next unless (scalar(@match_list) == scalar(keys %{$fields{$f}{match}})); - } - - if ( @{$fields{$f}{sf}} ) { - $to_field->delete_subfield(code => $fields{$f}{sf}); - } else { - $r->delete_field( $to_field ); - } - } - } - - $xml = $r->as_xml_record; - $xml =~ s/^<\?.+?\?>$//mo; - $xml =~ s/\n//sgo; - $xml =~ s/>\s+