Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Script to switch the MARC21 440$anv and 490$av information |
4 |
# It's best to run this immediately after changing the MARC frameworks |
5 |
# from using the 440 subfields for the biblio and biblioitems tables to using |
6 |
# the 490 subfields. |
7 |
|
8 |
BEGIN { |
9 |
# find Koha's Perl modules |
10 |
# test carefully before changing this |
11 |
use FindBin; |
12 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
13 |
} |
14 |
|
15 |
use C4::Biblio; |
16 |
use C4::Context; |
17 |
|
18 |
my $dbh = C4::Context->dbh; |
19 |
|
20 |
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 )" ); |
21 |
|
22 |
$bibs_sth->execute(); |
23 |
while ( my ( $biblionumber ) = $bibs_sth->fetchrow ) { |
24 |
my $framework = GetFrameworkCode( $biblionumber ) || ''; |
25 |
my ( $series1, $volume1, $series2, $volume2, $subfield ); |
26 |
|
27 |
# MARC21 specific |
28 |
my ( $series1_t, $series1_f ) = ( '440', 'a' ); |
29 |
my ( $volume1_t, $volume1_f ) = ( '440', 'v' ); |
30 |
my ( $number1_t, $number1_f ) = ( '440', 'n' ); |
31 |
|
32 |
my ( $series2_t, $series2_f ) = ( '490', 'a' ); |
33 |
my ( $volume2_t, $volume2_f ) = ( '490', 'v' ); |
34 |
|
35 |
# Get biblio marc |
36 |
my $biblio = GetMarcBiblio( $biblionumber ); |
37 |
|
38 |
my $series2 = $biblio->subfield( $series2_t, $series2_f ); |
39 |
my $volume2 = $biblio->subfield( $volume2_t, $volume2_f ); |
40 |
|
41 |
my $series1 = $biblio->subfield( $series1_t, $series1_f ); |
42 |
my $volume1 = $biblio->subfield( $volume1_t, $volume1_f ); |
43 |
if ( $biblio->subfield( $number1_t, $number1_f ) ) { |
44 |
$volume1 .= " ". $biblio->subfield( $number1_t, $number1_f ); |
45 |
} |
46 |
|
47 |
$subfield = $biblio->subfield( $series1_t ); |
48 |
if ( $series2 or $volume2 ) { |
49 |
if ( $subfield ) { |
50 |
$subfield->update( $series1_f => $series2, $volume1_f => $volume2 ); |
51 |
} |
52 |
else { |
53 |
$subfield = MARC::Field->new( $series1_t, '', '', |
54 |
$series1_f => $series2, $volume1_f => $volume2 ); |
55 |
$biblio->append_fields( $subfield ); |
56 |
} |
57 |
} |
58 |
elsif ( $subfield ) { |
59 |
$biblio->delete_fields( $subfield ); |
60 |
} |
61 |
|
62 |
$subfield = $biblio->subfield( $series2_t ); |
63 |
unless ( $subfield ) { |
64 |
$subfield = MARC::Field->new( $series2_t, '', '', |
65 |
$series2_f => $series1, $volume2_f => $volume1 ); |
66 |
$biblio->append_fields( $subfield ); |
67 |
} |
68 |
else { |
69 |
$subfield->update( $series2_f => $series1, $volume2_f => $volume1 ); |
70 |
} |
71 |
|
72 |
ModBiblioMarc( $biblio, $biblionumber, $framework ); |
73 |
} |