Commit 6921adf3 authored by drumm's avatar drumm Committed by Neil Drumm

Make it possible to write multiple name contexts to one file

parent 4f93d89a
......@@ -309,14 +309,15 @@ class provisionService_db extends provisionService {
* Write out server's drushrc alias file.
*/
function write_alias() {
$config = new provisionConfig_drushrc_alias(drush_get_option('hosting_name') . '-' . drush_get_option('init_db'), array('master_db'));
$config = new provisionConfig_drushrc_alias(array(
drush_get_option('hosting_name') . '-' . drush_get_option('init_db') => array(
'master_db',
),
));
$config->write();
}
}
/**
* Indicates the place holders that should be replaced in _db_query_callback().
*/
......
......@@ -128,7 +128,14 @@ class provisionService_http extends provisionService {
* Write out server's drushrc alias file.
*/
function write_alias() {
$config = new provisionConfig_drushrc_alias(drush_get_option('hosting_name') . '-' . drush_get_option('init_http'), array('web_host', 'web_ports', 'web_group', 'restart_cmd'));
$config = new provisionConfig_drushrc_alias(array(
drush_get_option('hosting_name') . '-' . drush_get_option('init_http') => array(
'web_host',
'web_ports',
'web_group',
'restart_cmd',
),
));
$config->write();
}
}
......@@ -123,8 +123,8 @@ class provisionConfig_drushrc extends provisionConfig {
function __construct($data = array()) {
parent::__construct($data);
$this->load_data();
}
function load_data() {
// we fetch the context to pass into the template based on the context name
$this->data = array_merge(drush_get_context($this->context_name), $this->data);
......@@ -137,34 +137,40 @@ class provisionConfig_drushrc extends provisionConfig {
}
}
// class to read and write an alias record
/**
* Class to write an alias records.
*/
class provisionConfig_drushrc_alias extends provisionConfig_drushrc {
public $template = 'provision_drushrc_alias.tpl.php';
function __construct($aliasname, $options = array()) {
$this->aliasname = $aliasname;
$data = array();
foreach ($options as $key) {
$data[$key] = drush_get_option($key);
/**
* 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.
*/
function __construct($contexts) {
$contexts_expanded = array();
foreach ($contexts as $name => $options) {
$contexts_expanded[$name] = array();
foreach ($options as $key) {
$contexts_expanded[$name][$key] = drush_get_option($key);
}
}
parent::__construct($data);
}
function load_data() {
$this->data = array(
'aliasname' => $this->aliasname,
'alias' => $this->data,
'aliasname' => reset(array_keys($contexts)),
'contexts' => $contexts_expanded,
);
}
function filename() {
return drush_get_option('alias-path', drush_server_home() . '/.drush/aliases/') . trim($this->aliasname, '@');
return drush_get_option('alias-path', drush_server_home() . '/.drush/aliases/') . trim($this->data['aliasname'], '@');
}
}
/**
* Server level config for drushrc.php files.
*/
......
......@@ -46,7 +46,12 @@ function provision_save_platform_data() {
$config->write();
// Save platform alias
$config = new provisionConfig_drushrc_alias(drush_get_option('hosting_name'), array('parent', 'publish_path'));
$config = new provisionConfig_drushrc_alias(array(
drush_get_option('hosting_name') => array(
'parent',
'publish_path',
),
));
$config->write();
}
}
......
<?php print "<?php \n"; ?>
$aliases['<?php print $aliasname; ?>'] = <?php print var_export($alias, TRUE); ?>;
<?php foreach ($contexts as $name => $data) { ?>
$aliases['<?php print $name; ?>'] = <?php print var_export($data, TRUE); ?>;
<?php } ?>
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