Commit b681c0e9 authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

Add provision_exec to run external provision scripts in their own namespace....

Add provision_exec to run external provision scripts in their own namespace. This is the basis of a cleaner install task
parent 0ea8b823
......@@ -54,7 +54,7 @@ function provision_drupal_provision_backup($url, $data) {
* The default template for the config file
*/
function _provision_drupal_default_template() {
return file_get_contents(drupal_get_path('module', 'provision_drupal') .'/provision_drupal_settings.tpl.php');
return file_get_contents(dirname(__FILE__) .'/provision_drupal_settings.tpl.php');
}
/**
......@@ -592,12 +592,8 @@ function _provision_drupal_import_site($url) {
$data = array(); // initialize site data to empty array
}
$cmd = sprintf("php %s/provision_drupal_import.php %s", drupal_get_path('module', 'provision_drupal'), escapeshellarg($url));
exec($cmd, $return, $code);
$return = join("", $return);
$values = unserialize($return);
if (is_array($values)) {
$data = array_merge($data, $values);
$cmd = sprintf("php %s/provision_drupal_import.php %s", dirname(__FILE__), escapeshellarg($url));
if (provision_exec($cmd, $data)) {
$data['installed'] = TRUE;
}
else {
......
<?php
if ($argv[1]) {
$_SERVER['HTTP_HOST'] = $argv[1];
$_SERVER['SCRIPT_NAME'] = '/index.php';
$command_line = true;
require_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
}
else {
print "USAGE: provision_drupal_import.php url\n";
exit(32);
}
<?php
include_once('provision_drupal_bootstrap.inc');
if ($argv[1]) {
$_SERVER['HTTP_HOST'] = $argv[1];
$_SERVER['SCRIPT_NAME'] = '/index.php';
$command_line = true;
require_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once(dirname(__FILE__) . '/../provision.inc');
}
else {
print "USAGE: provision_drupal_import.php url\n";
exit(PROVISION_FRAMEWORK_ERROR);
}
if ($parts = @parse_url($GLOBALS['db_url'])) {
$data['db_type'] = $parts['scheme'];
......@@ -15,5 +26,7 @@ if ($parts = @parse_url($GLOBALS['db_url'])) {
'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''));
$data['language'] = $language->language;
}
provision_output($argv[1], $data);
print(serialize($data));
exit(1);
exit(PROVISION_SUCCESS);
......@@ -121,7 +121,7 @@ function provision_output($url = NULL, $data = array(), $extra = NULL) {
$return['error_status'] = $error; // error code being returned
$return['log'] = provision_get_log(); // Append logging information
$return['messages'] = drupal_get_messages();
if (drush_get_option(array('b', 'backend'), FALSE)) {
if (PROVISION_DRUSH_BACKEND) {
print serialize($return);
}
else {
......@@ -234,7 +234,6 @@ function _provision_set_log($entry = NULL) {
* String containing the message to be logged.
*/
function provision_log($type, $message) {
if (DRUSH_VERBOSE) print $message . "\n";
_provision_set_log(array(
'type' => $type,
'message' => $message,
......@@ -583,4 +582,26 @@ function provision_posix_groupname($group) {
return $group;
}
/**
* Run an external provision script and integrate it's output
*/
function provision_exec($cmd, &$data) {
exec($cmd, $return, $code);
$return = join("", $return);
provision_log('command', t('Running: @cmd', array('@cmd' => $cmd)));
$values = unserialize($return);
if (is_array($values)) {
$data = array_merge($data, $values['site']);
foreach ($values['log'] as $log) {
provision_log($log['type'], $log['message']);
}
provision_set_error($code);
return TRUE;
}
else {
provision_set_error(PROVISION_FRAMEWORK_ERROR);
provision_log('error', t('External script failed'));
return FALSE;
}
};
......@@ -97,6 +97,8 @@ function provision_init() {
// Set up defines for platform
if (function_exists('drush_get_option')) {
$docroot = drush_get_option(array("r", "root"), $_SERVER['PWD']);
$backend = drush_get_option(array('b', 'backend'), 0);
define("PROVISION_DRUSH_BACKEND", $backend);
}
else {
$docroot = $_SERVER['pwd'];
......
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