Bugzilla – Attachment 156442 Details for
Bug 33749
Move Koha::MetadataRecord::stripWhitespaceChars into a RecordProcessor filter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33749: Add TrimFields field class
Bug-33749-Add-TrimFields-field-class.patch (text/plain), 3.84 KB, created by
David Nind
on 2023-09-30 21:36:52 UTC
(
hide
)
Description:
Bug 33749: Add TrimFields field class
Filename:
MIME Type:
Creator:
David Nind
Created:
2023-09-30 21:36:52 UTC
Size:
3.84 KB
patch
obsolete
>From 104049bc70018037d381d3dcd7cf29aa31831148 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 7 Jun 2023 14:28:34 -0300 >Subject: [PATCH] Bug 33749: Add TrimFields field class > >This patch adds a RecordProcessor filter class that takes care of >performing the field cleanup that was originally done in the static >method `Koha::MetadataRecord::stripWhitespaceChars`. > >In order to test the results, I adapted the tests to use the filter >instead of the original method. > >To test: >1. Run: > $ ktd --shell > k$ prove t/Koha_MetadataRecord.t >=> SUCCESS: Tests pass >2. Apply this patch >3. Repeat 1 >=> SUCCESS: Tests still pass >4. Sign off :-D > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/Filter/MARC/TrimFields.pm | 71 ++++++++++++++++++++++++++++++++++ > t/Koha_MetadataRecord.t | 4 +- > 2 files changed, 74 insertions(+), 1 deletion(-) > create mode 100644 Koha/Filter/MARC/TrimFields.pm > >diff --git a/Koha/Filter/MARC/TrimFields.pm b/Koha/Filter/MARC/TrimFields.pm >new file mode 100644 >index 0000000000..f5a9d9fcef >--- /dev/null >+++ b/Koha/Filter/MARC/TrimFields.pm >@@ -0,0 +1,71 @@ >+package Koha::Filter::MARC::TrimFields; >+ >+# Copyright 2023 Koha Development team >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+Koha::Filter::MARC::TrimFields - Trims MARC::Record object data fields. >+ >+=head1 SYNOPSIS >+ >+ my $p = Koha::RecordProcessor->new({ filters => ['TrimFields'] }); >+ >+ my $metadata = Koha::Biblio::Metadatas->find($biblio_id); >+ my $record = $metadata->record; >+ >+ $p->process($record); >+ >+=head1 DESCRIPTION >+ >+Filter to trim MARC::Record object data fields. >+ >+=cut >+ >+use Modern::Perl; >+ >+use base qw(Koha::RecordProcessor::Base); >+our $NAME = 'TrimFields'; >+ >+=head2 filter >+ >+Trim MARC::Record object data fields. >+ >+=cut >+ >+sub filter { >+ my ( $self, $record ) = @_; >+ >+ return >+ unless $record and ref($record) eq 'MARC::Record'; >+ >+ foreach my $field ( $record->fields ) { >+ unless ( $field->is_control_field ) { >+ foreach my $subfield ( $field->subfields ) { >+ my $key = $subfield->[0]; >+ my $value = $subfield->[1]; >+ $value =~ s/[\n\r]+/ /g; >+ $value =~ s/^\s+|\s+$//g; >+ $field->add_subfields( $key => $value ); # add subfield to the end of the subfield list >+ $field->delete_subfield( pos => 0 ); # delete the subfield at the top of the subfield list >+ } >+ } >+ } >+ return $record; >+} >+ >+1; >diff --git a/t/Koha_MetadataRecord.t b/t/Koha_MetadataRecord.t >index 7202f4a86f..f44700970c 100755 >--- a/t/Koha_MetadataRecord.t >+++ b/t/Koha_MetadataRecord.t >@@ -22,6 +22,7 @@ use Modern::Perl; > use Test::More tests => 6; > use Test::Warn; > >+use Koha::RecordProcessor; > use MARC::Record; > > BEGIN { >@@ -156,7 +157,8 @@ subtest "stripWhitespaceChars() tests" => sub { > [ '521', ' ', ' ', a => "This is a\t test!\t" ], > ); > >- $record = Koha::MetadataRecord::stripWhitespaceChars( $record ); >+ my $p = Koha::RecordProcessor->new({ filters => ['TrimFields'] }); >+ $p->process( $record ); > > my $get520a = $record->subfield('520','a'); > is( $get520a, "This is a test!", "Whitespace characters are appropriately stripped or replaced with spaces" ); >-- >2.30.2
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 33749
:
152135
|
152136
|
156442
|
156443
|
158338
|
158339
|
158340
|
158341