|
Lines 91-141
if ( $op eq 'cud-merge' ) {
Link Here
|
| 91 |
my $frameworkcode = $input->param('frameworkcode'); |
91 |
my $frameworkcode = $input->param('frameworkcode'); |
| 92 |
|
92 |
|
| 93 |
# Modifying the reference record |
93 |
# Modifying the reference record |
| 94 |
ModBiblio( $record, $ref_biblionumber, $frameworkcode ); |
94 |
my $invalid_metadata; |
|
|
95 |
my $modded = try { |
| 96 |
ModBiblio($record, $ref_biblionumber, $frameworkcode); |
| 97 |
return 1; |
| 98 |
} catch { |
| 99 |
my $exception = $_; |
| 100 |
if ( ref($exception) eq 'Koha::Exceptions::Metadata::Invalid' ) { |
| 101 |
$invalid_metadata = $exception; |
| 102 |
} else { |
| 103 |
$exception->rethrow; |
| 104 |
} |
| 105 |
return 0; |
| 106 |
}; |
| 95 |
|
107 |
|
| 96 |
my $report_header = {}; |
108 |
my $report_header = {}; |
| 97 |
foreach my $biblionumber ( $ref_biblionumber, @biblionumbers ) { |
109 |
if ($modded) { |
| 98 |
|
110 |
foreach my $biblionumber ( $ref_biblionumber, @biblionumbers ) { |
| 99 |
# build report |
111 |
|
| 100 |
my $biblio = Koha::Biblios->find($biblionumber); |
112 |
# build report |
| 101 |
my $marcrecord = $biblio->metadata->record; |
113 |
my $biblio = Koha::Biblios->find($biblionumber); |
| 102 |
my %report_record = ( |
114 |
my $marcrecord = $biblio->metadata->record; |
| 103 |
biblionumber => $biblionumber, |
115 |
my %report_record = ( |
| 104 |
fields => {}, |
116 |
biblionumber => $biblionumber, |
| 105 |
); |
117 |
fields => {}, |
| 106 |
foreach my $field (@report_fields) { |
118 |
); |
| 107 |
my @marcfields = $marcrecord->field( $field->{tag} ); |
119 |
foreach my $field (@report_fields) { |
| 108 |
foreach my $marcfield (@marcfields) { |
120 |
my @marcfields = $marcrecord->field( $field->{tag} ); |
| 109 |
my $tag = $marcfield->tag(); |
121 |
foreach my $marcfield (@marcfields) { |
| 110 |
if ( scalar @{ $field->{subfields} } ) { |
122 |
my $tag = $marcfield->tag(); |
| 111 |
foreach my $subfield ( @{ $field->{subfields} } ) { |
123 |
if ( scalar @{ $field->{subfields} } ) { |
| 112 |
my @values = $marcfield->subfield($subfield); |
124 |
foreach my $subfield ( @{ $field->{subfields} } ) { |
| 113 |
$report_header->{ $tag . $subfield } = 1; |
125 |
my @values = $marcfield->subfield($subfield); |
| 114 |
push @{ $report_record{fields}->{ $tag . $subfield } }, @values; |
126 |
$report_header->{ $tag . $subfield } = 1; |
| 115 |
} |
127 |
push @{ $report_record{fields}->{ $tag . $subfield } }, @values; |
| 116 |
} elsif ( $field->{tag} gt '009' ) { |
128 |
} |
| 117 |
my @marcsubfields = $marcfield->subfields(); |
129 |
} elsif ( $field->{tag} gt '009' ) { |
| 118 |
foreach my $marcsubfield (@marcsubfields) { |
130 |
my @marcsubfields = $marcfield->subfields(); |
| 119 |
my ( $code, $value ) = @$marcsubfield; |
131 |
foreach my $marcsubfield (@marcsubfields) { |
| 120 |
$report_header->{ $tag . $code } = 1; |
132 |
my ( $code, $value ) = @$marcsubfield; |
| 121 |
push @{ $report_record{fields}->{ $tag . $code } }, $value; |
133 |
$report_header->{ $tag . $code } = 1; |
|
|
134 |
push @{ $report_record{fields}->{ $tag . $code } }, $value; |
| 135 |
} |
| 136 |
} else { |
| 137 |
$report_header->{ $tag . '@' } = 1; |
| 138 |
push @{ $report_record{fields}->{ $tag . '@' } }, $marcfield->data(); |
| 122 |
} |
139 |
} |
| 123 |
} else { |
|
|
| 124 |
$report_header->{ $tag . '@' } = 1; |
| 125 |
push @{ $report_record{fields}->{ $tag . '@' } }, $marcfield->data(); |
| 126 |
} |
140 |
} |
| 127 |
} |
141 |
} |
|
|
142 |
push @report_records, \%report_record; |
| 128 |
} |
143 |
} |
| 129 |
push @report_records, \%report_record; |
|
|
| 130 |
} |
| 131 |
|
144 |
|
| 132 |
my $rmerge; |
145 |
my $rmerge; |
| 133 |
eval { |
146 |
eval { |
| 134 |
my $newbiblio = Koha::Biblios->find($ref_biblionumber); |
147 |
my $newbiblio = Koha::Biblios->find($ref_biblionumber); |
| 135 |
$rmerge = $newbiblio->merge_with( \@biblionumbers ); |
148 |
$rmerge = $newbiblio->merge_with( \@biblionumbers ); |
| 136 |
}; |
149 |
}; |
| 137 |
if ($@) { |
150 |
if ($@) { |
| 138 |
push @errors, $@; |
151 |
push @errors, $@; |
|
|
152 |
} |
| 153 |
} else { |
| 154 |
push @errors, { code => "INVALID_METADATA", value => $invalid_metadata }; |
| 139 |
} |
155 |
} |
| 140 |
|
156 |
|
| 141 |
# Parameters |
157 |
# Parameters |