Commit 08a2964d authored by drumm's avatar drumm Committed by Neil Drumm

Get contect saveing working with OO

parent 7e91e62a
......@@ -267,7 +267,7 @@ class provisionService_db extends provisionService {
/**
* Write out server's drushrc alias file.
*/
function write_alias() {
function context_options() {
return array('provision-service-db', 'master_db');
}
}
......
<?php
class provisionService_http_cluster extends provisionService_http {
function write_alias() {
function context_options() {
return array('provision-http-cluster-web-servers');
}
}
......@@ -74,7 +74,7 @@ class provisionService_http extends provisionService {
/**
* Write out server's drushrc alias file.
*/
function write_alias() {
function context_options() {
return array('provision-service-http', 'web_ports', 'web_group', 'restart_cmd');
}
}
......@@ -144,12 +144,10 @@ class provisionConfig_drushrc_alias extends provisionConfig_drushrc {
public $template = 'provision_drushrc_alias.tpl.php';
/**
* An array of contexts to write. The first key will determine the title.
*
* @param $contexts
* An associative array of named contexts, like
* @code '\@name' => array('option1', 'option2'), @endcode
* will save the current values of option1 and option2 to @name.
* @param $name
* String '\@name' for named context.
* @param $options
* Array of string option names to save.
*/
function __construct($name, $options = array()) {
$options_expanded = array();
......@@ -158,7 +156,7 @@ class provisionConfig_drushrc_alias extends provisionConfig_drushrc {
}
$this->data = array(
'aliasname' => $name,
'aliasname' => ltrim($name, '@'),
'options' => $options_expanded,
);
}
......
......@@ -60,7 +60,7 @@ include_once('provision.inc');
* @see provision_load_critical()
*/
function provision_drush_init() {
d( drush_get_option('name', '@self', 'alias'), TRUE);
d(drush_get_option('hosting-name', '@self'), TRUE);
print_r(d());
$load = sys_getloadavg();
......@@ -217,23 +217,7 @@ function drush_provision_hostmaster_make($platform) {
}
function drush_http_provision_named_context_save() {
if (PROVISION_CONTEXT_SERVER) {
$options = array_merge(
array('provision-host', 'provision-user', 'config_path', 'backup_path'),
d()->services_invoke('write_alias')
);
$config = new provisionConfig_drushrc_alias(drush_get_option('hosting_name'), $options);
$config->write();
}
elseif (PROVISION_CONTEXT_PLATFORM) {
drush_set_option('platform-name', preg_replace('/^platform_/', '', drush_get_option('hosting_name')));
$config = new provisionConfig_drushrc_alias(drush_get_option('hosting_name'), array('provision-http-server', 'root', 'platform-name'));
$config->write();
}
elseif (PROVISION_CONTEXT_SITE) {
$config = new provisionConfig_drushrc_alias(drush_get_option('hosting_name'), array('provision-db-server', 'provision-platform', 'uri', 'site_port', 'site_id', 'language', 'client_email'));
$config->write();
}
d()->write_alias();
}
function drush_http_provision_named_context_delete() {
......
......@@ -9,11 +9,14 @@
* Store and access environment objects by their alias name
*
*/
function & d($name = '@self', $root_object = FALSE) {
function & d($name = NULL, $root_object = FALSE) {
static $instances = null;
static $default_instance = '@self';
if ($name) {
if (is_null($name)) {
return $instances[$default_instance];
}
else {
if ($root_object) {
$default_instance = $name;
}
......@@ -27,8 +30,6 @@ function & d($name = '@self', $root_object = FALSE) {
return $instances[$name];
}
}
return $instances[$default_instance];
}
/**
......@@ -164,6 +165,13 @@ class provisionEnvironment {
$this->map[$field] = $context;
}
/**
* Write out this named context to an alias file.
*/
function write_alias() {
$config = new provisionConfig_drushrc_alias($this->name, $this->context_options());
$config->write();
}
}
/**
......@@ -251,6 +259,16 @@ class provisionServer extends provisionEnvironment {
}
return $return;
}
/**
* Options this environment will save in its context file.
*/
function context_options() {
return array_merge(
array('provision-host', 'provision-user', 'config_path', 'backup_path'),
d()->services_invoke('context_options')
);
}
}
/**
......@@ -258,9 +276,7 @@ class provisionServer extends provisionEnvironment {
*/
class provisionPlatform extends provisionServer {
public static function evaluate($options) {
if ($options['root']) {
return true;
}
return isset($options['root']);
}
function init() {
......@@ -273,10 +289,17 @@ class provisionPlatform extends provisionServer {
$this->setProperty('sites_path', $this->root . '/sites');
}
/**
* Options this environment will save in its context file.
*/
function context_options() {
drush_set_option('platform-name', preg_replace('/^platform_/', '', drush_get_option('hosting_name')));
return array('provision-http-server', 'root', 'platform-name');
}
}
class provisionSite extends provisionPlatform {
public static function evaluate($options) {
if ($options['uri']) {
return true;
......@@ -292,7 +315,6 @@ class provisionSite extends provisionPlatform {
$this->setProperty('aliases', array());
$this->setProperty('site_port', 80);
$this->setProperty('client_email');
// todo - turn into a re-usable mechanism for comma separated values
......@@ -303,10 +325,15 @@ class provisionSite extends provisionPlatform {
$this->aliases = array();
}
// this can potentially be handled by a drupal sub class
$this->setProperty('profile', 'default');
}
/**
* Options this environment will save in its context file.
*/
function context_options() {
return array('provision-db-server', 'provision-platform', 'uri', 'site_port', 'site_id', 'language', 'client_email');
}
}
......
......@@ -105,7 +105,7 @@ class provisionService {
return $this;
}
function write_alias() {
function context_options() {
return array();
}
}
......
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