Commit 2e916fbd authored by omega8cc's avatar omega8cc

Remove legacy subdir code and update checks.

parent 3c9a4d0d
......@@ -48,8 +48,12 @@ print "<?php \n"; ?>
$aliases = d()->aliases;
// Fix our subdir aliases.
foreach ($aliases as $alias) {
$records[str_replace('/', '.', $alias)] = $records[$alias];
unset($records[$alias]);
// Only replace the records[] array key if the alias is a subdir alias
// Patch for https://drupal.org/node/2213387
if(strpos($alias, "/")) {
$records[str_replace('/', '.', $alias)] = $records[$alias];
unset($records[$alias]);
}
}
?>
$sites = <?php print var_export($records, TRUE) ?>;
......@@ -86,7 +86,14 @@ if ($this->redirection || $ssl_redirection) {
<?php
$if_subsite = $this->data['http_subdird_path'] . '/' . $this->uri;
if (subdirs_drush_load() && provision_file()->exists($if_subsite)->status()) {
$if_subdirs = drush_get_option('hosting_features', array());
if ((array_key_exists('subdirs', $if_subdirs) && $if_subdirs['subdirs'])) {
$subdirs_support = TRUE;
}
else {
$subdirs_support = FALSE;
}
if ($subdirs_support && provision_file()->exists($if_subsite)->status()) {
print " Include " . $if_subsite . "/*.conf\n";
}
?>
......
......@@ -48,8 +48,12 @@ print "<?php \n"; ?>
$aliases = d()->aliases;
// Fix our subdir aliases.
foreach ($aliases as $alias) {
$records[str_replace('/', '.', $alias)] = $records[$alias];
unset($records[$alias]);
// Only replace the records[] array key if the alias is a subdir alias
// Patch for https://drupal.org/node/2213387
if(strpos($alias, "/")) {
$records[str_replace('/', '.', $alias)] = $records[$alias];
unset($records[$alias]);
}
}
?>
$sites = <?php print var_export($records, TRUE) ?>;
......@@ -68,7 +68,14 @@ else {
print " include " . $server->include_path . "/nginx_vhost_common.conf;\n";
}
$if_subsite = $this->data['http_subdird_path'] . '/' . $this->uri;
if (subdirs_drush_load() && provision_file()->exists($if_subsite)->status()) {
$if_subdirs = drush_get_option('hosting_features', array());
if ((array_key_exists('subdirs', $if_subdirs) && $if_subdirs['subdirs'])) {
$subdirs_support = TRUE;
}
else {
$subdirs_support = FALSE;
}
if ($subdirs_support && provision_file()->exists($if_subsite)->status()) {
print " include " . $if_subsite . "/*.conf;\n";
}
?>
......
......@@ -17,8 +17,14 @@ class Provision_Service_http_apache extends Provision_Service_http_public {
$this->configs['server'][] = 'Provision_Config_Apache_Server';
$this->configs['platform'][] = 'Provision_Config_Apache_Platform';
$this->configs['site'][] = 'Provision_Config_Apache_Site';
$features = drush_get_option('hosting_features', array());
if (array_key_exists('subdirs', $features) && $features['subdirs']) {
$if_subdirs = drush_get_option('hosting_features', array());
if ((array_key_exists('subdirs', $if_subdirs) && $if_subdirs['subdirs'])) {
$subdirs_support = TRUE;
}
else {
$subdirs_support = FALSE;
}
if ($subdirs_support) {
$this->configs['site'][] = 'Provision_Config_Apache_Subdir';
$this->configs['site'][] = 'Provision_Config_Apache_SubdirVhost';
}
......
......@@ -22,13 +22,26 @@ class Provision_Service_http_nginx extends Provision_Service_http_public {
$this->server->setProperty('nginx_has_gzip', FALSE);
$this->server->setProperty('provision_db_cloaking', TRUE);
$this->server->setProperty('phpfpm_mode', 'port');
if (subdirs_drush_load()) {
$this->server->setProperty('subdirs_support', FALSE);
$if_subdirs = drush_get_option('hosting_features', array());
if ((array_key_exists('subdirs', $if_subdirs) && $if_subdirs['subdirs'])) {
$subdirs_support = TRUE;
}
else {
$subdirs_support = FALSE;
}
if ($subdirs_support) {
$this->server->subdirs_support = TRUE;
$this->configs['site'][] = 'Provision_Config_Nginx_Subdir';
$this->configs['site'][] = 'Provision_Config_Nginx_SubdirVhost';
}
}
function save_server() {
// Set correct provision_db_cloaking value on server save.
$this->server->provision_db_cloaking = TRUE;
// Find nginx executable.
if (provision_file()->exists('/usr/local/sbin/nginx')->status()) {
$path = "/usr/local/sbin/nginx";
......@@ -42,6 +55,7 @@ class Provision_Service_http_nginx extends Provision_Service_http_public {
else {
return;
}
// Check if some nginx features are supported and save them for later.
$this->server->shell_exec($path . ' -V');
$this->server->nginx_is_modern = preg_match("/nginx\/1\.((1\.(8|9|(1[0-9]+)))|((2|3|4|5|6|7|8|9)\.))/", implode('', drush_shell_exec_output()), $match);
......@@ -67,9 +81,25 @@ class Provision_Service_http_nginx extends Provision_Service_http_public {
$this->server->phpfpm_mode = 'port';
drush_log(dt('PHP-FPM port mode detected -SAVE- NO socket found @path.', array('@path' => '/var/run/php5-fpm.sock')));
}
// Set correct subdirs_support value on server save
$if_subdirs = drush_get_option('hosting_features', array());
if ((array_key_exists('subdirs', $if_subdirs) && $if_subdirs['subdirs'])) {
$subdirs_support = TRUE;
}
else {
$subdirs_support = FALSE;
}
if ($subdirs_support) {
$this->server->subdirs_support = TRUE;
}
}
function verify_server_cmd() {
// Set correct provision_db_cloaking value on server verify.
$this->server->provision_db_cloaking = TRUE;
// Find nginx executable.
if (provision_file()->exists('/usr/local/sbin/nginx')->status()) {
$path = "/usr/local/sbin/nginx";
......@@ -109,6 +139,18 @@ class Provision_Service_http_nginx extends Provision_Service_http_public {
drush_log(dt('PHP-FPM port mode detected -VERIFY- NO socket found @path.', array('@path' => '/var/run/php5-fpm.sock')));
}
// Set correct subdirs_support value on server verify
$if_subdirs = drush_get_option('hosting_features', array());
if ((array_key_exists('subdirs', $if_subdirs) && $if_subdirs['subdirs'])) {
$subdirs_support = TRUE;
}
else {
$subdirs_support = FALSE;
}
if ($subdirs_support) {
$this->server->subdirs_support = TRUE;
}
// Call the parent at the end. it will restart the server when it finishes.
parent::verify_server_cmd();
}
......
<VirtualHost *:<?php print $http_port; ?>>
ServerName <?php print $uri; ?>
Include <?php print $subdirs_path; ?>/<?php print $uri; ?>/*.conf
</VirtualHost>
<?php
/**
* @file
* Template file to generate a D7 style sites.php for subdirectories.
*/
print "<?php \n"; ?>
/**
* @file
* Configuration file for Drupal's multi-site directory aliasing feature.
*
* Drupal searches for an appropriate configuration directory based on the
* website's hostname and pathname. A detailed description of the rules for
* discovering the configuration directory can be found in the comment
* documentation in 'sites/default/default.settings.php'.
*
* This file allows you to define a set of aliases that map hostnames and
* pathnames to configuration directories. These aliases are loaded prior to
* scanning for directories, and they are exempt from the normal discovery
* rules. The aliases are defined in an associative array named $sites, which
* should look similar to the following:
*
* $sites = array(
* 'devexample.com' => 'example.com',
* 'localhost.example' => 'example.com',
* );
*
* The above array will cause Drupal to look for a directory named
* "example.com" in the sites directory whenever a request comes from
* "example.com", "devexample.com", or "localhost/example". That is useful
* on development servers, where the domain name may not be the same as the
* domain of the live server. Since Drupal stores file paths into the database
* (files, system table, etc.) this will ensure the paths are correct while
* accessed on development servers.
*
* To use this file, copy and rename it such that its path plus filename is
* 'sites/sites.php'. If you don't need to use multi-site directory aliasing,
* then you can safely ignore this file, and Drupal will ignore it too.
*/
/**
* Multi-site directory aliasing:
*
* Edit the lines below to define directory aliases. Remove the leading hash
* signs to enable.
*/
<?php
$aliases = d()->aliases;
// Fix our subdir aliases.
foreach ($aliases as $alias) {
// Only replace the records[] array key if the alias is a subdir alias
// Patch for https://drupal.org/node/2213387
if(strpos($alias, "/")) {
$records[str_replace('/', '.', $alias)] = $records[$alias];
unset($records[$alias]);
}
}
?>
$sites = <?php print var_export($records, TRUE) ?>;
<?php
/**
* Implements hook_drush_init().
*/
function subdirs_drush_init() {
subdirs_provision_register_autoload();
}
/**
* Register our directory as a place to find Provision classes.
*
* This allows Provision to autoload our classes, so that we don't need to
* specifically include the files before we use the class.
*/
function subdirs_provision_register_autoload() {
static $loaded = FALSE;
if (!$loaded) {
$loaded = TRUE;
provision_autoload_register_prefix('Provision_', dirname(__FILE__));
}
}
/**
* Implements drush_hook_pre_provision_install().
*/
function drush_subdirs_pre_provision_install() {
_subdirs_create_symlinks();
}
/**
* Implements drush_hook_pre_provision_install_rollback().
*/
function drush_subdirs_pre_provision_install_rollback() {
_subdirs_remove_symlinks();
}
/**
* Implementation of drush_hook_pre_provision_verify()
*/
function drush_subdirs_pre_provision_verify() {
_subdirs_create_symlinks();
}
/**
* Implementation of drush_hook_post_provision_deploy()
*/
function drush_subdirs_pre_provision_deploy() {
_subdirs_create_symlinks();
}
/**
* Implementation of drush_hook_provision_delete()
*/
function drush_subdirs_pre_provision_delete() {
_subdirs_remove_symlinks();
}
/**
* Implements hook_provision_config_load_templates().
*/
function subdirs_provision_config_load_templates($config) {
if ($config->template == 'provision_drupal_sites.tpl.php') {
$context = d();
$use_subdirs_tpl = FALSE;
foreach ($context->aliases as $alias) {
if (strpos($alias, '/')) {
$use_subdirs_tpl = TRUE;
}
}
if ($use_subdirs_tpl) {
drush_log('Generating sites.php for use with subdirectories.', 'notice');
return dirname(__FILE__) . '/Provision/Config/subdirs_drupal_sites.tpl.php';
}
}
}
/**
* Create subdirectory symlinks
*
* This create a sites/example.com.foo symlink pointing to the main
* URL of the site.
*/
function _subdirs_create_symlinks() {
if (d()->type == 'site') {
$aliases = d()->aliases;
if (count($aliases)) {
foreach ($aliases as $alias) {
if (strpos($alias, '/')) {
drush_log("Subdirectory alias `$alias` found. Creating magic symlinks.", 'notice');
provision_file()->symlink(d()->uri, 'sites/' . str_replace('/', '.', $alias))
->succeed('symlinked @path to @target')
->fail('failed to symlink @path to @target');
}
}
}
}
}
/**
* Delete subdirectory symlinks
*
* This deletes the symlinks created by _subdirs_create_symlinks().
*/
function _subdirs_remove_symlinks() {
if (d()->type == 'site') {
$aliases = d()->aliases;
if (count($aliases)) {
foreach ($aliases as $alias) {
provision_file()->unlink('sites/' . str_replace('/', '.', $alias))
->succeed('removed @path symlink')
->fail('failed to remove @path symlink');
}
}
}
}
<?php
/**
* Implements hook_drush_load().
*
* Checks if the corresponsing Hosting Feature is installed and enabled.
*/
function subdirs_drush_load() {
$features = drush_get_option('hosting_features', array());
return array_key_exists('subdirs', $features) && $features['subdirs'];
}
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