summaryrefslogtreecommitdiff
authorTomas Cohen Arazi <tomascohen@gmail.com>2014-10-31 14:00:22 (GMT)
committer Tomas Cohen Arazi <tomascohen@gmail.com>2014-11-01 12:11:07 (GMT)
commita4a2159aad6d7276fc7efb9abb24830f7f473102 (patch) (unidiff)
tree99b2a0e6a7b22c661c5ebcfb5d99acd30e6c53af
parentd4a7fa85807301ceb5268817d035235bdcf313a3 (diff)
Bug 13169: C4::Templates::themelanguage fails if the DB is not populated
With the aim to remove hardcoded themes the C4::Templates::themelanguage got dependent on the DB being populated. This patch reintroduced the hardcoded defaults as a last resort. To test: - Do a fresh install, clean your browser's cache, empty DB - Open the staff interface => FAIL: A "Software error" screen shows "Template process failed: file error..." - Apply the patch - Reload => SUCCESS: The webinstaller prompts for login correctly. - Sign off :-D Regards Signed-off-by: Nick Clemens <nick@quecheelibrary.org> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--C4/Templates.pm40
1 files changed, 31 insertions, 9 deletions
diff --git a/C4/Templates.pm b/C4/Templates.pm
index 7d09a58..3a3a65c 100644
--- a/C4/Templates.pm
+++ b/C4/Templates.pm
@@ -4,7 +4,7 @@ use strict;
4use warnings; 4use warnings;
5use Carp; 5use Carp;
6use CGI; 6use CGI;
7use List::MoreUtils qw/any/; 7use List::MoreUtils qw/any uniq/;
8 8
9# Copyright 2009 Chris Cormack and The Koha Dev Team 9# Copyright 2009 Chris Cormack and The Koha Dev Team
10# 10#
@@ -250,9 +250,20 @@ sub gettemplate {
250} 250}
251 251
252 252
253#--------------------------------------------------------------------------------------------------------- 253=head2 themelanguage
254# FIXME - POD 254
255# FIXME - Rewritten to remove hardcoded theme with minimal changes, need to be rethinked 255 my ($theme,$lang,\@themes) = themelanguage($htdocs,$tmpl,$interface,query);
256
257This function returns the theme and language to be used for rendering the UI.
258It also returns the list of themes that should be applied as a fallback. This is
259used for the theme overlay feature (i.e. if a file doesn't exist on the requested
260theme, fallback to the configured fallback).
261
262Important: this function is used on the webinstaller too, so always consider
263the use case where the DB is not populated already when rewriting/fixing.
264
265=cut
266
256sub themelanguage { 267sub themelanguage {
257 my ($htdocs, $tmpl, $interface, $query) = @_; 268 my ($htdocs, $tmpl, $interface, $query) = @_;
258 ($query) or warn "no query in themelanguage"; 269 ($query) or warn "no query in themelanguage";
@@ -261,20 +272,31 @@ sub themelanguage {
261 my $lang = C4::Languages::getlanguage($query); 272 my $lang = C4::Languages::getlanguage($query);
262 273
263 # Get theme 274 # Get theme
264 my @themes = ( C4::Context->preference( ($interface eq 'intranet') ? 'template' : 'opacthemes' ) ); 275 my @themes;
265 my $fallback = C4::Context->preference( ($interface eq 'intranet') ? 'template' : 'OPACFallback' ); 276 my $theme_syspref = ($interface eq 'intranet') ? 'template' : 'opacthemes';
266 push @themes, $fallback; 277 my $fallback_syspref = ($interface eq 'intranet') ? 'template' : 'OPACFallback';
278 # Yeah, hardcoded, last resort if the DB is not populated
279 my $hardcoded_theme = ($interface eq 'intranet') ? 'prog' : 'bootstrap';
280
281 # Configured theme is the first one
282 push @themes, C4::Context->preference( $theme_syspref )
283 if C4::Context->preference( $theme_syspref );
284 # Configured fallback next
285 push @themes, C4::Context->preference( $fallback_syspref )
286 if C4::Context->preference( $fallback_syspref );
287 # The hardcoded fallback theme is the last one
288 push @themes, $hardcoded_theme;
267 289
268 # Try to find first theme for the selected theme/lang, then for fallback/lang 290 # Try to find first theme for the selected theme/lang, then for fallback/lang
269 for my $theme (@themes) { 291 for my $theme (@themes) {
270 if ( -e "$htdocs/$theme/$lang/modules/$tmpl" ) { 292 if ( -e "$htdocs/$theme/$lang/modules/$tmpl" ) {
271 return ($theme, $lang, \@themes); 293 return ( $theme, $lang, uniq( \@themes ) );
272 } 294 }
273 } 295 }
274 # Otherwise return theme/'en', last resort fallback/'en' 296 # Otherwise return theme/'en', last resort fallback/'en'
275 for my $theme (@themes) { 297 for my $theme (@themes) {
276 if ( -e "$htdocs/$theme/en/modules/$tmpl" ) { 298 if ( -e "$htdocs/$theme/en/modules/$tmpl" ) {
277 return ($theme, 'en', \@themes); 299 return ( $theme, 'en', uniq( \@themes ) );
278 } 300 }
279 } 301 }
280} 302}