Lines 17-28
use C4::Context;
Link Here
|
17 |
|
17 |
|
18 |
my $dbh = C4::Context->dbh; |
18 |
my $dbh = C4::Context->dbh; |
19 |
|
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 )" ); |
20 |
my $bibs_sth = $dbh->prepare( 'SELECT biblionumber FROM biblio CROSS JOIN biblioitems USING (biblionumber) WHERE ExtractValue(marcxml,\'//datafield[@tag="440"]/subfield[@code="a"]\') OR ExtractValue(marcxml,\'//datafield[@tag="440"]/subfield[@code="v"]\') OR ExtractValue(marcxml,\'//datafield[@tag="440"]/subfield[@code="n"]\') OR ExtractValue(marcxml,\'//datafield[@tag="490"]/subfield[@code="a"]\') OR ExtractValue(marcxml,\'//datafield[@tag="490"]/subfield[@code="v"]\')' ); |
21 |
|
21 |
|
22 |
$bibs_sth->execute(); |
22 |
$bibs_sth->execute(); |
23 |
while ( my ( $biblionumber ) = $bibs_sth->fetchrow ) { |
23 |
while ( my ( $biblionumber ) = $bibs_sth->fetchrow ) { |
24 |
my $framework = GetFrameworkCode( $biblionumber ) || ''; |
24 |
my $framework = GetFrameworkCode( $biblionumber ) || ''; |
25 |
my ( $series1, $volume1, $series2, $volume2, $subfield ); |
25 |
my ( @newfields ); |
26 |
|
26 |
|
27 |
# MARC21 specific |
27 |
# MARC21 specific |
28 |
my ( $series1_t, $series1_f ) = ( '440', 'a' ); |
28 |
my ( $series1_t, $series1_f ) = ( '440', 'a' ); |
Lines 35-73
while ( my ( $biblionumber ) = $bibs_sth->fetchrow ) {
Link Here
|
35 |
# Get biblio marc |
35 |
# Get biblio marc |
36 |
my $biblio = GetMarcBiblio( $biblionumber ); |
36 |
my $biblio = GetMarcBiblio( $biblionumber ); |
37 |
|
37 |
|
38 |
my $series2 = $biblio->subfield( $series2_t, $series2_f ); |
38 |
foreach my $field ( $biblio->field( $series1_t ) ) { |
39 |
my $volume2 = $biblio->subfield( $volume2_t, $volume2_f ); |
39 |
my @newsubfields; |
|
|
40 |
my @series1 = $field->subfield( $series1_f ); |
41 |
my @volume1 = $field->subfield( $volume1_f ); |
42 |
my @number1 = $field->subfield( $number1_f ); |
43 |
my $i = 0; |
44 |
foreach my $num ( @number1 ) { |
45 |
$volume1[$i] .= " " if ( $volume1[$i] ); |
46 |
$volume1[$i++] .= $num if ( $num ); |
47 |
} |
48 |
|
49 |
while ( @series1 || @volume1 ) { |
50 |
if ( @series1 ) { |
51 |
push @newsubfields, ( $series2_f, shift @series1 ); |
52 |
} |
53 |
if ( @volume1 ) { |
54 |
push @newsubfields, ( $volume2_f, shift @volume1 ); |
55 |
} |
56 |
} |
40 |
|
57 |
|
41 |
my $series1 = $biblio->subfield( $series1_t, $series1_f ); |
58 |
my $new_field = MARC::Field->new( $series2_t, '', '', |
42 |
my $volume1 = $biblio->subfield( $volume1_t, $volume1_f ); |
59 |
@newsubfields ); |
43 |
if ( $biblio->subfield( $number1_t, $number1_f ) ) { |
60 |
|
44 |
$volume1 .= " ". $biblio->subfield( $number1_t, $number1_f ); |
61 |
$biblio->delete_fields( $field ); |
|
|
62 |
push @newfields, $new_field; |
45 |
} |
63 |
} |
46 |
|
64 |
|
47 |
$subfield = $biblio->subfield( $series1_t ); |
65 |
foreach my $field ( $biblio->field( $series2_t ) ) { |
48 |
if ( $series2 or $volume2 ) { |
66 |
my @newsubfields; |
49 |
if ( $subfield ) { |
67 |
my @series2 = $field->subfield( $series2_f ); |
50 |
$subfield->update( $series1_f => $series2, $volume1_f => $volume2 ); |
68 |
my @volume2 = $field->subfield( $volume2_f ); |
51 |
} |
69 |
|
52 |
else { |
70 |
while ( @series2 || @volume2 ) { |
53 |
$subfield = MARC::Field->new( $series1_t, '', '', |
71 |
if ( @series2 ) { |
54 |
$series1_f => $series2, $volume1_f => $volume2 ); |
72 |
push @newsubfields, ( $series1_f, shift @series2 ); |
55 |
$biblio->append_fields( $subfield ); |
73 |
} |
|
|
74 |
if ( @volume2 ) { |
75 |
push @newsubfields, ( $volume1_f, shift @volume2 ); |
76 |
} |
56 |
} |
77 |
} |
57 |
} |
|
|
58 |
elsif ( $subfield ) { |
59 |
$biblio->delete_fields( $subfield ); |
60 |
} |
61 |
|
78 |
|
62 |
$subfield = $biblio->subfield( $series2_t ); |
79 |
my $new_field = MARC::Field->new( $series1_t, '', '', |
63 |
unless ( $subfield ) { |
80 |
@newsubfields ); |
64 |
$subfield = MARC::Field->new( $series2_t, '', '', |
81 |
|
65 |
$series2_f => $series1, $volume2_f => $volume1 ); |
82 |
$biblio->delete_fields( $field ); |
66 |
$biblio->append_fields( $subfield ); |
83 |
push @newfields, $new_field; |
67 |
} |
|
|
68 |
else { |
69 |
$subfield->update( $series2_f => $series1, $volume2_f => $volume1 ); |
70 |
} |
84 |
} |
|
|
85 |
$biblio->insert_fields_ordered( @newfields ); |
71 |
|
86 |
|
72 |
ModBiblioMarc( $biblio, $biblionumber, $framework ); |
87 |
ModBiblioMarc( $biblio, $biblionumber, $framework ); |
73 |
} |
88 |
} |
74 |
- |
|
|