Drupal git branch different database
<?php | |
$databases = array ( | |
'default' => | |
array ( | |
'default' => | |
array ( | |
'driver' => 'mysql', | |
'username' => 'root', | |
'password' => 'root', | |
'port' => '', | |
'host' => 'localhost', | |
'database' => 'regular_database', | |
'prefix' => '', | |
), | |
), | |
); | |
/** | |
* CHANGE CONFIGURATION BASED ON GIT | |
* */ | |
$databases_by_branch = array( | |
'branch_name_1' => array ( | |
'driver' => 'mysql', | |
'username' => 'root', | |
'password' => 'root', | |
'port' => '', | |
'host' => 'localhost', | |
'database' => 'branch_name_1_database', | |
'prefix' => '', | |
), | |
'branch_name_2' => array ( | |
'driver' => 'mysql', | |
'username' => 'root', | |
'password' => 'root', | |
'port' => '', | |
'host' => 'localhost', | |
'database' => 'branch_name_2_database', | |
'prefix' => '', | |
) | |
); | |
$branchname_from_HEAD = file(DRUPAL_ROOT . '/.git/HEAD'); | |
$branchname_from_HEAD = $branchname_from_HEAD[0]; //get the string from the array | |
$a_branchname = explode("/", $branchname_from_HEAD); //seperate out by the "/" in the string | |
$branchname = preg_replace('/\s/', '', $a_branchname[count($a_branchname) - 1]); | |
if(isset($databases_by_branch[$branchname])) { | |
$databases['default']['default'] = $databases_by_branch[$branchname]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment