/** * Display a link to a given path or open link in a browser. * * @todo Document new @handle-remote-commands and @bootstrap annotations. * * @param string|null $path Path to open. If omitted, the site front page will be opened. * @option string $browser Specify a particular browser (defaults to operating system default). Use --no-browser to suppress opening a browser. * @todo conflicts with global option: @option integer $redirect-port The port that the web server is redirected to (e.g. when running within a Vagrant environment). * @usage drush browse * Open default web browser (if configured or detected) to the site front page. * @usage drush browse node/1 * Open web browser to the path node/1. * @usage drush @example.prod * Open a browser to the web site specified in a site alias. * @usage drush browse --browser=firefox admin * Open Firefox web browser to the path 'admin'. * @todo not used AFAIK @bootstrap DRUSH_BOOTSTRAP_NONE * @todo not used @handle-remote-commands true * @complete \Drush\CommandFiles\core\BrowseCommands::complete */ public function browse($path = '', $options = ['browser' => NULL]) { // Redispatch if called against a remote-host so a browser is started on the // the *local* machine. $alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS'); if (drush_sitealias_is_remote_site($alias)) { $site_record = drush_sitealias_get_record($alias); $return = drush_invoke_process($site_record, 'browse', func_get_args(), drush_redispatch_get_options(), array('integrate' => TRUE)); if ($return['error_status']) { return drush_set_error('Unable to execute browse command on remote alias.'); } else { $link = $return['object']; } } else { if (!drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) { // Fail gracefully if unable to bootstrap Drupal. drush_bootstrap() has // already logged an error. return FALSE; } $link = drush_url($path, array('absolute' => TRUE)); } drush_start_browser($link); return $link; }
/** * Check to see if a '@self' record was created during bootstrap. * If not, make one now. * * @see drush_sitealias_create_self_alias() */ protected function create_self_alias() { $self_record = drush_sitealias_get_record('@self'); if (!array_key_exists('root', $self_record) && !array_key_exists('remote-host', $self_record)) { $backdrop_root = drush_get_context('DRUSH_SELECTED_BACKDROP_ROOT'); $uri = drush_get_context('DRUSH_SELECTED_URI'); if (!empty($backdrop_root) && !empty($uri)) { // Create an alias '@self' _drush_sitealias_cache_alias('@self', array('root' => $backdrop_root, 'uri' => $uri)); } } }
public function bootstrap($phase) { // The project name is the alias name of our site $project_name = $this->getProjectName(); $alias = '@' . $project_name; $site_record = drush_sitealias_get_record($alias); if (!drush_bootstrap_max_to_sitealias($site_record, $phase)) { throw new RumBootstrapDrupalConfigurationFailed(); } }
/** * 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'; }
<?php #!/usr/bin/env drush // Example of execution: // drush scr --root=/home/drupal/kms.test/site/htdocs ping.php --script-path=/home/drupal/kms.test/site/scripts/ftp_permissions // Check if we can bootstrap. $self = drush_sitealias_get_record('@self'); if (empty($self)) { drush_die("I can't bootstrap from the current location.", 0); } $ftp_script_hosts = array('loadftp1.kmsext.dk', 'loadftp2.kmsext.dk'); // Run the ftp thing. kms_permissions_ftp_scan_store_structure(); $i = 1; // Trigger external script. foreach ($ftp_script_hosts as $host) { if (variable_get('kms_ftp_perm_change_' . $i)) { exec(sprintf('ssh -i $HOME/.ssh/updateftpservers %s', $host), $message, $exit_code); if ($exit_code != 1) { variable_set('kms_ftp_perm_change_' . $i, FALSE); // Set variable to false, // as script should revisit the view and update things accordingly. watchdog('Permissions FTP', 'Ftp cron script ran successfully'); } } $i++; }