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