summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-04 04:02:26 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-04 04:02:26 +0000
commit65a1528f0529306e3a7a84208c435cfb7cebe3a5 (patch)
tree719c61a1c9566df53e80735190f353c0222872a8 /includes
parenta4733d86c9c969a036d0705700351bccc9bc7f56 (diff)
downloadbrdo-65a1528f0529306e3a7a84208c435cfb7cebe3a5.tar.gz
brdo-65a1528f0529306e3a7a84208c435cfb7cebe3a5.tar.bz2
#341140 by JohnAlbin and chx: Allow drupal_get_path() to be used even when database is down.
Diffstat (limited to 'includes')
-rw-r--r--includes/bootstrap.inc41
-rw-r--r--includes/common.inc6
2 files changed, 36 insertions, 11 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 84dba86f4..7164c40f5 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -635,20 +635,39 @@ function drupal_get_filename($type, $name, $filename = NULL) {
// the database. This is required because this function is called both
// before we have a database connection (i.e. during installation) and
// when a database connection fails.
- elseif (db_is_active() && (($file = db_query("SELECT filename FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchField()) && file_exists($file))) {
- $files[$type][$name] = $file;
- }
else {
- // Fallback to searching the filesystem if the database connection is
- // not established or the requested file is not found.
- $config = conf_path();
- $dir = (($type == 'theme_engine') ? 'themes/engines' : "${type}s");
- $file = (($type == 'theme_engine') ? "$name.engine" : "$name.$type");
-
- foreach (array("$config/$dir/$file", "$config/$dir/$name/$file", "$dir/$file", "$dir/$name/$file") as $file) {
+ try {
+ $file = db_query("SELECT filename FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchField();
if (file_exists($file)) {
$files[$type][$name] = $file;
- break;
+ }
+ }
+ catch (PDOException $e) {
+ // The database table may not exist because Drupal is not yet installed,
+ // or the database might be down. We have a fallback for this case so we
+ // hide the error completely.
+ }
+ // Fallback to searching the filesystem if the database could not find the
+ // file or the file returned by the database is not found.
+ if (!isset($files[$type][$name])) {
+ // We have a consistent directory naming: modules, themes...
+ $dir = $type . 's';
+ if ($type == 'theme_engine') {
+ $dir = 'themes/engines';
+ $mask = "/$name\.engine$/";
+ }
+ elseif ($type == 'theme') {
+ $mask = "/$name\.info$/";
+ }
+ else {
+ $mask = "/$name\.$type$/";
+ }
+
+ if (drupal_function_exists('drupal_system_listing')) {
+ $matches = drupal_system_listing($mask, $dir, 'name', 0);
+ if (!empty($matches[$name]->filepath)) {
+ $files[$type][$name] = $matches[$name]->filepath;
+ }
}
}
}
diff --git a/includes/common.inc b/includes/common.inc
index 6715fe792..15104c340 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -3672,6 +3672,12 @@ function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1)
$searchdir[] = "$config/$directory";
}
+ // If the database is not available, we can't use drupal_function_exists(), so
+ // we load the file_scan_directory function definition manually.
+ if (!function_exists('file_scan_directory')) {
+ require_once DRUPAL_ROOT . '/includes/file.inc';
+ }
+
// Get current list of items
foreach ($searchdir as $dir) {
$files = array_merge($files, file_scan_directory($dir, $mask, array('key' => $key, 'min_depth' => $min_depth)));