From 7ebf6dc6f760d2f93b45e57647cc31f6f6b1debc Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 11 Nov 2024 05:47:06 +0000 Subject: [PATCH] Bug 38270: Tidy Signed-off-by: Martin Renvoize --- Koha/SearchEngine/Elasticsearch.pm | 16 ++++++++-------- Koha/SearchEngine/Elasticsearch/Search.pm | 20 ++++++++------------ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index ee5d9b66143..a403fb337df 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -806,13 +806,13 @@ sub marc_records_to_documents { # TODO: Perhaps should check if $records_document non empty, but really should never be the case $record->encoding('UTF-8'); - if ($marcformat_syspref eq 'ARRAY') { + if ( $marcformat_syspref eq 'ARRAY' ) { $record_document->{'marc_data_array'} = $self->_marc_to_array($record); $record_document->{'marc_format'} = 'ARRAY'; - } elsif ($marcformat_syspref eq 'MARCXML'){ + } elsif ( $marcformat_syspref eq 'MARCXML' ) { $record_document->{'marc_data'} = $record->as_xml_record($marcflavour); $record_document->{'marc_format'} = 'MARCXML'; - } elsif ($marcformat_syspref eq 'MARCXML_COMPRESSED'){ + } elsif ( $marcformat_syspref eq 'MARCXML_COMPRESSED' ) { my $deflate = deflateInit( -Level => Z_BEST_COMPRESSION ); my $output = ""; if ($deflate) { @@ -833,19 +833,19 @@ sub marc_records_to_documents { local $SIG{__WARN__} = sub { push @warnings, $_[0]; }; - $record_document->{'marc_data'} = encode_base64(encode('UTF-8', $record->as_usmarc())); + $record_document->{'marc_data'} = encode_base64( encode( 'UTF-8', $record->as_usmarc() ) ); } if (@warnings) { + # Suppress warnings if record length exceeded - unless (substr($record->leader(), 0, 5) eq '99999') { + unless ( substr( $record->leader(), 0, 5 ) eq '99999' ) { foreach my $warning (@warnings) { carp $warning; } } - $record_document->{'marc_data'} = $record->as_xml_record($marcflavour); + $record_document->{'marc_data'} = $record->as_xml_record($marcflavour); $record_document->{'marc_format'} = 'MARCXML'; - } - else { + } else { $record_document->{'marc_format'} = 'base64ISO2709'; } } diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index fbaefd1b662..2bb82f1c0fb 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -408,21 +408,17 @@ sub decode_record_from_result { # Result is passed in as array, will get flattened # and first element will be $result my ( $self, $result ) = @_; - if ($result->{marc_format} eq 'base64ISO2709') { - return MARC::Record->new_from_usmarc(decode_base64($result->{marc_data})); - } - elsif ($result->{marc_format} eq 'MARCXML') { - return MARC::Record->new_from_xml($result->{marc_data}, 'UTF-8', uc C4::Context->preference('marcflavour')); - } - elsif ($result->{marc_format} eq 'MARCXML_COMPRESSED') { + if ( $result->{marc_format} eq 'base64ISO2709' ) { + return MARC::Record->new_from_usmarc( decode_base64( $result->{marc_data} ) ); + } elsif ( $result->{marc_format} eq 'MARCXML' ) { + return MARC::Record->new_from_xml( $result->{marc_data}, 'UTF-8', uc C4::Context->preference('marcflavour') ); + } elsif ( $result->{marc_format} eq 'MARCXML_COMPRESSED' ) { my $inflate = inflateInit(); my $marcxml = $inflate->inflate( decode_base64( $result->{marc_data} ) ); return MARC::Record->new_from_xml( $marcxml, 'UTF-8', uc C4::Context->preference('marcflavour') ); - } - elsif ($result->{marc_format} eq 'ARRAY') { - return $self->_array_to_marc($result->{marc_data_array}); - } - else { + } elsif ( $result->{marc_format} eq 'ARRAY' ) { + return $self->_array_to_marc( $result->{marc_data_array} ); + } else { Koha::Exceptions::Elasticsearch->throw("Missing marc_format field in Elasticsearch result"); } } -- 2.47.0