I have an external PHP script that bootstraps Drupal, and that lives in a subfolder of my Drupal install dir.

After bootstrapping, this script runs some functionality that depends on file_scan_directory() (lives in includes/file.inc). I discovered that this function doesn't currently work if called from a script that lives outside of the Drupal root, as there are several places where it should be (but is not) prepending DRUPAL_ROOT to the file path.

This is a similar bug to #1891802: Need DRUPAL_ROOT when rendering CSS include links

Attached patch fixes this, by doing the following:

- Appends DRUPAL_ROOT to the directory path before calling is_dir() and opendir() (unless it's a stream wrapper URL, or is already an absolute file path)

- Appends DRUPAL_ROOT to the file URI (unless it's a stream wrapper URL, or is already an absolute file path)

- Removes DRUPAL_ROOT from the $file->uri values that get returned by this function, in order to keep this function's return value the same as it is currently (i.e. with values relative to Drupal root).

CommentFileSizeAuthor
file_scan_directory_drupalroot.patch1.78 KBJaza
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jaza’s picture

Status: Needs review » Needs work

New meta-issue for wider discussion of this issue: #1928072: Bootstrapping Drupal from outside the Drupal root directory