Commit 93373b2c authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

Make use of constants for important paths. This is consistent with how hosting does it.

parent 832891eb
......@@ -309,18 +309,17 @@ function provision_drupal_provision_verify($url, &$data) {
provision_check_path("sites", "writable", 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);
$path = _provision_drushrc_path();
$exists = provision_check_path($path, "exists", true ,
$exists = provision_check_path(PROVISION_DRUSHRC_PATH, "exists", true ,
t("Virtual Host configuration path exists."),
t("Virtual Host configuration path does not exist."));
if (!$exists) {
$made = provision_check_path($path, "mkdir", true,
$made = provision_check_path(PROVISION_DRUSHRC_PATH, "mkdir", true,
t("Virtual host configuration path has been created."),
t("Virtual host configuration path could not be created."),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
}
else {
$writable = provision_check_path($path, "writable", true ,
$writable = provision_check_path(PROVISION_DRUSHRC_PATH, "writable", true ,
t("Virtual host configuration path is writable."),
t("Virtual host configuration path is not writable."),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
......
......@@ -385,38 +385,18 @@ function provision_confirm_drush() {
}
/**
* Get the backup path of the Provision installation
* Provide defines for all the major paths.
* Avoids duplication and possible errors in duplication
*/
function _provision_backup_path() {
function provision_init_paths() {
$path = ($_SERVER['PWD']) ? $_SERVER['PWD'] : $_SERVER['DOCUMENT_ROOT'];
$parts = explode("/", rtrim($path, '/'));
array_pop($parts);
return variable_get('provision_backup_path', implode("/" , $parts) . '/backups');
}
/**
* Get the base configuration path for the system
*/
function _provision_config_path() {
$path = ($_SERVER['PWD']) ? $_SERVER['PWD'] : $_SERVER['DOCUMENT_ROOT'];
$parts = explode("/", rtrim($path, '/'));
array_pop($parts);
return variable_get('provision_config_path', implode("/" , $parts) . '/config') ;
}
/**
* Get the vhost path of the Provision installation
*/
function _provision_vhost_path() {
return _provision_config_path() . '/vhost.d';
}
/**
* Get the drushrc path of the Provision installation
*/
function _provision_drushrc_path() {
return _provision_config_path() . '/drush';
define('PROVISION_BACKUP_PATH', rtrim(variable_get('provision_backup_path', implode("/" , $parts) . '/backups'), '/'));
define('PROVISION_CONFIG_PATH', rtrim(variable_get('provision_config_path', implode("/" , $parts) . '/config'), '/')) ;
define('PROVISION_VHOST_PATH', PROVISION_CONFIG_PATH . '/vhost.d');
define('PROVISION_DRUSHRC_PATH', PROVISION_CONFIG_PATH . '/drushrc.d');
}
......
......@@ -34,8 +34,16 @@
*/
/** Include the provisioning API. */
include_once('provision.inc');
/**
* Implementation of hook_init
*/
function provision_init() {
// Include the provisioning API.
include_once('provision.inc');
// Set up defines for platform
provision_init_paths();
}
/**
* Implementation of hook_provision_service
......@@ -551,50 +559,48 @@ function _provision_import($url = null) {
* Will exit with a PROVISION_SITE_NOT_FOUND error if the site does not exist.
*/
function _provision_verify($url = '') {
$path = _provision_config_path();
$exists = provision_check_path($path, "exists", true ,
$exists = provision_check_path(PROVISION_CONFIG_PATH, "exists", true ,
t("Provision configuration path exists."),
t("Provision configuration path does not exist."));
if (!$exists) {
$made = provision_check_path($path, "mkdir", true,
$made = provision_check_path(PROVISION_CONFIG_PATH, "mkdir", true,
t("Provision configuration path has been created."),
t("Provision configuration could not be created."),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
}
provision_check_path($path, "writable", true ,
provision_check_path(PROVISION_CONFIG_PATH, "writable", true ,
t("Provision configuration path is writable."),
t("Provision configuration path is not writable."),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
provision_check_path($path, "chown", provision_get_script_owner(),
provision_check_path(PROVISION_CONFIG_PATH, "chown", provision_get_script_owner(),
t("Changed ownership of <code>%path</code>", array("%path" => $path)),
t("Could not change ownership <code>%path</code>", array("%path" => $path)),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR );
provision_check_path($path, "chmod", 0700,
provision_check_path(PROVISION_CONFIG_PATH, "chmod", 0700,
t("Changed permissions of <code>%path</code> to %perms", array("%path" => $path, '%perms' => sprintf('%o', 0700))),
t("Could not change ownership <code>%path</code> to %perms", array("%path" => $path, '%perms' => sprintf('%o', 0700))),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR );
$path = _provision_backup_path();
$exists = provision_check_path($path, "exists", true ,
$exists = provision_check_path(PROVISION_BACKUP_PATH, "exists", true ,
t("Provision backup path exists."),
t("Provision backup path does not exist."));
if (!$exists) {
$made = provision_check_path($path, "mkdir", true,
$made = provision_check_path(PROVISION_BACKUP_PATH, "mkdir", true,
t("Provision backup path has been created."),
t("Provision backup could not be created."),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
}
provision_check_path($path, "writable", true ,
provision_check_path(PROVISION_BACKUP_PATH, "writable", true ,
t("Provision backup path is writable."),
t("Provision backup path is not writable."),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
provision_check_path($path, "chown", provision_get_script_owner(),
provision_check_path(PROVISION_BACKUP_PATH, "chown", provision_get_script_owner(),
t("Changed ownership of <code>%path</code>", array("%path" => $path)),
t("Could not change ownership <code>%path</code>", array("%path" => $path)),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR );
provision_check_path($path, "chmod", 0700,
provision_check_path(PROVISION_BACKUP_PATH, "chmod", 0700,
t("Changed permissions of <code>%path</code> to %perms", array("%path" => $path, '%perms' => sprintf('%o', 0700))),
t("Could not change ownership <code>%path</code> to %perms", array("%path" => $path, '%perms' => sprintf('%o', 0700))),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR );
......@@ -622,8 +628,8 @@ function _provision_restore($site, $backup_file) {
_provision_backup_site($url, $data); # Backup site for posterity, before rolling back.
provision_shell_exec("tar -zxf %s -C %s/%s.tmp", $backup_file, provision_backup_path(), $url); # check out old directory.
$rolled_back = provision_invoke("restore", $url, $data);
$data['site_installed'] = TRUE;
provision_save_site_data($url, $data);
}
......
......@@ -22,7 +22,7 @@ function provision_apache_help($section) {
case 'admin/help/provision#requirements':
$username = provision_get_script_owner();
$group = provision_get_group_name();
$vhost_path = _provision_vhost_path();
$vhost_path = PROVISION_VHOST_PATH;
$mkdir_cmd['@vhost_path'] = $vhost_path;
$mkdir_cmd['@provision_link'] = url('admin/settings/provision');
$mkdir_cmd['@mkdir_cmd'] = <<<EOF
......@@ -118,7 +118,7 @@ function provision_apache_provision_configure($node = null) {
'#title' => t('Configuration path'),
'#required' => TRUE,
'#size' => 40,
'#default_value' => ($node->config_path) ? $node->config_path : _provision_config_path(),
'#default_value' => ($node->config_path) ? $node->config_path : PROVISION_CONFIG_PATH,
'#description' => t("The path on the server where configuration files will be stored.<br />
It is essential that this directory should not be accessible via a web browser."),
'#maxlength' => 255,
......@@ -129,7 +129,7 @@ function provision_apache_provision_configure($node = null) {
'#title' => t('Backup path'),
'#required' => TRUE,
'#size' => 40,
'#default_value' => ($node->backup_path) ? $node->backup_path : _provision_backup_path(),
'#default_value' => ($node->backup_path) ? $node->backup_path : PROVISION_BACKUP_PATH,
'#description' => t("The path on the server where backups will be stored.<br />
It is essential that this directory should not be accessible via a web browser."),
'#maxlength' => 255,
......@@ -221,7 +221,7 @@ function provision_apache_provision_synch($url, &$data) {
* Delete virtual host file
*/
function _provision_apache_delete_vhost_config($url, $data) {
provision_check_path(_provision_vhost_path() . "/$url", "unlink", true,
provision_check_path(PROVISION_VHOST_PATH . "/$url", "unlink", true,
t("Removed apache virtual host configuration"));
}
......@@ -233,12 +233,12 @@ function _provision_apache_create_vhost_config($url, $data, $template = null) {
$template = variable_get('provision_apache_vhost_template', _provision_apache_default_template());
}
provision_log("Notice", t("Generate virtual host configuration file."));
$writable = provision_check_path(_provision_vhost_path(), "writable", true ,
$writable = provision_check_path(PROVISION_VHOST_PATH, "writable", true ,
t("Virtual host configuration path is writable."),
t("Virtual host configuration path is not writable."),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
if ($writable) {
$file = fopen(_provision_vhost_path() . '/' . $url, "w");
$file = fopen(PROVISION_VHOST_PATH . '/' . $url, "w");
$text = provision_render_config($template, $data);
fwrite($file, $text);
fclose($file);
......@@ -260,27 +260,26 @@ function _provision_apache_restart_apache() {
}
function provision_apache_provision_verify() {
$path = _provision_vhost_path();
$exists = provision_check_path($path, "exists", true ,
$exists = provision_check_path(PROVISION_VHOST_PATH, "exists", true ,
t("Virtual Host configuration path exists."),
t("Virtual Host configuration path does not exist."));
if (!$exists) {
$made = provision_check_path($path, "mkdir", true,
$made = provision_check_path(PROVISION_VHOST_PATH, "mkdir", true,
t("Virtual host configuration path has been created."),
t("Virtual host configuration path could not be created."),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
}
else {
$writable = provision_check_path($path, "writable", true ,
$writable = provision_check_path(PROVISION_VHOST_PATH, "writable", true ,
t("Virtual host configuration path is writable."),
t("Virtual host configuration path is not writable."),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
if (!$writable) {
provision_check_path($path, "chown", provision_get_script_owner(),
provision_check_path(PROVISION_VHOST_PATH, "chown", provision_get_script_owner(),
t("Changed ownership of <code>%path</code>", array("%path" => $path)),
t("Could not change ownership <code>%path</code>", array("%path" => $path)),
PROVISION_PERM_ERROR);
provision_check_path($path, "chmod", 0700,
provision_check_path(PROVISION_VHOST_PATH, "chmod", 0700,
t("Changed permissions of <code>%path</code> to %perms", array("%path" => $path, '%perms' => 0700)),
t("Could not change ownership <code>%path</code> to %perms", array("%path" => $path, '%perms' => 0700)),
PROVISION_PERM_ERROR );
......
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