/** * Check if the given command belongs to a disabled module. * * @return array * Array with a command-like bootstrap error or FALSE if Drupal was not * bootstrapped fully or the command does not belong to a disabled module. */ function drush_command_belongs_to_disabled_module() { if (drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)) { _drush_find_commandfiles(DRUSH_BOOTSTRAP_DRUPAL_SITE, DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION); drush_get_commands(TRUE); $commands = drush_get_commands(); $arguments = drush_get_arguments(); $command_name = array_shift($arguments); if (isset($commands[$command_name])) { // We found it. Load its module name and set an error. if (is_array($commands[$command_name]['drupal dependencies']) && count($commands[$command_name]['drupal dependencies'])) { $modules = implode(', ', $commands[$command_name]['drupal dependencies']); } else { // The command does not define Drupal dependencies. Derive them. $command_files = commandfiles_cache()->get(); $command_path = $commands[$command_name]['path'] . DIRECTORY_SEPARATOR . $commands[$command_name]['commandfile'] . '.drush.inc'; $modules = array_search($command_path, $command_files); } return array('bootstrap_errors' => array('DRUSH_COMMAND_DEPENDENCY_ERROR' => dt('Command !command needs the following module(s) enabled to run: !dependencies.', array('!command' => $command_name, '!dependencies' => $modules)))); } } return FALSE; }
public function query_prefix($query) { // Inject table prefixes as needed. if (drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_DATABASE)) { // Enable prefix processing which can be dangerous so off by default. See http://drupal.org/node/1219850. if (drush_get_option('db-prefix')) { if (drush_drupal_major_version() >= 7) { $query = Database::getConnection()->prefixTables($query); } else { $query = db_prefix_tables($query); } } } return $query; }
/** * Get this site's appropriate drush directory for env vars. * * Optionally, the directory can be created by passing in the --make option. * * @return string * The directory path. */ public function getSiteDir() { if (!drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_SITE)) { return FALSE; } // Check for aliases $site_name = drush_sitealias_bootstrapped_site_name(); $alias = drush_sitealias_get_record("@{$site_name}"); if (floatval(DRUSH_VERSION) > 6.2) { $site_path = drush_sitealias_local_site_path($alias); } else { $supposed_path = drush_sitealias_local_site_path($alias); $hostname = drush_sitealias_uri_to_site_dir($alias['uri']); $site_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT'); if (file_exists($site_root . '/sites/sites.php')) { $sites = []; include $site_root . '/sites/sites.php'; // If we found a match in sites.php and the supposed path is sites/default // then replace 'default' with the matching directory. if (isset($sites[$hostname]) && substr($supposed_path, -8) == '/default') { $site_path = str_replace('/default', "/{$sites[$hostname]}", $supposed_path); } else { $site_path = $supposed_path; } } else { $site_path = $supposed_path; } } // If the site dir is 'default', switch to 'all' if (substr($site_path, -8) == '/default') { $site_path = str_replace('/default', '/all', $site_path); } return $site_path . '/drush'; }