Commit c4dae0c9 authored by Adrian Rossouw's avatar Adrian Rossouw

Change the configuration classes so that they have an 'owner', and generate

the configuration based on the properties of their owner.

Get rid of the publish_path variable , which is replaced now by $this->root/d()->root;

work on some of the context stuff in provision_drupal.
parent 1e94e907
......@@ -20,34 +20,34 @@ class provisionService_http_apache extends provisionService_http {
}
function create_site_config() {
$config = new provisionConfig_apache_site(drush_get_merged_options());
$config = new provisionConfig_apache_site($this->context);
return $config->write();
}
function delete_site_config() {
$config = new provisionConfig_apache_site(drush_get_merged_options());
$config = new provisionConfig_apache_site($this->context);
return $config->unlink();
}
function create_platform_config() {
$config = new provisionConfig_apache_platform(array('d' => d()));
$config = new provisionConfig_apache_platform($this->context);
return $config->write();
}
function delete_platform_config() {
$config = new provisionConfig_apache_platform(drush_get_merged_options());
$config = new provisionConfig_apache_platform($this->context);
return $config->unlink();
}
function create_server_config() {
$config = new provisionConfig_apache_server(array('d' => d()));
$config = new provisionConfig_apache_server($this->context);
return $config->write();
}
function delete_server_config() {
$config = new provisionConfig_apache_server(drush_get_merged_options());
$config = new provisionConfig_apache_server($this->context);
return $config->unlink();
}
......@@ -111,7 +111,7 @@ class provisionConfig_apache_server extends provisionConfig_apache {
public $description = 'apache server configuration file';
function filename() {
return $this->data['d']->config_path . '/' . 'apache.conf';
return $this->config_path . '/' . 'apache.conf';
}
function process() {
......@@ -125,7 +125,7 @@ class provisionConfig_apache_platform extends provisionConfig_apache {
public $description = 'apache platform configuration file';
function filename() {
return $this->data['d']->server->apache_platform_conf_path . '/' . ltrim($this->data['d']->getName(), '@') . '.conf';
return $this->server->apache_platform_conf_path . '/' . ltrim($this->owner, '@') . '.conf';
}
function process() {
......
<Directory <?php print $d->root; ?>>
<Directory <?php print $this->root; ?>>
Order allow,deny
Allow from all
<?php print $extra_config; ?>
......
# Aegir web server configuration file
<?php if (is_array($d->web_ports)) :
foreach ($d->web_ports as $web_port) :?>
<?php if (is_array($this->web_ports)) :
foreach ($this->web_ports as $web_port) :?>
NameVirtualHost *:<?php print $web_port; ?>
<VirtualHost *:<?php print $web_port; ?>>
......@@ -23,13 +23,13 @@ endif;
</IfModule>
# virtual hosts
Include <?php print $d->apache_site_conf_path ?>
Include <?php print $this->apache_site_conf_path ?>
# platforms
Include <?php print $d->apache_platform_conf_path ?>
Include <?php print $this->apache_platform_conf_path ?>
# other configuration, not touched by aegir
Include <?php print $d->apache_conf_path ?>
Include <?php print $this->apache_conf_path ?>
<?php print $extra_config; ?>
......@@ -2,7 +2,7 @@
<?php if ($site_mail) : ?>
ServerAdmin <?php print $site_mail; ?>
<?php endif;?>
DocumentRoot <?php print $publish_path; ?>
DocumentRoot <?php print $this->platform->root; ?>
ServerName <?php print $site_url; ?>
......@@ -29,13 +29,10 @@
<?php print $extra_config; ?>
# Error handler for Drupal > 4.6.7
<Directory "<?php print $publish_path; ?>/sites/<?php print trim($site_url, '/'); ?>/files">
<Directory "<?php print $this->platform->root; ?>/sites/<?php print trim($site_url, '/'); ?>/files">
SetHandler This_is_a_Drupal_security_line_do_not_remove
</Directory>
# @todo make this configurable and more intelligent
# php_admin_value open_basedir /tmp:<?php print rtrim($publish_path, '/') ?>/:<?php print rtrim($config_path, '/') ?>/includes/:/usr/share/php/
</VirtualHost>
<?php
......
......@@ -2,7 +2,7 @@
<?php if ($site_mail) : ?>
ServerAdmin <?php print $site_mail; ?>
<?php endif;?>
DocumentRoot <?php print $publish_path; ?>
DocumentRoot <?php print $this->platform->root; ?>
ServerName <?php print $site_url; ?>
......
......@@ -16,7 +16,7 @@ function drush_provision_hostmaster_migrate_validate($site, $platform) {
}
$data = drush_get_merged_options();
$data['publish_path'] = $data['r'] = $data['root'] = realpath($platform);
$data['r'] = $data['root'] = realpath($platform);
drush_backend_invoke('provision-verify', $data);
// verify the current platform
drush_backend_invoke('provision-verify', array('root' => drush_get_option(array('r', 'root'), drush_locate_root())));
......
......@@ -69,7 +69,7 @@ function _provision_context_init() {
// define('PROVISION_CONTEXT_SITE', (d()->type == 'site') ? TRUE : FALSE);
// define('PROVISION_CONTEXT_PLATFORM', !PROVISION_CONTEXT_SITE);
$context = drush_get_option('provision-context');
$context = d()->type;
if (($context === 'platform' || $context === 'site') && drush_bootstrap_validate(DRUSH_BOOTSTRAP_DRUPAL_ROOT)) {
// i don't think i should be bootstrapping here yet ... but i have no choice yet.
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_ROOT);
......@@ -107,7 +107,7 @@ function provision_drupal_drush_exit() {
drush_set_option('site_url', drush_get_option('site_url'), 'site');
drush_set_option('site_id', drush_get_option('site_id'), 'site');
drush_set_option('client_email', drush_get_option('client_email'), 'site');
provision_save_site_data();
// provision_save_site_data();
}
}
elseif (PROVISION_CONTEXT_PLATFORM) {
......@@ -117,7 +117,7 @@ function provision_drupal_drush_exit() {
}
}
elseif (PROVISION_CONTEXT_SERVER) {
provision_save_server_data();
// provision_save_server_data();
}
}
}
......
......@@ -26,18 +26,18 @@ function drush_provision_drupal_provision_verify_validate() {
*/
function drush_provision_drupal_provision_verify() {
if (PROVISION_CONTEXT_SERVER) {
provision_service('file')->create_dir(drush_get_option('config_path'), dt('Provision configuration'), 0711);
provision_service('file')->create_dir(drush_get_option('config_path') . '/includes', dt('Provision PHP configuration'), 0711);
if (!provision_service('file')->exists(drush_get_option('config_path') . '/includes/global.inc')->succeed('Global configuration file exists')->status()) {
provision_service('file')->create_dir(d()->config_path, dt('Provision configuration'), 0711);
provision_service('file')->create_dir(d()->config_path . '/includes', dt('Provision PHP configuration'), 0711);
if (!provision_service('file')->exists(d()->config_path . '/includes/global.inc')->succeed('Global configuration file exists')->status()) {
// Create an empty global.inc so the include doesn't fail with
// open_basedir restrictions
$config = new provisionConfig_global_settings(drush_get_merged_options());
$config = new provisionConfig_global_settings(d()->name);
$config->write();
}
provision_service('file')->create_dir(drush_get_option('backup_path'), dt('Backup'), 0700);
provision_service('file')->create_dir(d()->backup_path, dt('Backup'), 0700);
}
elseif (PROVISION_CONTEXT_PLATFORM) {
provision_service('file')->writable(drush_get_option('sites_path'))
provision_service('file')->writable(d()->sites_path)
->succeed('Drupal sites directory @path is writable by the provisioning script')
->fail('Drupal sites directory @path is not writable by the provisioning script', 'PROVISION_SITES_DIR_NOT_WRITABLE');
......@@ -61,7 +61,7 @@ class provisionConfig_global_settings extends provisionConfig {
public $description = 'Global settings.php file';
function filename() {
return $this->data['config_path'] . '/includes/global.inc';
return $this->config_path . '/includes/global.inc';
}
function process() {
......
......@@ -9,18 +9,26 @@
class provisionConfig {
public $template = null;
public $data = array();
public $owner = null;
public $description = null;
protected $append = FALSE;
protected $mode = NULL;
protected $group = NULL;
function __construct($data = array()) {
function __get($name) {
if ($this->owner) {
return d($this->owner)->$name;
}
}
function __construct($owner, $data = array()) {
if (is_null($this->template)) {
throw(exception);
}
if (sizeof($data)) {
$this->data = $data;
}
$this->owner = $owner;
}
function process() {
......@@ -61,7 +69,6 @@ class provisionConfig {
function write() {
$filename = $this->filename();
// Make directory structure if it does not exist.
if (!provision_service('file')->exists(dirname($filename))->status()) {
provision_service('file')->mkdir(dirname($filename))
......@@ -120,8 +127,8 @@ class provisionConfig_drushrc extends provisionConfig {
return _drush_config_file($this->context_name);
}
function __construct($data = array()) {
parent::__construct($data);
function __construct($owner, $data = array()) {
parent::__construct($owner, $data);
$this->load_data();
}
......@@ -149,9 +156,10 @@ class provisionConfig_drushrc_alias extends provisionConfig_drushrc {
* @param $options
* Array of string option names to save.
*/
function __construct($name, $options = array()) {
function __construct($owner, $options = array()) {
$this->owner = $owner;
$this->data = array(
'aliasname' => ltrim($name, '@'),
'aliasname' => ltrim($owner, '@'),
'options' => $options,
);
}
......
......@@ -52,18 +52,14 @@ function provision_environment_factory($name) {
* Contains magic getter/setter functions
*/
class provisionEnvironment {
protected $name = null;
public $name = null;
public $type = null;
protected $properties = array();
protected $parent_key = null;
public $type = null;
protected $oid_map = array();
function getName() {
return $this->name;
}
/**
* Retrieve value from $properties array if property does not exist in class proper.
*
......@@ -85,6 +81,9 @@ class provisionEnvironment {
}
}
/**
* Specify that a property contains a named context.
*/
function is_oid($name) {
$this->oid_map[$name] = TRUE;
}
......@@ -159,9 +158,9 @@ class provisionEnvironment {
$config->write();
}
function service($service) {
function service($service, $name = null) {
if (!is_null($this->parent_key)) {
return $this->{$this->parent_key}->service($service);
return $this->{$this->parent_key}->service($service, ($name) ? $name : $this->name);
}
else {
return new provisionService_null($this->name);
......@@ -212,8 +211,7 @@ class provisionServer extends provisionEnvironment {
$this->setProperty('remote_host', 'localhost');
$this->setProperty('script_user', get_current_user());
$this->setProperty('aegir_root', '/var/aegir');
$this->setProperty('backup_path', $this->aegir_root . '/backup');
$this->setProperty('backup_path', $this->aegir_root . '/backups');
$this->setProperty('config_path', $this->aegir_root . '/config');
$this->setProperty('alias_path', $this->config_path . '/drush.d');
$this->setProperty('master_url');
......@@ -260,7 +258,8 @@ class provisionServer extends provisionEnvironment {
/**
* Retrieve a service of a specific type from the environment.
*/
function service($service) {
function service($service, $name = null) {
$this->services[$service]->context = ($name) ? $name : $this->name;
return $this->services[$service];
}
......@@ -273,8 +272,8 @@ class provisionServer extends provisionEnvironment {
* An array of return values from method implementations.
*/
function services_invoke($callback) {
foreach ($this->services as $service) {
$service->$callback();
foreach (array_keys($this->services) as $service) {
$this->service($service)->$callback();
}
}
......@@ -301,7 +300,6 @@ class provisionPlatform extends provisionEnvironment {
$this->setProperty('root', $_SERVER['PWD']);
// publish path can really be removed ...
$this->setProperty('publish_path', $this->root);
$this->setProperty('sites_path', $this->root . '/sites');
$this->setProperty('server', '@server_localhost');
......@@ -312,7 +310,7 @@ class provisionPlatform extends provisionEnvironment {
}
function verify() {
$this->server->verify();
$this->service('http')->verify();
}
}
......
......@@ -33,11 +33,31 @@ drush_errors_on();
*/
function provision_save_server_data() {
if (!drush_get_error()) {
$config = new provisionConfig_drushrc_server();
$config = new provisionConfig_drushrc_server(d()->name);
$config->write();
}
}
function provision_save_site_data() {
if (!drush_get_error()) {
$config = new provisionConfig_drushrc_site(d()->name);
$config->write();
}
}
/**
* Save modified options to the drushrc.php file
*/
function provision_save_platform_data() {
if (!drush_get_error()) {
$config = new provisionConfig_drushrc_platform(d()->name);
$config->write();
}
}
/**
* @} End of "defgroup sitedata".
*/
......
......@@ -3,29 +3,30 @@
include_once('provision.config.inc');
class provisionService {
protected $owner = '@self';
protected $server = '@self';
public $context;
protected $last_status;
protected $tokens;
function __get($name) {
return d($this->owner)->$name;
return d($this->server)->$name;
}
function __set($name, $value) {
d($this->owner)->$name = $value;
d($this->server)->$name = $value;
}
function __isset($name) {
return isset(d($this->owner)->$name);
return isset(d($this->server)->$name);
}
function __unset($name) {
unset(d($this->owner)->$name);
unset(d($this->server)->$name);
}
function __construct($owner) {
$this->owner = $owner;
function __construct($server) {
$this->server = $server;
}
function verify() {
......@@ -37,7 +38,7 @@ class provisionService {
}
function setProperty($field, $default = null) {
d($this->owner)->setProperty($field, $default);
d($this->server)->setProperty($field, $default);
}
/**
......
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