Solution:
template.theme_registry.inc, line 56:
- variable_set('theme_'. $theme .'_settings', $settings);
+ if (db_is_active()) variable_set('theme_'. $theme .'_settings', $settings);
template.conditional_styles.inc, line 96:
- // Save the stylesheets for later retrieval.
- if ($conditional_styles) {
- variable_set('conditional_styles_' . $theme, $conditional_styles);
- }
- else {
- variable_del('conditional_styles_' . $theme);
- }
+ // Save the stylesheets for later retrieval.
+ if (db_is_active()) {
+ if ($conditional_styles) {
+ variable_set('conditional_styles_' . $theme, $conditional_styles);
+ }
+ else {
+ variable_del('conditional_styles_' . $theme);
+ }
+ }
Reasoning:
if the database server goes down and the Zen theme (or a subtheme based on zen) is set as the maintenance theme, then a bunch of ugly database errors appear. There may be a better way of doing this, but this works for me..
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | zen-db-inactive-705264-26.patch | 1.65 KB | tlaurent |
| #21 | zen_705264_20.patch | 416 bytes | grendzy |
| #18 | 705264-18-db-inactive.patch | 2.73 KB | johnalbin |
| #8 | zen-allow-without-database-795264-8.patch | 2.01 KB | mlncn |
| #6 | template.conditional-styles.inc_.patch | 735 bytes | jehu |
Comments
Comment #1
espirates commentedJust curious, what does the above code actually do ?
Comment #2
zenic commentedYeah, looking at it it looks more complex than it is! Sorry about that. It simply calls db_is_active() to check if a database is available before calling variable_set() or variable_del().
Both of those functions assume a database link, so if you try to use a zen based theme as your maintenance theme, it will fail while you take the database offline.
Comment #3
Garrett Albright commentedPatches should be submitted as separate patch files to best preserve formatting and such. Please see http://drupal.org/patch/create .
Comment #4
rumblewand commentedI had the same issue with the latest release of 6.x-1.1. Though I would get the WSOD after disabling the database. The above changes worked to fix it! I do not believe they have been submitted as a patch or at least not committed as of the latest dev release.
I'm new. Is there a way to check?
@zenic: Did you submit them? If not can others do so? I don't want to take credit for your work but would be willing to submit it myself because I've seen a few posts regarding the maintenance-page-offline.tpl.php with zen.
Comment #5
izmeez commentedsubscribing
Comment #6
jehu commentedI've stumbled over the same problems and i've found the same solution to use maintenance page templates from zen subthemes if an db connection error occurs (see http://drupal.org/node/195435). Patch files attached.
Comment #7
ChrisRL commentedThe patch in the description and in #6 needlessly calculate the conditional_scripts_$theme variable when it can not be set.
It would be better to add if (!db_is_active()) return array(); to the beginning of template.conditional-styles.inc.
This bug affects 7.x-3.x-dev as well.
I have marked #793482: Zen theme generates errors when used as maintenance theme as a duplicate of this bug.
Comment #8
mlncn commentedHere's a re-roll, taking ChrisRL's suggestion in #7 into account, and preventing an undefined index error on body_classes() in zen's preprocess function for the maintenance page. Yep. Zen has a preprocess function specific for the maintenance page. This is supposed to work. Marking as bug report and bumping to major.
I can roll for seven also, would rather this go into six first and then we take 7 in this issue.
benjamin, agaric
Comment #9
geodaniel commentedThe patch in #8 seems to work fine for me.
Comment #10
mlncn commentedAnyone tested if Drupal 7 has this problem?
Comment #11
barraponto@Benjamin probably, this is what i get when i run d7 with the zen theme, with the database down. http://drupalbin.com/16937
Comment #12
grendzy commentedweird, I swear zen subthemes used to work as a maintenance theme. Now I get these notices:
Notice: Undefined index: zen in drupal/includes/theme.maintenance.inc on line 61
Notice: Trying to get property of non-object in drupal/includes/theme.inc on line 427
Notice: Trying to get property of non-object in drupal/includes/theme.inc on line 431
Notice: Trying to get property of non-object in drupal/includes/theme.inc on line 431
Warning: Cannot modify header information - headers already sent by (output started at drupal/includes/theme.inc:427) in drupal/includes/common.inc on line 148
Comment #13
barraponto@grendzy: try with #8 patch.
Comment #14
grendzy commentedAh! The errors I posted in #12 are caused by a different issue. I have the Zen theme installed in the /profiles directory. Since the profile is stored in the database, when the site is offline Drupal doesn't know where to find Zen.
I was able to resolve this by adding
$conf['install_profile'] = 'myprofile';to settings.php.The patch in #8 also appears to work as intended, though I haven't reviewed the code.
Comment #15
barraponto@grendzy: shouldn't drupal define that during the installation process?
reverting to needs review since patch only works in d6, d7 still lacks testing.
Comment #16
grendzy commentedbarraponto: yes, but like all variables $conf['install_profile'] isn't defined in offline mode.
Comment #17
barraponto@grendzy: i meant "shouldn't drupal write that value in settings.php during its installation?"
Comment #18
johnalbinThe patch in #8 doesn't apply. But there's lots of good code in the comments and patches.
I just committed the attached patch.
Thanks for all your help! :-)
Fixed. http://drupalcode.org/project/zen.git/commit/c33d648
Comment #20
grendzy commentedThere seems to be a similar issue in 7.x-3.x. When using a zen sub-theme, I get this error:
I also tried with a Bartik subtheme, to test if maybe it was a core issue. The Bartik subtheme worked fine. I also tested moving the zen folder into the core /themes/ directory.
Steps to reproduce:
-- Install Drupal 7.x and Zen 7.x-3.0.
-- Make a subtheme, add $conf['maintenance_theme'] = 'mytheme'; to settings.php
-- "break" the MySQL connection by changing the password in settings.php
A backtrace shows that the exception is coming from _drupal_bootstrap_variables.
Comment #21
grendzy commentedThis patch fixes the error - though it's unclear why the error is only present for subthemes.
Comment #22
johnalbinOh, bugger. That means there's a bug in core's theme_get_setting(). Themes should be able to use that function when the db is offline because the default values for these settings are stored in the .info file. #1135112: theme_get_setting() shouldn't check db when in off-line maintenance mode
ok. I've committed this work-around for now. http://drupalcode.org/project/zen.git/commit/3bf4416
Hmm… actually, shouldn't we be checking if the database is active instead? If the site is in db online maintenance mode, it can still safely check the database for theme settings.
Comment #23
grendzy commentedtheme_get_setting is OK - it was system_rebuild_theme_data() causing the exception.
Also, from what I can tell MAINTENANCE_MODE is not the same as $conf['maintenance_mode']. The former appears to only be set during install, update, or error conditions.
Comment #24
johnalbinOh! Excellent. nevermind then, back to fixed. :-)
Also, you're right about the core issue. Thanks!
Oh, I went ahead and switched the placement of defined and theme_get_setting in that if clause. That should improve performance of the if statement for most page loads. http://drupalcode.org/project/zen.git/commit/74cf7b6
Comment #26
tlaurent commentedJust re-releasing patch #18 to make it work with Zen 6.x-1.x (1.1 and 1.2).
Comment #27
tlaurent commentedComment #28
richsky commentedI could not make my maintenance-page--offline.tpl.php to load when the database is inactive no matter what.
Is the presence of both files, maintenance-page.tpl.php & maintenance-page--offline.tpl.php in /templates with the setting.php line:
$conf['maintenance_theme'] = 'myzensubtheme';
enough to have this working?
Comment #29
barrapontoI bet there's some preprocess going on, can you post your subtheme's template.php?
Use drupalbin or gist or something like that, please.
Comment #30
johnalbinPlease don't re-open an old bug report and change it into a new support request. Thanks!