public function createLink($source, $target) { $result = drush_shell_exec("sudo ln -s {$source} {$target}"); if (!$result) { throw new FileSystemCouldNotCreateLink($source, $target); } }
public function fetch($repository, $working_directory) { $username = drush_prompt(dt('Please provide your username for this svn repository'), ''); if (!drush_shell_exec("svn --username {$username} co {$repository} {$working_directory}")) { throw new RumRepositoryNotCheckedOutException($repository, $working_directory); } }
public function fetch($repository, $working_directory) { if (!drush_shell_exec("git clone {$repository} {$working_directory}")) { throw new RumRepositoryNotClonedException($repository, $working_directory); } $create_ignore = drush_confirm(dt('Do you want to create an ignore file?')); if ($create_ignore) { $this->createIgnoreFile($working_directory); } }
public function db_exists() { $database = $this->db_spec['database']; // Get a new class instance that has no 'database'. $db_spec_no_db = $this->db_spec; unset($db_spec_no_db['database']); $sql_no_db = drush_sql_get_class($db_spec_no_db); $query = "SELECT 1 AS result FROM pg_database WHERE datname='{$database}'"; drush_shell_exec($sql_no_db->connect() . ' -t -c %s', $query); $output = drush_shell_exec_output(); return (bool) $output[0]; }
public function db_exists() { // TODO: untested, but the gist is here. $database = $this->db_spec['database']; // Get a new class instance that has no 'database'. $db_spec_no_db = $this->db_spec; unset($db_spec_no_db['database']); $sql_no_db = drush_sql_get_class($db_spec_no_db); $query = "if db_id('{$database}') IS NOT NULL print 1"; drush_shell_exec($sql_no_db->connect() . ' -Q %s', $query); $output = drush_shell_exec_output(); return $output[0] == 1; }
public function restart($os) { switch ($os) { case Apache::RUM_APACHE_UBUNTU: drush_shell_exec("sudo /etc/init.d/apache2 reload"); break; case Apache::RUM_APACHE_OSX: drush_shell_exec("sudo apachectl restart"); break; case Apache::RUM_APACHE_MAMP: drush_shell_exec("/Applications/MAMP/bin/apache2/bin/apachectl restart"); break; case Apache::RUM_APACHE_FEDORA: drush_shell_exec("sudo /etc/init.d/httpd reload"); break; default: throw new RumApacheNoCommandNotFound(); } }
/** * Execute a SQL query. * * Note: This is an API function. Try to avoid using drush_get_option() and instead * pass params in. If you don't want to query results to print during --debug then * provide a $result_file whose value can be drush_bit_bucket(). * * @param string $query * The SQL to be executed. Should be NULL if $input_file is provided. * @param string $input_file * A path to a file containing the SQL to be executed. * @param string $result_file * A path to save query results to. Can be drush_bit_bucket() if desired. * * @return * TRUE on success, FALSE on failure */ public function query($query, $input_file = NULL, $result_file = '') { $input_file_original = $input_file; if ($input_file && drush_file_is_tarball($input_file)) { if (drush_shell_exec('gunzip %s', $input_file)) { $input_file = trim($input_file, '.gz'); } else { return drush_set_error(dt('Failed to gunzip input file.')); } } // Save $query to a tmp file if needed. We will redirect it in. if (!$input_file) { $query = $this->query_prefix($query); $query = $this->query_format($query); $input_file = drush_save_data_to_temp_file($query); } $parts = array($this->command(), $this->creds(), $this->silent(), drush_get_option('extra', $this->query_extra), $this->query_file, drush_escapeshellarg($input_file)); $exec = implode(' ', $parts); if ($result_file) { $exec .= ' > ' . drush_escapeshellarg($result_file); } // In --verbose mode, drush_shell_exec() will show the call to mysql/psql/sqlite, // but the sql query itself is stored in a temp file and not displayed. // We show the query when --debug is used and this function created the temp file. if ((drush_get_context('DRUSH_DEBUG') || drush_get_context('DRUSH_SIMULATE')) && empty($input_file_original)) { drush_log('sql-query: ' . $query, LogLevel::NOTICE); } $success = drush_shell_exec($exec); if ($success && drush_get_option('file-delete')) { drush_op('drush_delete_dir', $input_file); } return $success; }
// Load a drushrc.php file from the 'drush' folder at the root of the current // git repository. Customize as desired. // (Script by grayside; @see: http://grayside.org/node/93) $repo_dir = drush_get_option('root') ? drush_get_option('root') : getcwd(); $success = drush_shell_exec('cd %s && git rev-parse --show-toplevel 2> ' . drush_bit_bucket(), $repo_dir); if ($success) { $output = drush_shell_exec_output(); $repo = $output[0]; // If drush directory is not found, look for a parent git repo which might contain the drush folder if (!is_dir($repo . '/drush')) { $success = drush_shell_exec('cd %s && cd .. && git rev-parse --show-toplevel 2> ' . drush_bit_bucket(), $repo); if ($success) { $output = drush_shell_exec_output(); $repo = $output[0]; if (!is_dir($repo . '/drush')) { $success = drush_shell_exec('cd %s && cd .. && git rev-parse --show-toplevel 2> ' . drush_bit_bucket(), $repo); if ($success) { $output = drush_shell_exec_output(); $repo = $output[0]; } } } } if (is_dir($repo . '/drush')) { $options['config'] = $repo . '/drush/drushrc.php'; $options['include'] = $repo . '/drush/commands'; $options['alias-path'] = $repo . '/drush/aliases'; //print_r($options); // can be used to debug which directories it finds. } } $override = array('language_default' => (object) array('language' => 'en'));
* command line. Unary flags such as "--verbose" are overridden via special * "--no-xxx" options (e.g. "--no-verbose"). * * Limitation: If 'verbose' is set in a command-specific option, it must be * cleared by '--no-verbose', not '--no-v', and visa-versa. */ // Ensure all rsync commands use verbose output. # $command_specific['rsync'] = array('verbose' => TRUE); // Prevent drush ssh command from adding a cd to Drupal root before provided command. # $command_specific['ssh'] = array('cd' => FALSE); // Additional folders to search for scripts. // Separate by : (Unix-based systems) or ; (Windows). # $command_specific['script']['script-path'] = 'sites/all/scripts:profiles/myprofile/scripts'; // Always show release notes when running pm-update or pm-updatecode. # $command_specific['pm-update'] = array('notes' => TRUE); # $command_specific['pm-updatecode'] = array('notes' => TRUE); // Set a predetermined username and password when using site-install. # $command_specific['site-install'] = array('account-name' => 'alice', 'account-pass' => 'secret'); /** * Load a drushrc file from the 'drush' folder at the root of the current * git repository. Example script below by Grayside. Customize as desired. * @see: http://grayside.org/node/93. */ $repo_dir = drush_get_option('root') ? drush_get_option('root') : getcwd(); if (drush_shell_exec('cd %s && git rev-parse --show-toplevel 2> ' . drush_bit_bucket(), $repo_dir)) { $output = drush_shell_exec_output(); $repo_top = $output[0]; $options['config'] = $repo_top . '/drush/drushrc.php'; $options['include'] = $repo_top . '/drush/commands'; $options['alias-path'] = $repo_top . '/drush/aliases'; }
public function dropDatabase($database) { $drop_command = $this->baseCommand() . "DROP DATABASE IF EXISTS " . $database . ";\""; drush_shell_exec($drop_command); }
/** * Download a backup. * * @param array $backup * An array from apiGetSiteEnvBackups(). * @param string $destination * The path to the destination. * * @return string * The full path to the downloaded backup. */ public function apiDownloadBackup($backup, $destination) { drush_log(var_export($backup, TRUE)); $destination_tmp = drush_tempnam('download_file'); drush_shell_exec("curl --fail -s -L -u " . $this->authEmailGet() . ":" . $this->authPasswordGet() . " --connect-timeout 30 -o %s %s", $destination_tmp, $backup['url']); if (!drush_file_not_empty($destination_tmp) && ($file = @file_get_contents($backup['url']))) { @file_put_contents($destination_tmp, $file); } if (!drush_file_not_empty($destination_tmp)) { return drush_set_error('SWITCHBOARD_ACQUIA_BACKUP_DL_FAIL', dt('Unable to download!')); } $destination_path = $destination . DIRECTORY_SEPARATOR . $backup['filename']; drush_move_dir($destination_tmp, $destination_path, TRUE); return $destination_path; }
/** * Find the path to command. * * @param string $command * The command to find. * * @return string * The system path to run the command or empty if not found. */ private static function getCommand($command) { drush_shell_exec("which {$command}"); $stdout = (array) drush_shell_exec_output(); return reset($stdout); }