Bugzilla – Attachment 193987 Details for
Bug 35104
We should warn when attempting to save MARC records that contain characters invalid in XML
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35104: Catch the failure on merging records
d527507.patch (text/plain), 6.23 KB, created by
Martin Renvoize (ashimema)
on 2026-02-26 13:31:52 UTC
(
hide
)
Description:
Bug 35104: Catch the failure on merging records
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-02-26 13:31:52 UTC
Size:
6.23 KB
patch
obsolete
>From d52750772cd3240eb1ed93df726385156fba3597 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 12 Jun 2024 14:15:34 +0100 >Subject: [PATCH] Bug 35104: Catch the failure on merging records > >We now catch the error and display it to the end user so they can fix >the issues before attempting to merge again. > >Signed-off-by: Baptiste Bayche <baptiste.bayche@inlibro.com> >Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >--- > cataloguing/merge.pl | 92 +++++++++++-------- > .../prog/en/modules/cataloguing/merge.tt | 3 + > 2 files changed, 57 insertions(+), 38 deletions(-) > >diff --git a/cataloguing/merge.pl b/cataloguing/merge.pl >index 4ebc9c93bf6..a48f4bbe0f1 100755 >--- a/cataloguing/merge.pl >+++ b/cataloguing/merge.pl >@@ -91,51 +91,67 @@ if ( $op eq 'cud-merge' ) { > my $frameworkcode = $input->param('frameworkcode'); > > # Modifying the reference record >- ModBiblio( $record, $ref_biblionumber, $frameworkcode ); >+ my $invalid_metadata; >+ my $modded = try { >+ ModBiblio($record, $ref_biblionumber, $frameworkcode); >+ return 1; >+ } catch { >+ my $exception = $_; >+ if ( ref($exception) eq 'Koha::Exceptions::Metadata::Invalid' ) { >+ $invalid_metadata = $exception; >+ } else { >+ $exception->rethrow; >+ } >+ return 0; >+ }; > > my $report_header = {}; >- foreach my $biblionumber ( $ref_biblionumber, @biblionumbers ) { >- >- # build report >- my $biblio = Koha::Biblios->find($biblionumber); >- my $marcrecord = $biblio->metadata->record; >- my %report_record = ( >- biblionumber => $biblionumber, >- fields => {}, >- ); >- foreach my $field (@report_fields) { >- my @marcfields = $marcrecord->field( $field->{tag} ); >- foreach my $marcfield (@marcfields) { >- my $tag = $marcfield->tag(); >- if ( scalar @{ $field->{subfields} } ) { >- foreach my $subfield ( @{ $field->{subfields} } ) { >- my @values = $marcfield->subfield($subfield); >- $report_header->{ $tag . $subfield } = 1; >- push @{ $report_record{fields}->{ $tag . $subfield } }, @values; >- } >- } elsif ( $field->{tag} gt '009' ) { >- my @marcsubfields = $marcfield->subfields(); >- foreach my $marcsubfield (@marcsubfields) { >- my ( $code, $value ) = @$marcsubfield; >- $report_header->{ $tag . $code } = 1; >- push @{ $report_record{fields}->{ $tag . $code } }, $value; >+ if ($modded) { >+ foreach my $biblionumber ( $ref_biblionumber, @biblionumbers ) { >+ >+ # build report >+ my $biblio = Koha::Biblios->find($biblionumber); >+ my $marcrecord = $biblio->metadata->record; >+ my %report_record = ( >+ biblionumber => $biblionumber, >+ fields => {}, >+ ); >+ foreach my $field (@report_fields) { >+ my @marcfields = $marcrecord->field( $field->{tag} ); >+ foreach my $marcfield (@marcfields) { >+ my $tag = $marcfield->tag(); >+ if ( scalar @{ $field->{subfields} } ) { >+ foreach my $subfield ( @{ $field->{subfields} } ) { >+ my @values = $marcfield->subfield($subfield); >+ $report_header->{ $tag . $subfield } = 1; >+ push @{ $report_record{fields}->{ $tag . $subfield } }, @values; >+ } >+ } elsif ( $field->{tag} gt '009' ) { >+ my @marcsubfields = $marcfield->subfields(); >+ foreach my $marcsubfield (@marcsubfields) { >+ my ( $code, $value ) = @$marcsubfield; >+ $report_header->{ $tag . $code } = 1; >+ push @{ $report_record{fields}->{ $tag . $code } }, $value; >+ } >+ } else { >+ $report_header->{ $tag . '@' } = 1; >+ push @{ $report_record{fields}->{ $tag . '@' } }, $marcfield->data(); > } >- } else { >- $report_header->{ $tag . '@' } = 1; >- push @{ $report_record{fields}->{ $tag . '@' } }, $marcfield->data(); > } > } >+ push @report_records, \%report_record; > } >- push @report_records, \%report_record; >- } > >- my $rmerge; >- eval { >- my $newbiblio = Koha::Biblios->find($ref_biblionumber); >- $rmerge = $newbiblio->merge_with( \@biblionumbers ); >- }; >- if ($@) { >- push @errors, $@; >+ my $rmerge; >+ eval { >+ my $newbiblio = Koha::Biblios->find($ref_biblionumber); >+ $rmerge = $newbiblio->merge_with( \@biblionumbers ); >+ }; >+ if ($@) { >+ push @errors, $@; >+ } >+ } else { >+ push @errors, { code => "INVALID_METADATA", value => $invalid_metadata }; > } > > # Parameters >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt >index cbfa421a54e..a7d22b8be6e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt >@@ -61,6 +61,9 @@ > <div class="alert alert-warning"> > [% IF error.code == 'CANNOT_MOVE' %] > The following items could not be moved from the old record to the new one: [% error.value | html %] >+ [% ELSIF error.code == 'INVALID_METADATA' %] >+ <p>This record had encoding issues, non-xml characters have been stripped in order to allow editing. Please be cautious when saving that some data may have been removed from the record.</p> >+ <pre class="problem">[% error.value | html %]</pre> > [% ELSE %] > [% error | html %] > [% END %] >-- >2.53.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35104
:
157625
|
157627
|
157628
|
157642
|
159615
|
159620
|
159621
|
159630
|
159810
|
159811
|
159812
|
159813
|
166431
|
173145
|
173146
|
176820
|
176821
|
176850
|
176851
|
176852
|
176860
|
193985
|
193986
|
193987
|
193988
|
193989
|
193990
|
193991
|
193992
|
193993
|
193994
|
193995
|
193996
|
193997
|
193998
|
193999
|
194000
|
194001
|
194004
|
194005
|
194006
|
194007
|
194008
|
194009
|
194010
|
194011
|
194012
|
194013