Commit 595dccd2 authored by anarcat's avatar anarcat

move subdir vhost generation to the service

parent 2fbfcb19
<?php
/**
* Base class for subdir support.
*
* This class will publish the config files to remote
* servers automatically.
*/
class Provision_Config_Apache_SubdirVhost extends Provision_Config_Http {
public $template = 'subdir_vhost.tpl.php';
public $description = 'subdirectory support';
/**
* Guess the URI this subdir alias is related too.
*/
function uri() {
return explode('/', $this->current_alias, 2)[0];
}
/**
* Guess the subdir part of the subdir alias.
*/
function subdir() {
return explode('/', $this->current_alias, 2)[1];
}
function process() {
parent::process();
$this->data['uri'] = $this->uri();
$this->data['subdir'] = $this->subdir();
$this->data['subdirs_path'] = $this->data['http_subdird_path'] . '/' . $this->uri() . '/';
}
function filename() {
return $this->data['http_subdird_path'] . '/' . $this->uri() . '/' . $this->subdir() . '.conf';
}
}
...@@ -18,6 +18,7 @@ class Provision_Service_http_apache extends Provision_Service_http_public { ...@@ -18,6 +18,7 @@ class Provision_Service_http_apache extends Provision_Service_http_public {
$this->configs['platform'][] = 'Provision_Config_Apache_Platform'; $this->configs['platform'][] = 'Provision_Config_Apache_Platform';
$this->configs['site'][] = 'Provision_Config_Apache_Site'; $this->configs['site'][] = 'Provision_Config_Apache_Site';
$this->configs['site'][] = 'Provision_Config_Apache_Subdir'; $this->configs['site'][] = 'Provision_Config_Apache_Subdir';
$this->configs['site'][] = 'Provision_Config_Apache_SubdirVhost';
} }
/** /**
......
...@@ -86,7 +86,6 @@ function _subdirs_create_site_configs() { ...@@ -86,7 +86,6 @@ function _subdirs_create_site_configs() {
foreach ($aliases as $alias) { foreach ($aliases as $alias) {
if (strpos($alias, '/')) { if (strpos($alias, '/')) {
drush_log("Subdirectory alias `$alias` found. Creating configuration files.", 'notice'); drush_log("Subdirectory alias `$alias` found. Creating configuration files.", 'notice');
_subdirs_create_domain_vhost($alias);
_subdirs_create_symlinks($alias, d()->uri); _subdirs_create_symlinks($alias, d()->uri);
} }
} }
...@@ -109,7 +108,6 @@ function _subdirs_remove_site_configs() { ...@@ -109,7 +108,6 @@ function _subdirs_remove_site_configs() {
$includes_path = $subdirs_path . '/' . $alias_parts[0]; $includes_path = $subdirs_path . '/' . $alias_parts[0];
if ($handle = opendir($includes_path)) { if ($handle = opendir($includes_path)) {
if (FALSE === readdir($handle)) { if (FALSE === readdir($handle)) {
_subdirs_delete_domain_vhost($alias);
_subdirs_delete_symlinks($alias); _subdirs_delete_symlinks($alias);
} }
} }
...@@ -117,50 +115,6 @@ function _subdirs_remove_site_configs() { ...@@ -117,50 +115,6 @@ function _subdirs_remove_site_configs() {
} }
} }
/**
* Create the vhost for the subdirectory domain.
*/
function _subdirs_create_domain_vhost($alias) {
$alias_parts = explode('/', $alias, 2);
$context = d();
// Generate variables to pass to template
$variables = array(
'http_port' => $context->server->http_port,
'subdirs_path' => $context->server->http_app_path . '/subdirs.d',
'uri' => $alias_parts[0],
);
$output = _subdirs_render_template('domain_vhost.tpl.php', $variables);
$domain_vhost_path = $context->server->http_vhostd_path . '/' . $alias_parts[0];
if (fwrite(fopen($domain_vhost_path, 'w'), $output)) {
drush_log('Created domain vhost for subdirectory ' . $alias . ' at ' . $domain_vhost_path, 'success');
}
else {
drush_log('Error encountered attempting to create domain vhost for subdirectory ' . $alias, 'error');
}
}
/**
* Delete the vhost for the subdirectory domain.
*/
function _subdirs_delete_domain_vhost($alias) {
$alias_parts = explode('/', $alias, 2);
$context = d();
$domain_vhost_path = $context->server->http_vhostd_path . '/' . $alias_parts[0];
if (unlink($domain_vhost_path)) {
drush_log('Deleted domain vhost for subdirectory ' . $alias, 'success');
}
else {
drush_log('Error encountered attempting to delete domain vhost for subdirectory ' . $alias, 'error');
}
}
/** /**
* Create subdirectory symlinks * Create subdirectory symlinks
...@@ -184,20 +138,3 @@ function _subdirs_delete_symlinks($alias) { ...@@ -184,20 +138,3 @@ function _subdirs_delete_symlinks($alias) {
->succeed('removed @path symlink') ->succeed('removed @path symlink')
->fail('failed to remove @path symlink'); ->fail('failed to remove @path symlink');
} }
/**
* Render our config file templates.
*/
function _subdirs_render_template($template, $variables) {
// TODO: Remove this, once we've got a working Config class.
$template_path = dirname(__FILE__) . '/Provision/Config/' . $template;
extract($variables);
ob_start();
include $template_path;
$content = ob_get_clean();
return $content;
}
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