Commit 46fd4e6e authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

Merged the verify and synch tasks.

parent 2ea9d2b6
......@@ -480,20 +480,30 @@ function provision_drupal_send_welcome_mail($url, $profile, $language, $client_e
* implementation of provision_verify
*/
function provision_drupal_provision_verify($url, &$data) {
_provision_drupal_create_directories('default');
provision_path("writable", "sites", TRUE, t("Drupal sites directory is writable by the provisioning script"),
t("Drupal sites directory is not writable by the provisioning script"), PROVISION_PERM_ERROR);
$exists = _provision_create_dir(PROVISION_DRUSHRC_PATH, t('Drush configuration path'), 0700);
$data['modules'] = _provision_drupal_get_cvs_versions(module_rebuild_cache());
// Find theme engines
$data['engines'] = drupal_system_listing('\.engine$', 'themes/engines');
$data['profiles'] = _provision_find_profiles();
$data['themes'] = system_theme_data();
$data['platform'] = array('short_name' => 'drupal', 'version' => VERSION);
provision_log('notice', t("This platform is running @short_name @version",
array('@short_name' => 'drupal', '@version' => VERSION)));
$sites = provision_drupal_find_sites();
$data['sites'] = array_keys($sites); // return list of hosted sites. used to determine whether or not to import.
if (!$url) {
provision_path("writable", "sites", TRUE, t("Drupal sites directory is writable by the provisioning script"),
t("Drupal sites directory is not writable by the provisioning script"), PROVISION_PERM_ERROR);
$exists = _provision_create_dir(PROVISION_DRUSHRC_PATH, t('Drush configuration path'), 0700);
$data['modules'] = _provision_drupal_get_cvs_versions(module_rebuild_cache());
// Find theme engines
$data['engines'] = drupal_system_listing('\.engine$', 'themes/engines');
$data['profiles'] = _provision_find_profiles();
$data['themes'] = system_theme_data();
$data['platform'] = array('short_name' => 'drupal', 'version' => VERSION);
provision_log('notice', t("This platform is running @short_name @version",
array('@short_name' => 'drupal', '@version' => VERSION)));
$sites = provision_drupal_find_sites();
$data['sites'] = array_keys($sites); // return list of hosted sites. used to determine whether or not to import.
}
else {
// This is the actual drupal provisioning requirements.
_provision_drupal_create_directories($url, $data['profile']);
_provision_drupal_maintain_aliases($url, $data);
// Requires at least the database settings to complete.
_provision_drupal_create_settings_file($url, $data);
}
}
/**
......
......@@ -13,6 +13,8 @@
* @see provisionvalues
*/
define('PROVISION_OUTPUT', 'PROVISION_OUTPUT>>>');
/**
* Invoke provision api calls.
*
......@@ -95,6 +97,35 @@ function _provision_log_messages() {
}
function provision_parse_output($lines) {
$start = FALSE;
$output = '';
foreach ($lines as $line) {
if (preg_match('/^' . PROVISION_OUTPUT . '/', $line)) {
// found the start out output.
$line = str_replace(PROVISION_OUTPUT, '', $line);
$start = TRUE;
}
if ($start) {
$output .= $line;
}
else {
if (!trim($line)) {
$messages[] = array('type' => 'warning', 'message' => $line, 'timestamp' => time());
}
}
}
if ($start) {
$data = unserialize($output);
if (is_array($data)) {
if (is_array($messages)) {
$data['log'] = array_merge($data['log'], $messages);
}
return $data;
}
}
return false;
}
/**
......@@ -122,7 +153,7 @@ function provision_output($url = NULL, $data = array(), $extra = NULL) {
$return['log'] = provision_get_log(); // Append logging information
$return['messages'] = drupal_get_messages();
if (PROVISION_DRUSH_BACKEND) {
print serialize($return);
print PROVISION_OUTPUT . serialize($return);
}
else {
if ($return) {
......@@ -618,9 +649,8 @@ function provision_posix_groupname($group) {
*/
function provision_exec($cmd, &$data) {
exec($cmd, $return, $code);
$return = join("", $return);
provision_log('command', t('Running: @cmd', array('@cmd' => $cmd)));
$values = unserialize($return);
$values = provision_parse_output($return);
if (is_array($values)) {
$data = array_merge($data, $values['site']);
foreach ($values['log'] as $log) {
......@@ -633,7 +663,7 @@ function provision_exec($cmd, &$data) {
}
else {
provision_set_error(PROVISION_FRAMEWORK_ERROR);
provision_log('error',t("The command could not be executed succesfully (returned: !return, code: %code)", array("!return" => $return, "%code" => $code)));
provision_log('error',t("The command could not be executed succesfully (returned: !return, code: %code)", array("!return" => implode('', $return), "%code" => $code)));
return FALSE;
}
};
......
......@@ -14,7 +14,7 @@
* Implemented :
* install - Install a new Drupal site. The install command uses 3 separate hooks to do it's job,
* namely hook_provision_pre_install(), hook_provision_install() and hook_provision_post_install()
* synch - Recreate all configuration files, to be in synch with changes in the front end.
* verify - Recreate all configuration files, to be in synch with changes in the front end. And test that they are correct.
* stats - Return an associated array of site statistics. (implemented in provision_stats module, is thus optional)
* import - Import the details of an already existing site into the provisioning framework.
* This command inspects the settings.php and generates the site.php file that the framework uses for configuration.
......@@ -277,12 +277,6 @@ function provision_drush_command() {
'description' => t('Provision a new site using the provided data.')
);
$items['provision synch'] = array(
'callback' => '_provision_synch',
'optional arguments' => array('domain.com' => t('The domain of the site to synch.')),
'description' => t('Regenerate the configuration files for a site or platform.')
);
$items['provision import'] = array(
'callback' => '_provision_import',
'arguments' => array('domain.com' => t('The domain of the site to import.')),
......@@ -309,7 +303,7 @@ function provision_drush_command() {
$items['provision verify'] = array(
'callback' => '_provision_verify',
# 'arguments' => array('domain.com' => t('The domain of the site to disable (only if disabled).')),
'arguments' => array('domain.com' => t('The domain of the site to verify).')),
'description' => 'Verify that the provisioning framework is correctly installed.'
);
......@@ -486,25 +480,9 @@ function _provision_post_install($url, &$data) {
function _provision_synch($url = NULL) {
if (!$url) {
global $args;
_provision_generate_config($args['options']);
provision_output(NULL, $args['options']);
provision_output(NULL, $data);
}
else {
if (!_provision_drupal_site_installed($url)) {
provision_log("error", "Site has not been installed yet.");
provision_set_error(PROVISION_SITE_NOT_FOUND);
provision_output();
}
$data = provision_get_site_data($url);
// This is the actual drupal provisioning requirements.
_provision_drupal_create_directories($url, $data['profile']);
_provision_drupal_maintain_aliases($url, $data);
$rolled_back = provision_invoke("synch", $url, $data);
// Requires at least the database settings to complete.
_provision_drupal_create_settings_file($url, $data);
$data['installed'] = TRUE;
provision_save_site_data($url, $data);
provision_output($url, $data);
}
}
......@@ -593,20 +571,41 @@ function _provision_import($url) {
* This is accomplished by inspecting the settings.php file and generating a site.php file.
*
* @param url
* The url of the site being synched.
* The url of the site being verified.
* Optional, if no site is specified the platform will be verified
* @return
* Output of provision_output() function.
* Will exit with a PROVISION_SITE_NOT_FOUND error if the site does not exist.
* Will exit with a PROVISION_SITE_NOT_FOUND error if the site specified does not exist.
*/
function _provision_verify($url = '') {
_provision_create_dir(PROVISION_CONFIG_PATH, t('Provision configuration'), 0700);
_provision_create_dir(PROVISION_BACKUP_PATH, t('Web server configuration'), 0700);
$data = array();
function _provision_verify($url = NULL) {
if (!$url) {
// we are verifying a platform
$data = array();
_provision_create_dir(PROVISION_CONFIG_PATH, t('Provision configuration'), 0700);
_provision_create_dir(PROVISION_BACKUP_PATH, t('Web server configuration'), 0700);
}
else {
// we are verifying a site
if (!_provision_drupal_site_installed($url)) {
provision_log("error", "Site has not been installed yet.");
provision_set_error(PROVISION_SITE_NOT_FOUND);
provision_output();
}
$data = provision_get_site_data($url);
}
$rolled_back = provision_invoke("verify", $url, $data);
if ($url) {
provision_save_site_data($url, $data);
// We only save the settings if they validated correctly, not before.
if (!$rolled_back) {
if (!$url) {
_provision_generate_config();
}
else {
provision_save_site_data($url, $data);
}
}
provision_output($url, $data);
}
......
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