Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#10 | 317417-zen.patch | 4.74 KB | catch |
#9 | zen_get_filename.patch | 2.13 KB | catch |
#6 | maintenance-page-317417-6.patch | 6.68 KB | JohnAlbin |
#5 | maintenance-page-317417-5.patch | 7.72 KB | JohnAlbin |
#3 | zen-maintenance.patch | 1.58 KB | quicksketch |
Comments
Comment #1
JohnAlbinThe 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.
Comment #2
JohnAlbinAlso, your issue might be fixed by #275832: hook_theme implementation breaks maintenance page when database is down
Comment #3
quicksketchCurrently, 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:
Then intentionally screw up your database connection:
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.
Comment #4
JohnAlbinThe 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.Comment #5
JohnAlbin@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.
Comment #6
JohnAlbinAnd here's the patch for Zen 6.x-1.x.
Comment #7
arhak CreditAttribution: arhak commented@JohnAlbin#5 yes, of course those errors should go to log
anyway, log shouldn't be that dirty when it is avoidable
Comment #9
catchWasn'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.
Comment #10
catchActually for a quick fix, it's better for sites to apply that core patch, and have one here postponed for the core fix.
Comment #11
JohnAlbinMoving 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.
Comment #12
JohnAlbinAs an FYI, the related #705264: Allow Zen (and subthemes) to be used without a database has just been fixed.
Comment #13
barraponto CreditAttribution: barraponto commented@JohnAlbin, then is this issue closed?
Comment #14
barraponto CreditAttribution: barraponto commentedAs far as I could test, it is fixed.
If anyone ever runs against this bug again, please re-open.