From f59d16c083b6560522966b07bdc6c2ec19463da3 Mon Sep 17 00:00:00 2001 From: Bernardo Gonzalez Kriegel Date: Sun, 27 Apr 2014 22:29:20 -0300 Subject: [PATCH] Bug 12017 - 10 - Remove description from getLanguage This patch rewrites getLanguage function. This function is of not much use, but is rewrited to takes its data from language_rfc4646_to_iso639 table. To test: 1. Apply the patch 2. Only place that use this function is t/db_dependent/Languages.t so run the test and check that it pass 3. To compare the output pre and post patch you can run perl -e 'use C4::Languages; use Data::Dumper; $a = getLanguages(); print Dumper $a;' --- C4/Languages.pm | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/C4/Languages.pm b/C4/Languages.pm index d8c7435..296aa2e 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -47,7 +47,7 @@ BEGIN { &getLanguages &getAllLanguages ); - @EXPORT_OK = qw(getSearchLanguages getLanguages_iso getTranslatedLanguages getAllLanguages getLanguages get_bidi regex_lang_subtags language_get_description accept_language getlanguage); + @EXPORT_OK = qw(getSearchLanguages getLanguages_iso getTranslatedLanguages getAllLanguages getLanguages get_bidi regex_lang_subtags accept_language getlanguage); $DEBUG = 0; } @@ -265,43 +265,10 @@ sub getLanguages { if ($lang) { $current_language = regex_lang_subtags($lang)->{'language'}; } - my $sth = $dbh->prepare('SELECT * FROM language_subtag_registry WHERE type=\'language\''); + my $sth = $dbh->prepare('SELECT * FROM language_rfc4646_to_iso639'); $sth->execute(); while (my $language_subtag_registry = $sth->fetchrow_hashref) { - my $desc; - # check if language name is stored in current language - my $sth4= $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag =? AND lang = ?"); - $sth4->execute($language_subtag_registry->{subtag},$current_language); - while (my $language_desc = $sth4->fetchrow_hashref) { - $desc=$language_desc->{description}; - } - my $sth2= $dbh->prepare("SELECT * FROM language_descriptions LEFT JOIN language_rfc4646_to_iso639 on language_rfc4646_to_iso639.rfc4646_subtag = language_descriptions.subtag WHERE type='language' AND subtag =? AND language_descriptions.lang = ?"); - if ($desc) { - $sth2->execute($language_subtag_registry->{subtag},$current_language); - } - else { - $sth2->execute($language_subtag_registry->{subtag},$default_language); - } - my $sth3 = $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag=? AND lang=?"); - # add the correct description info - while (my $language_descriptions = $sth2->fetchrow_hashref) { - $sth3->execute($language_subtag_registry->{subtag},$language_subtag_registry->{subtag}); - my $native_description; - while (my $description = $sth3->fetchrow_hashref) { - $native_description = $description->{description}; - } - - # fill in the ISO6329 code - $language_subtag_registry->{iso639_2_code} = $language_descriptions->{iso639_2_code}; - # fill in the native description of the language, as well as the current language's translation of that if it exists - if ($native_description) { - $language_subtag_registry->{language_description} = $native_description; - $language_subtag_registry->{language_description}.=" ($language_descriptions->{description})" if $language_descriptions->{description}; - } - else { - $language_subtag_registry->{language_description} = $language_descriptions->{description}; - } - } + $language_subtag_registry->{subtag} = $language_subtag_registry->{rfc4646_subtag}; if ( !$language_list || index ( $language_list, $language_subtag_registry->{ iso639_2_code } ) >= 0) { push @languages_loop, $language_subtag_registry; } -- 1.9.1