there are several spots in Zen theme where should be checked if db_is_active() before using the data base.
for instance in template.theme-registry.inc , line 91

    // Save default theme settings.
    variable_set(
      str_replace('/', '_', 'theme_' . $theme . '_settings'),
      array_merge($defaults, $settings)
    );

mentioned block code should be enclosed between

    if (db_is_active())
    {
      variable_set(...);
    }

to avoid the following kind of warnings:
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in .../includes/database.mysqli.inc on line 323

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JohnAlbin’s picture

Status: Active » Postponed (maintainer needs more info)

The warning you mention shouldn't be affected by doing (or not doing) a db_is_active() check.

Why should checking if the database is active cause a warning to disappear? I don't understand.

JohnAlbin’s picture

quicksketch’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.58 KB

Currently, Zen nor any subtheme of Zen may be used as a maintenance theme (without the database). This patch makes it so that zen doesn't use the database unnecessarily by using drupal_get_path() (which checks the system database table).

To test: set a maintenance theme in settings.php:

$conf = array(
  'maintenance_theme' => 'zen_classic',
);

Then intentionally screw up your database connection:

$db_url = 'mysql://root:root2@localhost/drupal';

Then see what your maintenance theme looks like. Without this patch, it'll choke and throw a bunch of PHP errors since drupal_get_path() will return an empty string, then the include_once will fail and the whole thing just blows up.

Apologies for the SVN patch, I figure it'll need work anyway, since zen itself should probably be able to be a base theme also, but the addition of CSS files will probably prevent that from working properly.

JohnAlbin’s picture

Title: use of db_is_active() to check for database connection before jumping in » check for db_is_active() to fix off-line maintenance page
Version: 6.x-1.0-beta3 » 6.x-1.x-dev
Component: Code » PHP Code

The real problem is drupal_get_filename is broken for themes. Please review this patch so we can get the fix into Drupal 6.12: #341140: drupal_get_filename() when database is down, does not deal with phptemplate themes

We will probably still need a workaround until then. :-p I'm not crazy about the looks of dirname(__FILE__), but it is efficient.

JohnAlbin’s picture

Title: check for db_is_active() to fix off-line maintenance page » fix off-line maintenance page since drupal_get_path('theme', 'zen') won't work
Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Needs review » Fixed
FileSize
7.72 KB

@ahrak: variable_set() saves the variable's value in two places: database and in memory. Even when the database is down, Zen still needs to save those values to memory. So its really core's fault those PHP warnings are generated. Also, the PHP warnings can be prevented by configured PHP properly to not display warnings to the screen; those types of errors should be stored in a log and not displayed on the screen.

Here's the full patch I used on Zen 6.x-2.x to get Zen and sub-themes working for db-offline maintenance pages.

JohnAlbin’s picture

Title: fix off-line maintenance page since drupal_get_path('theme', 'zen') won't work » Fix off-line maintenance page since drupal_get_path('theme', 'zen') won't work
Version: 6.x-2.x-dev » 6.x-1.x-dev
FileSize
6.68 KB

And here's the patch for Zen 6.x-1.x.

arhak’s picture

@JohnAlbin#5 yes, of course those errors should go to log
anyway, log shouldn't be that dirty when it is avoidable

Status: Fixed » Closed (fixed)

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

catch’s picture

Component: PHP Code » PHP code
Status: Closed (fixed) » Needs review
FileSize
2.13 KB

Wasn't sure whether to re-open this or not, but went for re-opening.

The file_scan_directory() here can be avoided by adding our own, patched, copy of drupal_get_filename() to zen's template.php. Atttached a patch for that, not tested yet.

catch’s picture

Status: Needs review » Postponed
FileSize
4.74 KB

Actually for a quick fix, it's better for sites to apply that core patch, and have one here postponed for the core fix.

JohnAlbin’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev

Moving to the 6.x-2.x queue so that I'm more likely to see it. It needs to be applied to both 6.x-2.x and 6.x-1.x anyway.

JohnAlbin’s picture

As an FYI, the related #705264: Allow Zen (and subthemes) to be used without a database has just been fixed.

barraponto’s picture

@JohnAlbin, then is this issue closed?

barraponto’s picture

Status: Postponed » Fixed

As far as I could test, it is fixed.
If anyone ever runs against this bug again, please re-open.

Status: Fixed » Closed (fixed)

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