Bugzilla – Attachment 156443 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: Use TrimFields instead of stripWhitespaceChars
Bug-33749-Use-TrimFields-instead-of-stripWhitespac.patch (text/plain), 5.41 KB, created by
David Nind
on 2023-09-30 21:36:55 UTC
(
hide
)
Description:
Bug 33749: Use TrimFields instead of stripWhitespaceChars
Filename:
MIME Type:
Creator:
David Nind
Created:
2023-09-30 21:36:55 UTC
Size:
5.41 KB
patch
obsolete
>From 23d553a8e5afc592be06e5d4f53fcbd07a1da018 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 7 Jun 2023 17:31:37 -0300 >Subject: [PATCH] Bug 33749: Use TrimFields instead of stripWhitespaceChars > >This patch replaces the uses of the static method with the new filter. >It also moves the tests to the relevant place and removes the (now) >unused method. > >Signed-off-by: David Nind <david@davidnind.com> >--- > C4/AuthoritiesMarc.pm | 4 +++- > C4/Biblio.pm | 5 +++-- > Koha/MetadataRecord.pm | 27 --------------------------- > t/Koha_MetadataRecord.t | 25 +------------------------ > t/RecordProcessor.t | 24 ++++++++++++++++++++++++ > 5 files changed, 31 insertions(+), 54 deletions(-) > >diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm >index d21e7c059c..e8d84a3c1a 100644 >--- a/C4/AuthoritiesMarc.pm >+++ b/C4/AuthoritiesMarc.pm >@@ -35,6 +35,7 @@ use Koha::Authority::MergeRequests; > use Koha::Authority::Types; > use Koha::Authority; > use Koha::Libraries; >+use Koha::RecordProcessor; > use Koha::SearchEngine; > use Koha::SearchEngine::Indexer; > use Koha::SearchEngine::Search; >@@ -659,7 +660,8 @@ sub AddAuthority { > } > > if ( C4::Context->preference('StripWhitespaceChars') ) { >- $record = Koha::MetadataRecord::stripWhitespaceChars( $record ); >+ my $p = Koha::RecordProcessor->new({ filters => qw(TrimFields) }); >+ $p->process( $record ); > } > > # Save record into auth_header, update 001 >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index a0e942f79e..3c70c8c4bd 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -110,11 +110,11 @@ use Koha::Holds; > use Koha::ItemTypes; > use Koha::MarcOverlayRules; > use Koha::Plugins; >+use Koha::RecordProcessor; > use Koha::SearchEngine; > use Koha::SearchEngine::Indexer; > use Koha::Libraries; > use Koha::Util::MARC; >-use Koha::MetadataRecord; > > =head1 NAME > >@@ -2829,7 +2829,8 @@ sub ModBiblioMarc { > } > > if ( C4::Context->preference('StripWhitespaceChars') ) { >- $record = Koha::MetadataRecord::stripWhitespaceChars( $record ); >+ my $p = Koha::RecordProcessor->new({ filters => qw(TrimFields) }); >+ $p->process( $record ); > } > > my $metadata = { >diff --git a/Koha/MetadataRecord.pm b/Koha/MetadataRecord.pm >index bb7ec62be0..6f0aa1fb4b 100644 >--- a/Koha/MetadataRecord.pm >+++ b/Koha/MetadataRecord.pm >@@ -108,31 +108,4 @@ sub createMergeHash { > } > } > >-=head2 stripWhitespaceChars >- >- $record = Koha::MetadataRecord::stripWhitespaceChars( $record ); >- >-Strip leading and trailing whitespace characters from input fields. >- >-=cut >- >-sub stripWhitespaceChars { >- my ( $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 f44700970c..cb24fb8659 100755 >--- a/t/Koha_MetadataRecord.t >+++ b/t/Koha_MetadataRecord.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 6; >+use Test::More tests => 5; > use Test::Warn; > > use Koha::RecordProcessor; >@@ -143,26 +143,3 @@ subtest "new() tests" => sub { > > is( $metadata_record, undef, 'record object mandatory') > }; >- >-subtest "stripWhitespaceChars() tests" => sub { >- plan tests => 2; >- >- # Test default values with a MARC::Record record >- my $record = MARC::Record->new(); >- >- $record->add_fields( >- [ '001', '1234' ], >- [ '150', ' ', ' ', a => 'Test' ], >- [ '520', ' ', ' ', a => "This is\na test!\t" ], >- [ '521', ' ', ' ', a => "This is a\t test!\t" ], >- ); >- >- 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" ); >- >- my $get521a = $record->subfield('521','a'); >- is( $get521a, "This is a\t test!", "Trailing tabs are stripped while inner tabs are kept" ); >-}; >diff --git a/t/RecordProcessor.t b/t/RecordProcessor.t >index 9a0db02797..89914b3f3e 100755 >--- a/t/RecordProcessor.t >+++ b/t/RecordProcessor.t >@@ -203,4 +203,28 @@ subtest 'options() tests' => sub { > ); > }; > >+subtest "'TrimFields' filter tests" => sub { >+ >+ plan tests => 2; >+ >+ # Test default values with a MARC::Record record >+ my $record = MARC::Record->new(); >+ >+ $record->add_fields( >+ [ '001', '1234' ], >+ [ '150', ' ', ' ', a => 'Test' ], >+ [ '520', ' ', ' ', a => "This is\na test!\t" ], >+ [ '521', ' ', ' ', a => "This is a\t test!\t" ], >+ ); >+ >+ 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" ); >+ >+ my $get521a = $record->subfield('521','a'); >+ is( $get521a, "This is a\t test!", "Trailing tabs are stripped while inner tabs are kept" ); >+}; >+ > done_testing(); >-- >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