Last active
March 31, 2017 01:20
-
-
Save frob/d3c6f2d97fe17f39daa8d24c99867f31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$database_suffix = ''; | |
if (git_command_exists('git') && $git_describe = settings_execute_os_command('git rev-parse --abbrev-ref HEAD') ) { | |
if (trim($git_describe) == 'HEAD') { | |
$git_describe = settings_execute_os_command('git describe --all'); | |
} | |
// Execute "git describe --all" and get the last part of heads/* as | |
// the tag/branch. | |
if (empty($git_describe)) { | |
return; | |
} | |
$tag_branch_parts = explode('/', $git_describe); | |
$release = end($tag_branch_parts); | |
if (!empty($release)) { | |
$database_suffix = '-' . $release; | |
} | |
} | |
/** | |
* Determines if a command exists on the current environment. | |
* | |
* @param string $command | |
* The command to check. | |
* | |
* @return bool | |
* TRUE if the command has been found; otherwise, FALSE. | |
*/ | |
function git_command_exists($command) { | |
$where_is_command = (PHP_OS == 'WINNT') ? 'where' : 'which'; | |
$command_return = settings_execute_os_command("$where_is_command $command"); | |
$output = !empty($command_return); | |
return $output; | |
} | |
/** | |
* Execute a system command and return the results. | |
* | |
* @param string $command | |
* The command to execute. | |
* | |
* @return string | |
* The results of the string execution. | |
*/ | |
function settings_execute_os_command($command) { | |
$process = proc_open( | |
$command, | |
array( | |
// STDIN. | |
0 => array("pipe", "r"), | |
// STDOUT. | |
1 => array("pipe", "w"), | |
// STDERR. | |
2 => array("pipe", "w"), | |
), | |
$pipes | |
); | |
if ($process === FALSE) { | |
return FALSE; | |
} | |
$stdout = stream_get_contents($pipes[1]); | |
$stderr = stream_get_contents($pipes[2]); | |
fclose($pipes[1]); | |
fclose($pipes[2]); | |
proc_close($process); | |
return $stdout; | |
} | |
$databases = array ( | |
'default' => | |
array ( | |
'default' => | |
array ( | |
'database' => 'drupal'. str_replace('.', '-', trim($database_suffix)), | |
'username' => 'drupal', | |
'password' => 'drupal', | |
'host' => 'localhost', | |
'port' => '', | |
'driver' => 'mysql', | |
'prefix' => '', | |
), | |
), | |
); | |
// Reroute emails in dev mode. | |
$conf['reroute_email_enable'] = 1; | |
// Show all errors. | |
error_reporting(E_ALL); | |
ini_set('display_errors', TRUE); | |
ini_set('display_startup_errors', TRUE); | |
// Turn off some performance caching. | |
$conf['preprocess_css'] = 0; | |
$conf['preprocess_js'] = 0; | |
$conf['less_devel'] = 1; | |
$conf['less_source_maps'] = 1; | |
// Replace the production GA account with the one we use for dev. | |
$conf['googleanalytics_account'] = 'UA-37674876-1'; | |
// Set environment indicator. | |
$conf['environment_indicator_overwrite'] = TRUE; | |
$conf['environment_indicator_overwritten_name'] = 'LOCAL SERVER'; | |
$conf['environment_indicator_overwritten_color'] = '#413D00'; | |
$conf['environment_indicator_overwritten_text_color'] = '#BEBEBE'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
adds a db suffix that matches the git branch name. So switching branches also switches databases. Awsome for use with drupal-vm and drush sql-create.
mostly taken from the environment module.