Created
December 15, 2015 12:28
-
-
Save delineas/2b83a5e76cd0e2fe1920 to your computer and use it in GitHub Desktop.
Drupal git branch different database
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 | |
$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