From 9dd4a768e36cb4dd299376e56e6ba3a1344ce1eb Mon Sep 17 00:00:00 2001 From: Bernardo Gonzalez Kriegel Date: Mon, 7 Jul 2014 15:30:02 -0300 Subject: [PATCH] Bug 12539: PROG/CCSR deprecation: Remove hardcoded theme from C4/Templates.pm This patch removes hardcoded 'prog' from themelanguage on C4/Templates.pm It adds a new syspref OPACFallback to hold the prefferred fallback theme for new themes with minimal changes. This does not brake CCSR if new syspref value is 'prog', using 'bootstrap' works somehow, but with strange results. To test: 1) Apply the patch 2) Run updatedatbase.pl 3) CCSR, prog & bootstrap must work as usual 4) Need to test theme/language fallback a) translate for your preferred language (xx-YY) b) enable language on opac c) go to opac, select that language d) login on opac, go to personal details e) remove koha-tmpl/opac-tmpl/bootstrap/xx-YY/modules/opac-memberentry.tt d) reload page, must load in English f) click other member options, must load on translated language (can use other pages, ccsr, prog or bootstrap) 5) Do a similar test but for a staff page, enable lang, switch to it, rm koha-tmpl/intranet-tmpl/prog/xx-YY/modules/admin/admin-home.tt, any page must be translated except for admin home. Signed-off-by: Chris Cormack --- C4/Templates.pm | 23 +++++++++------------- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 8 ++++++++ .../prog/en/modules/admin/preferences/opac.pref | 7 +++++++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/C4/Templates.pm b/C4/Templates.pm index 16eeec1..0860839 100644 --- a/C4/Templates.pm +++ b/C4/Templates.pm @@ -201,13 +201,8 @@ sub _get_template_file { my $is_intranet = $interface eq 'intranet'; my $htdocs = C4::Context->config($is_intranet ? 'intrahtdocs' : 'opachtdocs'); my ($theme, $lang, $availablethemes) = themelanguage($htdocs, $tmplbase, $interface, $query); - - # if the template doesn't exist, load the English one as a last resort my $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; - unless (-f $filename) { - $lang = 'en'; - $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; - } + return ($htdocs, $theme, $lang, $filename); } @@ -248,6 +243,7 @@ sub gettemplate { #--------------------------------------------------------------------------------------------------------- # FIXME - POD +# FIXME - Rewritten to remove hardcoded theme with minimal changes, need to be rethinked sub themelanguage { my ($htdocs, $tmpl, $interface, $query) = @_; ($query) or warn "no query in themelanguage"; @@ -255,20 +251,19 @@ sub themelanguage { # Select a language based on cookie, syspref available languages & browser my $lang = C4::Languages::getlanguage($query); - # Select theme - my $is_intranet = $interface eq 'intranet'; - my @themes = split(" ", C4::Context->preference( - $is_intranet ? "template" : "opacthemes" )); - push @themes, 'prog'; + # Get theme + my @themes = ( C4::Context->preference( ($interface eq 'intranet') ? 'template' : 'opacthemes' ) ); + my $fallback = C4::Context->preference( ($interface eq 'intranet') ? 'template' : 'OPACFallback' ); + push @themes, $fallback; # Try to find first theme for the selected language for my $theme (@themes) { if ( -e "$htdocs/$theme/$lang/modules/$tmpl" ) { - return ($theme, $lang, \@themes) + return ($theme, $lang, \@themes); } } - # Otherwise, return prog theme in English 'en' - return ('prog', 'en', \@themes); + # Otherwise, return fallback theme in English 'en' + return ($fallback, 'en', \@themes); } diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index d820b94..4ec2836 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -231,6 +231,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OPACdidyoumean',NULL,NULL,'Did you mean? configuration for the OPAC. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free'), ('OPACDisplay856uAsImage','OFF','OFF|Details|Results|Both','Display the URI in the 856u field as an image, the corresponding OPACXSLT option must be on','Choice'), ('OpacExportOptions','bibtex|dc|marcxml|marc8|utf8|marcstd|mods|ris','','Define export options available on OPAC detail page.','free'), +('OPACFallback', 'prog', 'bootstrap|prog', 'Define the fallback theme for the OPAC interface.', 'Themes'), ('OpacFavicon','','','Enter a complete URL to an image to replace the default Koha favicon on the OPAC','free'), ('OPACFineNoRenewals','100','','Fine limit above which user cannot renew books via OPAC','Integer'), ('OPACFinesTab','1','','If OFF the patron fines tab in the OPAC is disabled.','YesNo'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 531bb12..fbd7d05 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8589,6 +8589,14 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } +$DBversion = "3.17.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do("INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES + ('OPACFallback', 'prog', 'bootstrap|prog', 'Define the fallback theme for the OPAC interface.', 'Themes')"); + print "Upgrade to $DBversion done (Bug 12539 - PROG/CCSR deprecation: Remove hardcoded theme from C4/Templates.pm)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 9fe3312..cf94693 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -6,6 +6,13 @@ OPAC: choices: opac-templates - theme on the OPAC. - + - Use the + - pref: OPACFallback + choices: + bootstrap: bootstrap + prog: prog + - theme as the fallback theme on the OPAC. + - - "The OPAC is located at http://" - pref: OPACBaseURL class: url -- 1.9.1