From d9783fe3fa7d1b9706e9d188421b954a36c357b8 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 30 Mar 2022 12:53:43 +0100 Subject: [PATCH] Bug 24975: Fix db_t The query here is difficult.. I wanted to return FULL LEFT JOIN, but filtering on the joined data (l10n_targets.language) means we drop the l10n_source rows where there are no corresponding l10n_targets with language code. I tried setting `l10n_targets.language => [ $language, undef ]` to include null values, but that doesn't work either. I then tried coming up with a correlate subquery instead of the join and couldn't get dbic to play nicely there either. As such, I've fallen back to multiple queries over the relationship.. I'm sure we can do better... but this works for now. --- Koha/I18N.pm | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Koha/I18N.pm b/Koha/I18N.pm index d905f4c456..5502c9f076 100644 --- a/Koha/I18N.pm +++ b/Koha/I18N.pm @@ -250,22 +250,21 @@ sub db_t { my $translations = $cache->get_from_cache($cache_key); unless ($translations) { my $schema = Koha::Database->new->schema; - my $rs = $schema->resultset('L10nSource'); + my $source_rs = $schema->resultset('L10nSource'); - my @targets = $rs->search( + my $sources = $source_rs->search( { - 'group' => $group, - 'l10n_targets.language' => $language, - }, - { - join => 'l10n_targets', - prefetch => 'l10n_targets', - result_class => 'DBIx::Class::ResultClass::HashRefInflator', - }, + 'group' => $group + } ); - $translations = - { map { $_->{key} => $_->{l10n_targets}->[0]{translation} //= $_->{text} } - @targets }; + while ( my $source = $sources->next ) { + my $translation = + $source->l10n_targets->search( { language => $language } ); + $translations->{ $source->key } = + $translation->count + ? $translation->first->translation + : $source->text; + } $cache->set_in_cache($cache_key, $translations); } -- 2.20.1