Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove drush_locate_root #2788

Merged
merged 2 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions includes/environment.inc
Original file line number Diff line number Diff line change
Expand Up @@ -317,33 +317,6 @@ function drush_conf_path($server_uri, $require_settings = TRUE) {
return $conf;
}

/**
* Exhaustive depth-first search to try and locate the Drupal root directory.
* This makes it possible to run Drush from a subdirectory of the drupal root.
*
* @param
* Search start path. Defaults to current working directory.
* @return
* A path to drupal root, or FALSE if not found.
*/
function drush_locate_root($start_path = NULL) {
$drupal_root = FALSE;

$start_path = empty($start_path) ? drush_cwd() : $start_path;

$drupalFinder = new DrupalFinder();
if (!$drupalFinder->locateRoot($start_path)) {
// echo ' Drush must be executed within a Drupal site.'. PHP_EOL;
// exit(1);
}

// $composerRoot = $drupalFinder->getComposerRoot();
$drupalRoot = $drupalFinder->getDrupalRoot();
// chdir($drupalRoot);

return $drupalRoot;
}

/**
* Checks whether given path qualifies as a Drupal root.
*
Expand Down
8 changes: 1 addition & 7 deletions includes/preflight.inc
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,7 @@ function drush_preflight() {
*/
function drush_preflight_root() {
$root = drush_get_option('root');
if (!isset($root)) {
$root = drush_locate_root();
}
if ($root) {
$root = realpath($root);
}
Drush::bootstrapManager()->setRoot($root);
Drush::bootstrapManager()->locateRoot($root);

// Load the config options from Drupal's /drush, ../drush, and sites/all/drush directories,
// even prior to bootstrapping the root.
Expand Down
11 changes: 8 additions & 3 deletions includes/sitealias.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1443,8 +1443,10 @@ function _drush_find_local_sites_in_sites_folder($a_drupal_root) {
// First we'll resolve the realpath of the settings.php file,
// so that we get the correct drupal root when symlinks are in use.
$real_sitedir = dirname(realpath($filename));
$real_root = drush_locate_root($filename);
if ($real_root !== FALSE) {

$drupalFinder = new DrupalFinder();
if ($drupalFinder->locateRoot($real_sitedir)) {
$real_root = $drupalFinder->getDrupalRoot();
$a_drupal_site = $real_root . '#' . basename($real_sitedir);
}
// If the symlink points to some folder outside of any drupal
Expand Down Expand Up @@ -1556,7 +1558,10 @@ function drush_sitealias_build_record_from_settings_file($site_settings_file, $a

if (file_exists($site_settings_file)) {
if (!isset($drupal_root)) {
$drupal_root = drush_locate_root($site_settings_file);
$drupalFinder = new DrupalFinder();
if ($drupalFinder->locateRoot(dirname($site_settings_file))) {
$drupal_root = $drupalFinder->getDrupalRoot();
}
}

$alias_record['root'] = $drupal_root;
Expand Down
30 changes: 26 additions & 4 deletions src/Boot/BootstrapManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drush\Boot;

use DrupalFinder\DrupalFinder;
use Drush\Drush;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerAwareInterface;
Expand All @@ -11,6 +12,11 @@ class BootstrapManager implements LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* @var DrupalFinder
*/
protected $drupalFinder;

/**
* @var \Drush\Boot\Boot[]
*/
Expand Down Expand Up @@ -46,6 +52,7 @@ class BootstrapManager implements LoggerAwareInterface
public function __construct(Boot $default)
{
$this->defaultBootstrapObject = $default;
$this->drupalFinder = new DrupalFinder();
}

/**
Expand All @@ -66,13 +73,28 @@ public function add($candidateList)
*/
public function getRoot()
{
return $this->root;
return $this->drupalFinder->getDrupalRoot();
}

public function setRoot($root)
/**
* Return the composer root for the selected Drupal site.
*/
public function getComposerRoot()
{
return $this->drupalFinder->getComposerRoot();
}

public function locateRoot($root, $start_path = NULL)
{
// TODO: Throw if we already bootstrapped a framework?
$this->root = $root;

if (!isset($root)) {
$root = drush_cwd();
}
if (!$this->drupalFinder->locateRoot($root)) {
// echo ' Drush must be executed within a Drupal site.'. PHP_EOL;
// exit(1);
}
}

/**
Expand Down Expand Up @@ -133,7 +155,7 @@ protected function selectBootstrapClass()
{
// Once we have selected a Drupal root, we will reduce our bootstrap
// candidates down to just the one used to select this site root.
$bootstrap = $this->bootstrapObjectForRoot($this->root);
$bootstrap = $this->bootstrapObjectForRoot($this->getRoot());
// If we have not found a bootstrap class by this point,
// then return our default bootstrap object. The default bootstrap object
// should pass through all calls without doing anything that
Expand Down