Bugzilla – Attachment 194171 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: Show nonxml_stripped errors in edit form with quick-links to fields
5ebcbb6.patch (text/plain), 6.29 KB, created by
Martin Renvoize (ashimema)
on 2026-02-27 19:24:20 UTC
(
hide
)
Description:
Bug 35104: Show nonxml_stripped errors in edit form with quick-links to fields
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-02-27 19:24:20 UTC
Size:
6.29 KB
patch
obsolete
>From 5ebcbb67b7ed77c1c3dfbf3342584520c387d87f Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Fri, 27 Feb 2026 18:33:05 +0000 >Subject: [PATCH] Bug 35104: Show nonxml_stripped errors in edit form with > quick-links to fields > >Two related changes: > >1. Metadata::store() no longer auto-clears nonxml_stripped errors on a > clean re-save. Errors are review flags that require deliberate human > resolution; they are only replaced when fresh stripping occurs on the > same record. > >2. addbiblio.pl loads any existing nonxml_stripped errors for a biblio > being edited and passes them to the template. The template renders > them in an alert banner above the editor with "Go to field" quick-links > that navigate to the correct tab and scroll to the first occurrence of > the affected subfield. A custom .nonxml-linkfield JS handler resolves > the tab and element at click time using the tag/subfield data attributes, > avoiding the need to know the random element-ID suffix server-side. >--- > Koha/Biblio/Metadata.pm | 7 ++-- > cataloguing/addbiblio.pl | 29 ++++++++++++++++ > .../prog/en/modules/cataloguing/addbiblio.tt | 34 +++++++++++++++++++ > 3 files changed, 68 insertions(+), 2 deletions(-) > >diff --git a/Koha/Biblio/Metadata.pm b/Koha/Biblio/Metadata.pm >index 6cb83e2a6af..d673004617d 100644 >--- a/Koha/Biblio/Metadata.pm >+++ b/Koha/Biblio/Metadata.pm >@@ -117,9 +117,12 @@ sub store { > > $self->SUPER::store; > >- # Sync nonxml_stripped error rows: clear any existing, then re-add if needed >- $self->metadata_errors->search( { error_type => 'nonxml_stripped' } )->delete; >+ # If this save triggered fresh stripping, replace all existing nonxml_stripped >+ # errors with the new set. If the save was clean (no stripping needed), leave >+ # any existing errors alone â they are review flags requiring explicit human >+ # resolution and should not be silently cleared by a routine re-save. > if ($nonxml_error_message) { >+ $self->metadata_errors->search( { error_type => 'nonxml_stripped' } )->delete; > my @occurrences = > ref $nonxml_error_message eq 'ARRAY' > ? @{$nonxml_error_message} >diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl >index 4bb600a029a..144095b30c2 100755 >--- a/cataloguing/addbiblio.pl >+++ b/cataloguing/addbiblio.pl >@@ -681,6 +681,35 @@ if ($biblionumber) { > } > } > >+# Load any existing nonxml_stripped errors so they can be shown in the edit form >+# with quick-links to the affected fields. >+if ( $biblio && $is_a_modif ) { >+ my @existing_errors = $biblio->metadata->metadata_errors->search( { error_type => 'nonxml_stripped' } )->as_list; >+ if (@existing_errors) { >+ $template->param( >+ existing_nonxml_errors => [ >+ map { >+ my $msg = $_->message; >+ >+ # First line is "TAG$sub: invalid char ..." â extract tag/subfield >+ my ($field_ref) = $msg =~ /^(\S+?):/; >+ my ( $tag, $subfield ) = >+ $field_ref && $field_ref =~ /^(\w+)\$(\w)$/ ? ( $1, $2 ) >+ : $field_ref ? ( $field_ref, undef ) >+ : ( undef, undef ); >+ { >+ id => $_->id, >+ message => $msg, >+ field_ref => $field_ref // '', >+ tag => $tag // '', >+ subfield => $subfield // '', >+ } >+ } @existing_errors >+ ] >+ ); >+ } >+} >+ > #------------------------------------------------------------------------------------- > if ( $op eq "cud-addbiblio" ) { > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >index 46d4827e9a8..dea2d4911ad 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >@@ -193,6 +193,21 @@ > document.getElementById("form-errors").scrollIntoView(); > }); > >+ $("body").on("click", ".nonxml-linkfield", function(e){ >+ e.preventDefault(); >+ var tag = $(this).data("tag"); >+ var sub = $(this).data("subfield") || "@"; >+ // Find the first subfield_line for this tag+subfield (random suffix unknown) >+ var $li = $('li[id^="subfield' + tag + sub + '"]').first(); >+ if ( !$li.length ) return; >+ // Determine which tab contains the field >+ var $tabpane = $li.closest(".tab-pane"); >+ if ( $tabpane.length ) { >+ selectTab("#" + $tabpane.attr("id")); >+ } >+ window.scrollTo(0, getScrollto($li.attr("id"), "toolbar")); >+ }); >+ > }); > > function selectTab( tablink ){ >@@ -798,6 +813,25 @@ > [% END #/ WRAPPER sub-header.inc %] > > [% WRAPPER 'main-container.inc' wide_centered => 1 %] >+ [% IF existing_nonxml_errors %] >+ <div class="alert alert-warning" id="nonxml-errors-notice"> >+ <h2>Data quality warnings</h2> >+ <p><strong>Non-XML characters were automatically stripped from this record when it was last saved. Please review the affected fields and correct or confirm the data.</strong></p> >+ <ul> >+ [% FOREACH err IN existing_nonxml_errors %] >+ <li> >+ [% IF err.tag %] >+ <a class="nonxml-linkfield btn btn-link" href="#" data-tag="[% err.tag | html %]" [% IF err.subfield %]data-subfield="[% err.subfield | html %]"[% END %]> >+ <i class="fa fa-arrow-right" aria-hidden="true"></i> >+ Go to [% err.field_ref | html %] >+ </a> >+ [% END %] >+ <code>[% err.message | html %]</code> >+ </li> >+ [% END %] >+ </ul> >+ </div> >+ [% END %] > [% IF ( INVALID_METADATA ) %] > <div class="alert alert-warning"> > <h1>Errors found</h1> >-- >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
|
194152
|
194153
|
194154
|
194155
|
194156
|
194157
|
194158
|
194159
|
194160
|
194161
|
194162
|
194163
|
194164
|
194165
|
194166
|
194167
|
194168
|
194169
|
194170
| 194171 |
194172