Bug 31383: Check lang and use right column in search_for_display

We should check if $lang equals default before looking for translated
contents.
And note that @translated_content_id contains additional_content_id
not id, so cannot be used in the last query.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2023-06-22 08:41:41 +00:00 committed by Tomas Cohen Arazi
parent 772337f525
commit 2e773a33c3
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -87,9 +87,9 @@ sub search_for_display {
my $contents = $self->SUPER::search( $search_params, { order_by => 'number' } );
my @all_content_id = $contents->get_column('id');
my @translated_content_id;
if ( $params->{lang} ) {
my $translated_contents = Koha::AdditionalContentsLocalizations->search(
my ( $translated_contents, @translated_content_id );
if ( $params->{lang} && $params->{lang} ne 'default' ) {
$translated_contents = Koha::AdditionalContentsLocalizations->search(
{
additional_content_id => [$contents->get_column('id')],
lang => $params->{lang},
@ -107,7 +107,7 @@ sub search_for_display {
return Koha::AdditionalContentsLocalizations->search(
{
id => [@translated_content_id, $default_contents->get_column('id')]
id => [ $translated_contents ? $translated_contents->get_column('id') : (), $default_contents->get_column('id') ]
},
);