Solution:, line 56:
- variable_set('theme_'. $theme .'_settings', $settings);
+ if (db_is_active()) variable_set('theme_'. $theme .'_settings', $settings);, 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);
+ }
+ }

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..

Members fund testing for the Drupal project. Drupal Association Learn more


espirates’s picture

Just curious, what does the above code actually do ?

zenic’s picture

Yeah, 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.

Garrett Albright’s picture

Category: bug » feature
Status: Active » Needs work

Patches should be submitted as separate patch files to best preserve formatting and such. Please see .

rumblewand’s picture

I 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.

izmeez’s picture


Jehu’s picture

I'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 Patch files attached.

ChrisRL’s picture

The 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

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.

mlncn’s picture

Version: 6.x-1.1 » 6.x-2.x-dev
Category: feature » bug
Priority: Normal » Major
Status: Needs work » Needs review
2.01 KB

Here'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

geodaniel’s picture

The patch in #8 seems to work fine for me.

mlncn’s picture

Status: Needs review » Reviewed & tested by the community

Anyone tested if Drupal 7 has this problem?

barraponto’s picture

@Benjamin probably, this is what i get when i run d7 with the zen theme, with the database down.

grendzy’s picture

weird, I swear zen subthemes used to work as a maintenance theme. Now I get these notices:

Notice: Undefined index: zen in drupal/includes/ on line 61
Notice: Trying to get property of non-object in drupal/includes/ on line 427
Notice: Trying to get property of non-object in drupal/includes/ on line 431
Notice: Trying to get property of non-object in drupal/includes/ on line 431
Warning: Cannot modify header information - headers already sent by (output started at drupal/includes/ in drupal/includes/ on line 148

barraponto’s picture

@grendzy: try with #8 patch.

grendzy’s picture

Component: PHP Code » layout.css

Ah! 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.

barraponto’s picture

Component: layout.css » PHP code
Status: Reviewed & tested by the community » Needs review

@grendzy: shouldn't drupal define that during the installation process?

reverting to needs review since patch only works in d6, d7 still lacks testing.

grendzy’s picture

barraponto: yes, but like all variables $conf['install_profile'] isn't defined in offline mode.

barraponto’s picture

@grendzy: i meant "shouldn't drupal write that value in settings.php during its installation?"

JohnAlbin’s picture

Status: Needs review » Fixed
2.73 KB

The 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! :-)


Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

grendzy’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Status: Closed (fixed) » Active

There seems to be a similar issue in 7.x-3.x. When using a zen sub-theme, I get this error:

Additional uncaught exception thrown while handling exception.


PDOException: SQLSTATE[42000] [1044] Access denied for user 'drupal7'@'localhost' to database 'drupal7x' in lock_may_be_available() (line 164 of /Users/dylan/Sites/7-drupal/drupal/includes/


PDOException: SQLSTATE[42000] [1044] Access denied for user 'drupal7'@'localhost' to database 'drupal7x' in system_get_files_database() (line 2180 of /Users/dylan/Sites/7-drupal/drupal/modules/system/system.module).

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.

grendzy’s picture

Status: Active » Needs review
416 bytes

This patch fixes the error - though it's unclear why the error is only present for subthemes.

JohnAlbin’s picture

Status: Needs review » Needs work

Oh, 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.

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.

grendzy’s picture

theme_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.

JohnAlbin’s picture

Status: Needs work » Fixed

Also, from what I can tell MAINTENANCE_MODE is not the same as $conf['maintenance_mode'].

Oh! 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

tlaurent’s picture

Component: PHP code » layout.css
1.65 KB

Just re-releasing patch #18 to make it work with Zen 6.x-1.x (1.1 and 1.2).

tlaurent’s picture

Component: layout.css » PHP/JS code
richsky’s picture

Version: 7.x-3.x-dev » 7.x-5.1
Priority: Major » Minor
Status: Closed (fixed) » Active
Issue tags: +offline, +maintenance mode, +7.5.1, +db_inactive

I 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?

barraponto’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

I bet there's some preprocess going on, can you post your subtheme's template.php?
Use drupalbin or gist or something like that, please.

JohnAlbin’s picture

Version: 7.x-5.1 » 7.x-3.x-dev
Category: support » bug
Priority: Minor » Major
Status: Postponed (maintainer needs more info) » Closed (fixed)

Please don't re-open an old bug report and change it into a new support request. Thanks!