Last active
December 19, 2015 00:09
-
-
Save zerolab/5866263 to your computer and use it in GitHub Desktop.
Prevent variable_init from returning an empty array.
@see https://github.com/pressflow/6/pull/37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc | |
index 8c5b294..2bf283a 100644 | |
--- a/includes/bootstrap.inc | |
+++ b/includes/bootstrap.inc | |
@@ -568,6 +568,13 @@ function variable_init($conf = array(), $regenerate = FALSE, $recursion_depth = | |
else { | |
if (defined('MAINTENANCE_MODE') || lock_acquire('variable_cache_regenerate')) { | |
$result = db_query('SELECT * FROM {variable}'); | |
+ // Exit here if the database went away. Do not want to pollute the cache | |
+ // with bad data. This request isn't going to end well anyway; end it | |
+ // eairly. | |
+ if ($result === FALSE) { | |
+ // This function calls exit. | |
+ _db_error_page(); | |
+ } | |
while ($variable = db_fetch_object($result)) { | |
$variables[$variable->name] = unserialize($variable->value); | |
} | |
@@ -588,7 +595,19 @@ function variable_init($conf = array(), $regenerate = FALSE, $recursion_depth = | |
return variable_init($conf, $regenerate, $recursion_depth); | |
} | |
- $variables = array(); | |
+ // If the recursion_depth hit the limit, assume we aren't going to get it | |
+ // from the cache or the lock will be released any time soon. Give up and | |
+ // get variables from the database. | |
+ $result = db_query('SELECT * FROM {variable}'); | |
+ // Exit here if the database went away. Do not want to pollute the cache | |
+ // with bad data. This request isn't going to end well. | |
+ if ($result === FALSE) { | |
+ // This function calls exit. | |
+ _db_error_page(); | |
+ } | |
+ while ($variable = db_fetch_object($result)) { | |
+ $variables[$variable->name] = unserialize($variable->value); | |
+ } | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment