Commit e5945277 authored by Adrian Rossouw's avatar Adrian Rossouw

modified the provisionConfig_drushrc to take over from the drush_save_config...

modified the provisionConfig_drushrc to take over from the drush_save_config function entirely, so we can instance specific classes based on which templates we want to write..

this will be useful as a base for alias writing.
parent 5b5b8dc7
......@@ -88,27 +88,7 @@ function provision_drupal_drush_exit($url = NULL) {
else {
// Generate a drushrc.php for the platform unless it's being deleted
if (!preg_match("/^provision-delete/", $command[0])) {
$exists = provision_service('file')->exists(drush_get_option('docroot_path') . '/drushrc.php')
->succeed('Found existing drushrc.php file')
->fail('Generating drushrc.php file')
->status();
if ($exists) {
provision_service('file')->chmod(drush_get_option('docroot_path') . '/drushrc.php', 0600)
->succeed('Changed permissions of drushrc.php to @perm')
->fail('Could not change permissions of drushrc.php to @perm');
}
drush_set_option('context-path', drush_get_option('context-path', null, 'drupal'));
drush_unset_option('context-path', 'drupal');
drush_set_option('config-file', drush_get_option('config-file', null, 'drupal'));
drush_unset_option('config-file', 'drupal');
drush_save_config('drupal');
provision_service('file')->chmod(drush_get_option('docroot_path') . '/drushrc.php', 0400)
->succeed('Changed permissions of drushrc.php to @perm')
->fail('Could not change permissions of drushrc.php to @perm');
provision_save_platform_data();
}
}
}
......
......@@ -95,3 +95,51 @@ class provisionConfig {
return provision_service('file')->unlink($this->filename())->status();
}
}
/**
* Specialized class to handle the creation of drushrc.php files.
*
* This is based on the drush_save_config code, but has been abstracted
* for our purposes.
*/
class provisionConfig_drushrc extends provisionConfig {
public $template = 'provision_drushrc.tpl.php';
public $description = 'Drush configuration file';
protected $mode = 0400;
protected $context_name = 'drush';
function filename() {
return _drush_config_file($this->context_name);
}
function __construct($data = array()) {
parent::__construct($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);
}
function process() {
unset($this->data['context-path']);
unset($this->data['config-file']);
$this->data['option_keys'] = array_keys($this->data);
}
}
/**
* Class for writing $platform/drushrc.php files.
*/
class provisionConfig_drushrc_platform extends provisionConfig_drushrc {
protected $context_name = 'drupal';
public $description = 'Platform Drush configuration file';
}
/**
* Class for writing $platform/sites/$url/drushrc.php files.
*/
class provisionConfig_drushrc_site extends provisionConfig_drushrc {
protected $context_name = 'site';
public $template = 'provision_drushrc_site.tpl.php';
public $description = 'Site Drush configuration file';
}
......@@ -30,33 +30,20 @@ drush_errors_on();
* Save modified options to the drushrc.php file
*/
function provision_save_site_data() {
$context = 'site';
drush_set_option('context-path', drush_get_option('context-path', null, 'site'));
drush_unset_option('context-path', 'site');
drush_set_option('config-file', drush_get_option('config-file', null, 'site'));
drush_unset_option('config-file', 'site');
drush_save_config($context);
drush_set_option('config-file', _drush_config_file('site'));
if (!drush_get_error()) {
$config = new provisionConfig_drushrc(drush_get_merged_options());
$config = new provisionConfig_drushrc_site();
$config->write();
}
}
class provisionConfig_drushrc extends provisionConfig {
public $template = 'provision_drushrc.tpl.php';
public $description = 'Drush configuration file';
protected $append = TRUE;
protected $mode = 0600;
function filename() {
return $this->data['config-file'];
}
function process() {
/**
* Save modified options to the drushrc.php file
*/
function provision_save_platform_data() {
if (!drush_get_error()) {
$config = new provisionConfig_drushrc_platform();
$config->write();
}
}
......
# Aegir additions
<?php foreach (array('db_type', 'db_host', 'db_user', 'db_passwd', 'db_name') as $key) { ?>
$_SERVER['<?php print $key; ?>'] = $options['<?php print $key; ?>'];
<?php } ?>
<?php print "<?php \n"; ?>
<?php foreach ($option_keys as $key) {
print "\n\$options['$key'] = ". var_export(${$key}, TRUE) .';';
}
?>
<?php include('provision_drushrc.tpl.php'); ?>
# Aegir additions
<?php foreach (array('db_type', 'db_host', 'db_user', 'db_passwd', 'db_name') as $key) { ?>
$_SERVER['<?php print $key; ?>'] = $options['<?php print $key; ?>'];
<?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