3 namespace Drush\Preflight;
5 use Webmozart\PathUtil\Path;
8 * RedispatchToSiteLocal forces an `exec` to the site-local Drush if it
9 * exist. We must do this super-early, before loading Drupal's autoload
10 * file. If we do not, we will crash unless the site-local Drush and the
11 * global Drush are using the exact same versions of all dependencies, which
12 * will rarely line up sufficiently to prevent problems.
14 class RedispatchToSiteLocal
18 * Determine if a local redispatch is needed, and do so if it is.
20 * @param array $argv The commandline arguments
21 * @param string $root The selected site root or false if none
22 * @param string $vendor The path to the vendor directory
23 * @param PreflightLog $preflightLog A basic logger.
26 * True if redispatch occurred, and was returned successfully.
28 public static function redispatchIfSiteLocalDrush($argv, $root, $vendor, PreflightLog $preflightLog)
31 // Try to find the site-local Drush. If there is none, we are done.
32 $siteLocalDrush = static::findSiteLocalDrush($root);
33 if (!$siteLocalDrush) {
37 // If the site-local Drush is us, then we do not need to redispatch.
38 if (Path::isBasePath($vendor, $siteLocalDrush)) {
42 // Do another special check to detect symlinked Drush folder similar
43 // to what the SUT sets up for Drush functional tests.
44 if (dirname($vendor) == dirname($siteLocalDrush)) {
49 $command = $siteLocalDrush;
50 $preflightLog->log(dt('Redispatch to site-local Drush: !cmd.', ['!cmd' => $command]));
54 return escapeshellarg($item);
58 $command .= ' ' . implode(' ', $args);
59 passthru($command, $status);
64 * Find a site-local Drush, if there is one in the selected site's
67 * @param string $root The selected site root
69 protected static function findSiteLocalDrush($root)
72 "$root/vendor/drush/drush/drush",
73 dirname($root) . '/vendor/drush/drush/drush',
75 foreach ($candidates as $candidate) {
76 if (file_exists($candidate)) {