Problem
When trying to set zurb_foundation or one of its sub-themes as the maintenance theme and once the db is offline, we get the following error:
Additional uncaught exception thrown while handling exception.
Original
PDOException: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. in lock_may_be_available() (line 167 of [...]/includes/lock.inc).
Additional
PDOException: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. in system_list() (line 165 of [...]/includes/module.inc).
We've located the issue at zurb_foundation_theme_registry_alter(), which tries to access the db with a call to entity_get_info().
Steps to reproduce
- In settings.php, add the following line:
$conf['maintenance_theme'] = 'zurb_foundation'; - Stop the database server
- Try to access a drupal page
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | pdoexception_when-2833423-12.patch | 2.28 KB | hongpong |
| #10 | pdoexception_when-2833423-10.patch | 2.32 KB | hongpong |
| #7 | zurb_pdoexception-2833423-7.patch | 2.24 KB | kshm |
| #5 | pdoexception_when-2833423-5.patch | 1.46 KB | icicleking |
| #3 | pdoexception_when-2833423-2.patch | 687 bytes | icicleking |
Comments
Comment #2
icicleking commentedThis is a first stab at fixing the issue. I'm running a sort of "dummy" query on the database to see if it's there. There must be a better way, but this does work. I tried wrapping the `entity_get_info()` in a `try` block, but then the theme only loads halfway (no CSS).
Comment #3
icicleking commentedComment #4
icicleking commentedComment #5
icicleking commentedI think this is a better patch, and it does start the theming of the offline maintenance page, however, as stated above, the CSS is not loaded. Which may be a core bug or maybe there's another solution. It may be an issue with core. Digging into core I've found if I
print($schema)on line 3249 in bootstrap.inc, then CSS loads properly. Obviously this is an issue to address elsewhere.Comment #6
icicleking commentedI've created an issue in core https://www.drupal.org/node/2838463#comment-11839244, but this may never be addressed. Perhaps finding another way to integrate with Display Suite is the real solution, rather than call
entity_get_infoinhook_theme_registry_alterComment #7
kshm commentedI've created a patch that checks the database connection using
Database::getConnection()instead while wrapping the remainder of the function's body in the try/catch. This causes thehook_theme_registryto return cleanly when there is no database connection without any calls toentity_get_info()and still load the proper style sheets without any exceptions.Comment #8
kshm commentedComment #9
hongpong commentedThis seems like a good idea, is it possible to get a test that confirms this works? Thank you.
Comment #10
hongpong commentedTested it and it works. Compacted the line breaks and added a comment. Thank you!
Comment #12
hongpong commentedHere is the patch for 7.x-4.x to make it work more gracefully on maintenance mode without a database available.
Comment #14
hongpong commentedThank you for figuring this out!