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

#269934 - ported site alias support from DRUPAL-5 branch

parents 996d36ba 497eec9e
......@@ -217,7 +217,6 @@ function provision_drupal_provision_restore_rollback($url, $data) {
provision_drupal_provision_restore($url, $data);
}
/**
* Force drupal to load the modules it expects to find on an uninstalled site
*
......@@ -520,6 +519,12 @@ function _provision_find_profiles() {
* This can't be rolled back. so won't even try.
*/
function provision_drupal_provision_delete($url, $data) {
if ($old_data = provision_load_site_data($url)) {
if (sizeof($old_aliases = $old_data['aliases'])) {
_provision_drupal_delete_aliases($old_aliases);
}
}
return _provision_recursive_delete("sites/$url");
}
......@@ -614,3 +619,41 @@ function _provision_drupal_variable_get($name, $default) {
return ($value) ? unserialize($value) : $default;
}
/**
* Create and remove symlinks for each of the possible domain aliases of an existing site
*/
function _provision_drupal_maintain_aliases($url, $data) {
if ($old_data = provision_load_site_data($url)) {
$old_aliases = $old_data['aliases'];
}
else {
$old_aliases = array();
}
// Flip the array to make it easier to remove duplicates
$old_aliases = array_flip($old_aliases);
if (is_array($data['aliases'])) {
foreach($data['aliases'] as $alias) {
if (isset($old_aliases[$alias])) {
// We have already created an alias for this site.
unset($old_aliases[$alias]);
}
provision_path("symlink", $url, PROVISION_DOCROOT_PATH . "/sites/" . $alias,
t("Created symlink for alias @alias", array("@alias" => $alias)),
t("Could not create symlink for alias @alias", array("@alias" => $alias)));
}
// Delete existing aliases that are no longer present
_provision_drupal_delete_aliases(array_keys($old_aliases));
}
}
/**
* Delete a list of aliases
*/
function _provision_drupal_delete_aliases($aliases) {
foreach ($aliases as $alias) {
provision_path("unlink", PROVISION_DOCROOT_PATH . "/sites/" . $alias, TRUE,
t("Removed symlink for alias @alias", array("@alias" => $alias)),
t("Could not remove symlink for alias @alias", array("@alias" => $alias)));
}
}
......@@ -294,10 +294,13 @@ function provision_get_site_data($url) {
$site_data['language'] = $site_data['language'] ? $site_data['language'] : 'en';
if ($old_data = provision_load_site_data($url)) {
//Merge previously saved data with the new data. This way, old parameters overwrite new ones.
//Merge previously saved data with the new data. This way, new parameters overwrite old ones.
$site_data = array_merge($old_data, $site_data);
}
if ($site_data['aliases']) {
$site_data['aliases'] = explode(",", $site_data['aliases']);
}
return $site_data;
}
......
......@@ -423,6 +423,7 @@ function _provision_install($url, &$data) {
_provision_drupal_switch_active_site($url); # Change headers and db info, also backs up
_provision_drupal_force_load_modules($url);
_provision_drupal_install_schema($url, $data['profile'], $data['language'], $data['client_email']);
_provision_drupal_maintain_aliases($url, $data); # Create symlinks for site aliases (if any)
_provision_drupal_force_load_modules();
_provision_drupal_switch_active_site(); # This *should* bring the site back to where we were before installing
......@@ -476,6 +477,7 @@ function _provision_synch($url = NULL) {
$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);
......
<VirtualHost *:80>
<?php if ($site_mail) : ?>
ServerAdmin <?php print $site_mail; ?>
<?php endif;?>
DocumentRoot <?php print $publish_path; ?>
<?php if ($site_mail) : ?>
ServerAdmin <?php print $site_mail; ?>
<?php endif;?>
DocumentRoot <?php print $publish_path; ?>
ServerName <?php print $site_url; ?>
ServerName <?php print $site_url; ?>
<?php if (is_array($site_aliases)) :
foreach ($site_aliases as $alias_url) : ?>
ServerAlias <?php print $alias_url; ?>
<?php
endforeach;
endif; ?>
<?php if (is_array($aliases)) :
foreach ($aliases as $alias_url) : ?>
ServerAlias <?php print $alias_url; ?>
<?php
endforeach;
endif; ?>
# Error handler for Drupal > 4.6.7
<Directory "<?php print $publish_path; ?>/sites/<?php print trim($site_url, '/'); ?>/files">
......
......@@ -10,9 +10,9 @@
# the ? at the end is to remove any query string in the original url
RewriteRule ^(.*)$ <?php print $redirect_url ?>?
<?php if (is_array($site_aliases)) :
foreach ($site_aliases as $alias_url) : ?>
ServerAlias <?php print $alias_url; ?>
<?php if (is_array($aliases)) :
foreach ($aliases as $alias) : ?>
ServerAlias <?php print $alias; ?>
<?php
endforeach;
endif; ?>
......
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