Bug 26464: Code correction in opac-main when news_id passed

Theoretical change. If somehow the search would return more than one result, the code is wrong.

The if test can be simplified: remove scalar and >0.
We should not pass @array to one param. It would theoretically add wrong items or
trigger an odd number warning. If it is only one, it is no problem. But it is buggy.

Test plan:
Pass an existing news_id to opac-main. Item visible?
And pass a not-existing. Error message?

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Marcel de Rooy 2020-09-15 12:09:56 +00:00 committed by Jonathan Druart
parent 0310e973a4
commit 22f14a7b6d
1 changed files with 2 additions and 2 deletions

View File

@ -64,8 +64,8 @@ my @all_koha_news;
if (defined $news_id){
@all_koha_news = Koha::News->search({ idnew => $news_id, lang => { '!=', 'koha' } }); # get news that is not staff-only news
if (scalar @all_koha_news > 0){
$template->param( news_item => @all_koha_news );
if( @all_koha_news ) { # we only expect one btw
$template->param( news_item => $all_koha_news[0] );
} else {
$template->param( single_news_error => 1 );
}