Right now - alomst every place we are including a file we have to concat DRUPAL_ROOT.

It would be much better if this was just included at a lower level in drupal_system_listing(), etc.

possible like:

index fc8acd1..853547d 100644
--- includes/common.inc
+++ includes/common.inc
@@ -3740,7 +3740,7 @@ function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1)
 
   // 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)));
+    $files = array_merge($files, file_scan_directory(DRUPAL_ROOT . '/' . $dir, $mask, array('key' => $key, 'min_depth' => $min_depth)));
   }

Comments

gaelicWizard’s picture

+q

zroger’s picture

Category: task » bug

Changing this to a bug report. When bootstrapping Drupal from outside of DRUPAL_ROOT, the relative paths to the search directories cause nothing to be found.

Here's a script to reproduce:

/**
 * @file drupal-system-listing.php
 */

define('DRUPAL_ROOT', getcwd() . '/drupal-7');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_override_server_variables();
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// cwd != DRUPAL_ROOT
$modules = system_rebuild_module_data();
printf("- Outside of DRUPAL_ROOT, found %d modules.\n", count($modules));

// Do the same thing from with cwd == DRUPAL_ROOT.
chdir(DRUPAL_ROOT);
drupal_static_reset();
$modules = system_rebuild_module_data();
printf("- Inside of DRUPAL_ROOT, found %d modules.\n", count($modules));

Put this script in the parent directory of your Drupal root. My drupal root in this test is named drupal-7. Running it from that same directory gives me the following output.

$ php drupal-system-listing.php 
- Outside of DRUPAL_ROOT, found 0 modules.
- Inside of DRUPAL_ROOT, found 177 modules.

I personally consider this a bug with drupal_system_listing, since from what I understand DRUPAL_ROOT was introduced to eliminate any dependency on the current working directory. If this is not a bug, then at a minimum the docs for drupal_bootstrap should be updated to include changing directories before bootstrapping.

cameron tod’s picture

For reference, here's the original issue where system_listing was replaced with drupal_system_listing : http://drupal.org/node/88287

And where DRUPAL_ROOT was added: http://drupal.org/node/259623

cameron tod’s picture

pwolainin, by putting DRUPAL_ROOT into drupal_system_listing(), how do you propose changing the way files are included?

I'm seeing 238 uses of the `require_once DRUPAL_ROOT . '/file.inc'` approach with a egrep -rn "(include_once|require_once) DRUPAL_ROOT" . | grep -v "*" | wc -l on the 7.x branch.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.