Bug 36875: (follow-up) Modify query in translated_content

This removes the MySQLism for FIELD(..).
In this case we just want to get the non-default records in
the front. So we can just test lang=default. And prevent inserting
$lang in the expression. And so prevent execution in ORDER BY.
No longer needing the ->quote call too.

Test plan:
Run Koha/AdditionalContents.t again.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit c16f5c61849460489992977812f020ec7fa5c9f3)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Marcel de Rooy 2024-05-16 09:25:34 +00:00 committed by Fridolin Somers
parent 929becb01d
commit cf1f726616
1 changed files with 3 additions and 2 deletions

View File

@ -134,9 +134,10 @@ Return the translated content for a given language. The default is returned if n
sub translated_content {
my ( $self, $lang ) = @_;
$lang ||= 'default';
my $content = $self->translated_contents->search(
{ lang => [ 'default', ( $lang ? $lang : () ) ] },
{ ( $lang ? ( order_by => \[ "field(lang, '" . $lang . "', 'default')" ] ) : () ) }
{ lang => [ 'default', $lang ] },
{ order_by => { -asc => [ \'lang="default"', 'id' ] } }
)->next;
return $content;
}