From b66f779688080c752d152c67d88ac6ed5de87a7a Mon Sep 17 00:00:00 2001 From: Michael Hafen Date: Tue, 11 Jan 2011 16:28:42 -0700 Subject: [PATCH] [HEAD] command-line tool to switch information in 440 and 490 tags Content-Type: text/plain; charset="utf-8" With the MARC21 standard moving from the 440 tag to the 490, this tool is to help libraries make the move. --- misc/migration_tools/switch_marc21_series_info.pl | 73 +++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-) create mode 100755 misc/migration_tools/switch_marc21_series_info.pl diff --git a/misc/migration_tools/switch_marc21_series_info.pl b/misc/migration_tools/switch_marc21_series_info.pl new file mode 100755 index 0000000..e174224 --- /dev/null +++ b/misc/migration_tools/switch_marc21_series_info.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl + +# Script to switch the MARC21 440$anv and 490$av information +# It's best to run this immediately after changing the MARC frameworks +# from using the 440 subfields for the biblio and biblioitems tables to using +# the 490 subfields. + +BEGIN { + # find Koha's Perl modules + # test carefully before changing this + use FindBin; + eval { require "$FindBin::Bin/../kohalib.pl" }; +} + +use C4::Biblio; +use C4::Context; + +my $dbh = C4::Context->dbh; + +my $bibs_sth = $dbh->prepare( "SELECT biblionumber FROM biblio CROSS JOIN biblioitems USING (biblionumber) WHERE ( seriestitle <> '' AND seriestitle IS NOT NULL ) OR ( volume <> '' AND volume IS NOT NULL ) OR ( number <> '' AND number IS NOT NULL )" ); + +$bibs_sth->execute(); +while ( my ( $biblionumber ) = $bibs_sth->fetchrow ) { + my $framework = GetFrameworkCode( $biblionumber ) || ''; + my ( $series1, $volume1, $series2, $volume2, $subfield ); + + # MARC21 specific + my ( $series1_t, $series1_f ) = ( '440', 'a' ); + my ( $volume1_t, $volume1_f ) = ( '440', 'v' ); + my ( $number1_t, $number1_f ) = ( '440', 'n' ); + + my ( $series2_t, $series2_f ) = ( '490', 'a' ); + my ( $volume2_t, $volume2_f ) = ( '490', 'v' ); + + # Get biblio marc + my $biblio = GetMarcBiblio( $biblionumber ); + + my $series2 = $biblio->subfield( $series2_t, $series2_f ); + my $volume2 = $biblio->subfield( $volume2_t, $volume2_f ); + + my $series1 = $biblio->subfield( $series1_t, $series1_f ); + my $volume1 = $biblio->subfield( $volume1_t, $volume1_f ); + if ( $biblio->subfield( $number1_t, $number1_f ) ) { + $volume1 .= " ". $biblio->subfield( $number1_t, $number1_f ); + } + + $subfield = $biblio->subfield( $series1_t ); + if ( $series2 or $volume2 ) { + if ( $subfield ) { + $subfield->update( $series1_f => $series2, $volume1_f => $volume2 ); + } + else { + $subfield = MARC::Field->new( $series1_t, '', '', + $series1_f => $series2, $volume1_f => $volume2 ); + $biblio->append_fields( $subfield ); + } + } + elsif ( $subfield ) { + $biblio->delete_fields( $subfield ); + } + + $subfield = $biblio->subfield( $series2_t ); + unless ( $subfield ) { + $subfield = MARC::Field->new( $series2_t, '', '', + $series2_f => $series1, $volume2_f => $volume1 ); + $biblio->append_fields( $subfield ); + } + else { + $subfield->update( $series2_f => $series1, $volume2_f => $volume1 ); + } + + ModBiblioMarc( $biblio, $biblionumber, $framework ); +} -- 1.7.1