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

fix the error code handling.

parent 26b5dcf2
......@@ -75,6 +75,14 @@ function _provision_drupal_site_exists($url) {
return file_exists("sites/$url/settings.php");
}
function _provision_drupal_site_installed($url) {
if (_provision_drupal_site_exists($url)) {
if ($data = provision_load_site_data($url)) {
return isset($data['site_installed']) ? $data['site_installed'] : FALSE;
}
}
return false;
}
/**
* Implentation of hook_provision_backup()
......@@ -137,7 +145,7 @@ function _provision_drupal_create_directories($url, $profile = null) {
"sites/$url/files/images" => 02770,
"sites/$url/files/pictures" => 02770,
"sites/$url/themes" => 02750,
"sites/$url/modules" => 02750,
"sites/$url/modules" => 02750,
);
foreach ($paths as $path => $perm) {
......@@ -153,11 +161,10 @@ function _provision_drupal_create_directories($url, $profile = null) {
PROVISION_PERM_ERROR | PROVISION_INSTALL_ERROR );
provision_check_path($path, "chgrp", provision_get_group_name(),
t("Changed group ownership of <code>%path</code>", array("%path" => $path)),
t("Could not change group ownership <code>%path</code>", array("%path" => $path)),
PROVISION_PERM_ERROR | PROVISION_INSTALL_ERROR );
t("Could not change group ownership <code>%path</code>", array("%path" => $path)));
provision_check_path($path, "chmod", $perm,
t("Changed permissions of <code>%path</code> to %perms", array("%path" => $path, '%perms' => $perms)),
t("Could not change ownership <code>%path</code> to %perms", array("%path" => $path, '%perms' => $perms)),
t("Changed permissions of <code>%path</code> to %perms", array("%path" => $path, '%perms' => $perm)),
t("Could not change permissions <code>%path</code> to %perms", array("%path" => $path, '%perms' => $perm)),
PROVISION_PERM_ERROR | PROVISION_INSTALL_ERROR );
}
}
......@@ -261,6 +268,7 @@ function _provision_drupal_force_load_modules($url = null) {
* Install the drupal schema and install profile
*/
function _provision_drupal_install_schema($profile) {
provision_log("install", t("Installing Drupal schema"));
// Load the profile.
require_once "./profiles/$profile/$profile.profile";
......@@ -284,7 +292,7 @@ function _provision_drupal_install_schema($profile) {
if (!$modules) {
return false;
}
// Perform actual installation defined in the profile.
drupal_install_profile($profile, $modules);
......
......@@ -83,8 +83,13 @@ function provision_invoke($hook, $url, &$data, $rollback = false) {
*/
function provision_output($url = null, $data = array(), $extra = null) {
$return = $extra;
$return['site'] = $data;
$return['error_status'] = provision_get_error(); // error code being returned
$error = provision_get_error();
if (!$error) {
$error = PROVISION_SUCCESS; // return 1 on success.
}
$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)) {
......@@ -100,7 +105,7 @@ function provision_output($url = null, $data = array(), $extra = null) {
}
}
}
exit(provision_get_error());
exit($error);
}
......@@ -253,7 +258,7 @@ function provision_get_site_data($url) {
}
$site_data['site_url'] = $url;
$site_data['site_action_type'] = $args['commands'][1];
$docroot = drush_get_option("r", $_SERVER['PWD']);
$docroot = drush_get_option(array("r", "root"), $_SERVER['PWD']);
$site_data['publish_path'] = ($docroot) ? $docroot : $_SERVER['DOCUMENT_ROOT'];
$site_data['site_profile'] = ($site_data['site_profile']) ? $site_data['site_profile'] : variable_get('provision_default_profile', 'default');
$site_data['site_ip'] = variable_get('provision_apache_server_ip', '127.0.0.1');
......@@ -383,7 +388,8 @@ function provision_confirm_drush() {
* Get the backup path of the Provision installation
*/
function _provision_backup_path() {
$parts = explode("/", $_SERVER['DOCUMENT_ROOT']);
$path = ($_SERVER['PWD']) ? $_SERVER['PWD'] : $_SERVER['DOCUMENT_ROOT'];
$parts = explode("/", rtrim($path, '/'));
array_pop($parts);
return variable_get('provision_backup_path', implode("/" , $parts) . '/backups');
}
......@@ -394,7 +400,7 @@ function _provision_backup_path() {
*/
function _provision_config_path() {
$path = ($_SERVER['PWD']) ? $_SERVER['PWD'] : $_SERVER['DOCUMENT_ROOT'];
$parts = explode("/", $path);
$parts = explode("/", rtrim($path, '/'));
array_pop($parts);
return variable_get('provision_config_path', implode("/" , $parts) . '/config') ;
}
......@@ -533,7 +539,7 @@ function provision_check_path($path, $type, $test = true, $succeed_message = '',
provision_set_error($error_codes);
}
if ($fail_message) {
provision_log("error", $fail_message . " ($value != $test");
provision_log("error", $fail_message . " ($value != $test)");
}
}
return $status;
......
......@@ -320,8 +320,6 @@ function provision_drush_command() {
* Will exit with a PROVISION_FRAMEWORK_ERROR if the command is incorrectly used.
*/
function provision_install_cmd($url) {
#safety mechanism to ensure back end calls are not made via the front end.
if (!provision_confirm_drush()) return null;
global $args;
$data = provision_get_site_data($url);
......@@ -335,9 +333,9 @@ function provision_install_cmd($url) {
}
$ops = array('pre_install', 'install', 'post_install'); # these are the provision hooks that will get triggered.
if ($data['site-installed'] == TRUE) {
print "The site $url is already installed.\nIf you want to re-install it, you will need to delete it first.";
if (_provision_drupal_site_installed($url)) {
provision_set_error(PROVISION_SITE_INSTALLED);
provision_log("error", t("Site has already been installed. Exiting."));
provision_output($url, $data);
}
......@@ -365,10 +363,7 @@ function provision_install_cmd($url) {
* Boolean denoting whether the provision_invoke rolled back changes made.
*/
function _provision_pre_install($url, &$data) {
#safety mechanism to ensure back end calls are not made via the front end.
if (!provision_confirm_drush()) return null;
$rolled_back = provision_invoke("pre_install", $url, $data);
if (!provision_get_error()) {
// This is the actual drupal provisioning requirements.
_provision_drupal_create_directories($url, $data['profile']);
......@@ -424,11 +419,9 @@ function _provision_install($url, &$data) {
* Boolean denoting whether the provision_invoke rolled back changes made.
*/
function _provision_post_install($url, &$data) {
#safety mechanism to ensure back end calls are not made via the front end.
if (!provision_confirm_drush()) return null;
$rolled_back = provision_invoke("post_install", $url, $data);
if (!$rolled_back) {
$data['site-installed'] = true;
$data['site_installed'] = true;
}
return $rolled_back;
}
......@@ -443,10 +436,8 @@ function _provision_post_install($url, &$data) {
* Will exit with a PROVISION_SITE_NOT_FOUND error if the site does not exist.
*/
function _provision_synch($url) {
#safety mechanism to ensure back end calls are not made via the front end.
if (!provision_confirm_drush()) return null;
if (!_provision_drupal_site_exists($url)) {
provision_log("Error", "Site has not been installed yet.");
if (!_provision_drupal_site_installed($url)) {
provision_log("error", "Site has not been installed yet.");
provision_set_error(PROVISION_SITE_NOT_FOUND);
provision_output($url, $data);
}
......@@ -470,7 +461,7 @@ function _provision_synch($url) {
* Will exit with a PROVISION_SITE_NOT_FOUND error if the site does not exist.
*/
function _provision_backup($url) {
if (!_provision_drupal_site_exists($url)) {
if (!_provision_drupal_site_installed($url)) {
provision_log("Error", "Site has not been installed yet.");
provision_set_error(PROVISION_SITE_NOT_FOUND);
provision_output($url, $data);
......@@ -528,8 +519,6 @@ function _provision_backup_site($url, &$data, $file = null) {
* Will exit with a PROVISION_SITE_NOT_FOUND error if the site does not exist.
*/
function _provision_import($url) {
#safety mechanism to ensure back end calls are not made via the front end.
if (!provision_confirm_drush()) return null;
if (!_provision_drupal_site_exists($url)) {
provision_log("Error", "Site directory is not present, and can not be imported.");
......@@ -622,7 +611,7 @@ function _provision_verify($url = '') {
}
function _provision_restore($site, $backup_file) {
if (!_provision_drupal_site_exists($url)) {
if (!_provision_drupal_site_installed($url)) {
provision_log("Error", "Site has not been installed yet.");
provision_set_error(PROVISION_SITE_NOT_FOUND);
provision_output($url, $data);
......
......@@ -12,10 +12,10 @@
* @see provision_set_error(), provision_get_error(), provision_cmp_error()
*/
/** Succesful **/
define('PROVISION_SUCCESS', -1);
/** Queue not run */
define('PROVISION_QUEUED', 1);
define('PROVISION_QUEUED', 0);
/** Succesful **/
define('PROVISION_SUCCESS', 1);
/** Drupal was unable to complete it's installation */
define('PROVISION_INSTALL_ERROR', 2);
/** Could not create files due to permission error - potentially less severe */
......
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