Commit 24520f12 authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

Move to using drush_backend_invoke. #380688

parent 0b4a2986
......@@ -12,7 +12,7 @@ function provision_mysql_provision_verify_validate() {
function provision_mysql_provision_verify() {
if (PROVISION_CONTEXT_PLATFORM) {
if (!_provision_mysql_can_create_database()) {
drush_set_error('PROVISION_CREATE_DB_FAILED', dt('Unable to create new databases.'));
drush_set_error('PROVISION_CREATE_DB_FAILED');
}
else {
drush_log(dt('Mysql can create new databases.'), 'message');
......
......@@ -13,7 +13,7 @@ $old_url = $data['old_site_url'];
*/
drush_log(
pt('Changed paths from sites/@old_url to sites/@new_url',
dt('Changed paths from sites/@old_url to sites/@new_url',
array('@old_url' => $old_url, '@new_url' => $new_url)));
db_query("UPDATE {files} SET filepath=replace(filepath, 'sites/%', 'sites/%')", $old_url, $new_url);
......
......@@ -49,8 +49,7 @@ function provision_provision_pre_migrate_rollback(&$data, $url, $platform) {
* Switch the migrate directories around now that we have the new db installed
*/
function provision_drupal_provision_migrate(&$data, $url, $platform) {
$cmd = sprintf("%s provision deploy %s %s --root=%s --backend=1", $_SERVER['argv'][0], $url, $data['backup_file'], $platform);
provision_exec($cmd,$data);
drush_backend_invoke('provision deploy', array($url, $data['backup_file'], 'root' => $platform);
}
......
......@@ -326,29 +326,6 @@ function _provision_drupal_get_cvs_versions($files) {
return $files;
}
function _provision_drupal_import_site(&$data, $url = NULL) {
$cmd = sprintf("php %s/drupal_import.php %s", dirname(__FILE__), escapeshellarg($url));
if (provision_exec($cmd, $data)) {
$data['installed'] = TRUE;
}
else {
$data['installed'] = FALSE;
}
}
/**
* Retrieve drupal variable from database
*
* This is different to the normal variable_get in that it doesn't
* do any caching whatsoever.
*/
function _provision_drupal_variable_get($name, $default) {
$value = db_result(db_query("SELECT value FROM {variable} WHERE name='%s'", $name));
return ($value) ? unserialize($value) : $default;
}
/**
* Create and remove symlinks for each of the possible domain aliases of an existing site
*/
......
......@@ -56,9 +56,7 @@ function provision_init() {
}
// Set up defines for platform
$docroot = provision_get_option(array("r", "root"), $_SERVER['PWD']);
$backend = provision_get_option(array('b', 'backend'), 0);
define("PROVISION_DRUSH_BACKEND", $backend);
$docroot = drush_get_option(array("r", "root"), $_SERVER['PWD']);
define('PROVISION_DOMAIN', $_SERVER['HTTP_HOST']);
// Paths
......@@ -70,31 +68,31 @@ function provision_init() {
array_pop($parts);
define('PROVISION_PARENT_PATH', rtrim(implode("/" , $parts), '/'));
define('PROVISION_BACKUP_PATH',
provision_get_option('backup_path', PROVISION_PARENT_PATH . '/backups'));
drush_get_option('backup_path', PROVISION_PARENT_PATH . '/backups'));
define('PROVISION_CONFIG_PATH',
provision_get_option('config_path', PROVISION_PARENT_PATH .'/config'));
drush_get_option('config_path', PROVISION_PARENT_PATH .'/config'));
define('PROVISION_VHOST_PATH', PROVISION_CONFIG_PATH .'/vhost.d');
// Commands
define('PROVISION_RESTART_CMD',
provision_get_option('restart_cmd', _provision_default_restart_cmd()));
drush_get_option('restart_cmd', _provision_default_restart_cmd()));
// System account
$info = posix_getgrgid(posix_getgid());
define('PROVISION_WEB_GROUP',
provision_get_option('web_group', $info['name'] ));
drush_get_option('web_group', $info['name'] ));
define('PROVISION_SCRIPT_USER',
provision_get_option('script_user', get_current_user() ));
drush_get_option('script_user', get_current_user() ));
// Redirection urls
define('PROVISION_MASTER_URL',
provision_get_option('master_url', $GLOBALS['base_url']));
drush_get_option('master_url', $GLOBALS['base_url']));
define('PROVISION_WEB_DISABLE_URL', PROVISION_MASTER_URL .'/provision/disabled');
define('PROVISION_WEB_MAINTENENCE_URL', PROVISION_MASTER_URL .'/provision/maintenance');
// Database
define('PROVISION_MASTER_DB',
provision_get_option('master_db', $GLOBALS['db_url']));
drush_get_option('master_db', $GLOBALS['db_url']));
$db = parse_url(PROVISION_MASTER_DB);
define('PROVISION_DB_USER', $db['user']);
define('PROVISION_DB_PASSWD', $db['pass']);
......
......@@ -101,72 +101,12 @@ function provision_command($hook, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL, $arg
$func($data, $arg1, $arg2, $arg3, $arg4, $arg5);
_drush_log_drupal_messages();
}
$GLOBALS['args']['options'] = array_merge($GLOBALS['args']['options'], $data);
}
}
provision_output($data);
}
function provision_parse_output($string) {
$regex = sprintf(PROVISION_OUTPUT, '(.*)');
preg_match("/$regex/s", $string, $match);
if ($match[1]) {
// we have our serialized string
$output = $match[1];
// remove the match we just made and any non printing characters
$string = trim(str_replace(sprintf(PROVISION_OUTPUT, $match[1]), '', $string));
if ($string) {
$messages[] = array('type' => 'warning', 'message' => $string, 'timestamp' => time());
}
}
if ($output) {
$data = unserialize($output);
if (is_array($data)) {
if (is_array($messages)) {
$data['log'] = array_merge($data['log'], $messages);
}
return $data;
}
}
return false;
}
/**
* Return output to the command line.
*
* Provides support for the -b/--backend flag to drush, which returns a serialized data structure.
* This feature is used for communication with the front end.
*
* @param data
* The complete associative array containing all the aggregated site settings.
* @param extra
* An associative array containing additional data to be returned from the command. @see provision_stats_stats()
*/
function provision_output($data = array()) {
$return['site'] = $data;
$error = drush_get_error();
if (!$error) {
$error = DRUSH_SUCCESS; // return 1 on success.
}
$return['error_status'] = $error; // error code being returned
$return['error_log'] = drush_get_error_log();
$return['log'] = drush_get_log(); // Append logging information
if (PROVISION_DRUSH_BACKEND) {
printf(PROVISION_OUTPUT, serialize($return));
}
else {
if ($return) {
/** TODO : return a cleanly formatted display of all the necessary information */
print_r($return);
}
}
exit($error);
}
/**
* @defgroup sitedata Site data management utility functions.
* @{
......@@ -310,8 +250,6 @@ function provision_save_platform_data() {
* @{
*/
/**
* Generate the text for a config file using php
*/
......@@ -498,102 +436,6 @@ function provision_proc_open($cmd, &$data = NULL) {
return false;
}
/**
* Run an external provision script and integrate it's output
*/
function provision_exec($cmd, &$data) {
drush_log(dt('Running: @cmd', array('@cmd' => $cmd)), 'command');
$proc = provision_proc_open($cmd, $data);
if ($proc['output']) {
$values = provision_parse_output($proc['output']);
if (is_array($values)) {
$data = array_merge($data, $values['site']);
foreach ($values['log'] as $log) {
drush_log($log['message'], $log['type']);
}
if (!($proc['code'] & DRUSH_SUCCESS)) {
drush_set_error($proc['code']);
}
return TRUE;
}
else {
return drush_set_error(DRUSH_FRAMEWORK_ERROR, dt("The command could not be executed succesfully (returned: !return, code: %code)", array("!return" => $proc['output'], "%code" => $proc['code'])));
}
}
};
/**
* A wrapper for drush_get_option for when it is not present
*/
function provision_get_option($option, $default) {
if (function_exists('drush_get_option')) {
return call_user_func('drush_get_option', $option, $default);
}
else {
return $default;
}
}
/**
* A wrapper for dt(). The st() function is too specific for our purposes
*/
function pt($string, $args = array()) {
if (function_exists('t')) {
return call_user_func('t', $string, $args);
}
else {
// Transform arguments before inserting them
foreach ($args as $key => $value) {
switch ($key[0]) {
// Escaped only
case '@':
$args[$key] = htmlspecialchars($value, ENT_QUOTES);
break;
// Escaped and placeholder
case '%':
default:
$args[$key] = '<em>'. htmlspecialchars($value, ENT_QUOTES) .'</em>';
break;
// Pass-through
case '!':
}
}
return strtr($string, $args);
}
}
/**
* This is a script that allows external scripts to initialize themselves to a certain url (usually $argv[1])
*
* Some scripts need to run with drupal as the only active database, and this allows us to do that.
*/
function provision_external_init($url, $bootstrap = TRUE) {
$url = ($url) ? $url : 'default';
$drupal_base_url = parse_url(sprintf("http://" . $url));
$_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
$_SERVER['PHP_SELF'] = $drupal_base_url['path'].'/install.php';
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
$_SERVER['REMOTE_ADDR'] = '';
$_SERVER['REQUEST_METHOD'] = NULL;
$_SERVER['SERVER_SOFTWARE'] = NULL;
define('DRUPAL_ROOT', realpath('.'));
define('PROVISION_DRUSH_BACKEND', true);
if ($bootstrap) {
include_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
}
ob_start();
print stream_get_contents(STDIN);
$string = ob_get_contents();
ob_end_clean();
if (trim($string)) {
return unserialize($string);
}
return TRUE;
}
function provision_internal_init($url, $bootstrap = TRUE) {
$url = ($url) ? $url : 'default';
$drupal_base_url = parse_url(sprintf("http://" . $url));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment