/** * Class constructor. * * @param CommandBase $command * The current instance of the command. */ public function __construct(CommandBase $command) { $this->command = $command; // Determine if the "path" option has been set. $this->path = drush_get_option('path'); if ($this->path && !file_exists($this->path)) { return drush_set_error('DRUSH_LWG_INVALID_PATH', dt("The specified project path does not exist:\n!path", array('!path' => $this->path))); } else { if (!$this->path) { $this->path = drush_cwd(); } } // Ensure the path is writable. if (!is_writable($this->path)) { return drush_set_error('DRUSH_LWG_PATH_NOT_WRITABLE', dt("The specified project path is not writable:\n!path", array('!path' => $this->path))); } foreach (drush_scan_directory($this->path, '/\\.info(\\.yml)?/') as $file) { if ($this->info = drush_drupal_parse_info_file($file->filename)) { $this->name = $file->name; break; } } if (!$this->getInfo('name')) { return drush_set_error('DRUSH_LWG_NOT_PROJECT', dt('Project info not found. Please navigate to a valid project directory or specify one with the --path option.')); } // Indicate that this is a valid project. $this->valid = TRUE; }
/** * Like Backdrop conf_path(), but searching from beneath. * Allows proper site uri detection in site sub-directories. * * Essentially looks for a settings.php file. Drush uses this * function to find a usable site based on the user's current * working directory. * * @param string * Search starting path. Defaults to current working directory. * * @return * Current site path (folder containing settings.php) or FALSE if not found. */ protected function site_path($path = NULL) { $site_path = FALSE; $path = empty($path) ? drush_cwd() : $path; // Check the current path. if (file_exists($path . '/settings.php')) { $site_path = $path; } else { // Move up dir by dir and check each. Stop if we get to a Backdrop root. // We don't care if it is DRUSH_SELECTED_BACKDROP_ROOT or some other root. while (($path = _drush_shift_path_up($path)) && !drush_valid_root($path)) { if (file_exists($path . '/settings.php')) { $site_path = $path; break; } } } $site_root = drush_get_context('DRUSH_SELECTED_BACKDROP_ROOT'); if (file_exists($site_root . '/sites/sites.php')) { $sites = array(); // This will overwrite $sites with the desired mappings. include $site_root . '/sites/sites.php'; // We do a reverse lookup here to determine the URL given the site key. if ($match = array_search($site_path, $sites)) { $site_path = $match; } } // Last resort: try from site root if (!$site_path) { if ($site_root) { if (file_exists($site_root . '/settings.php')) { $site_path = $site_root; } } } return $site_path; }