Created
October 26, 2022 07:34
-
-
Save junaidpv/7d188264e43e02aeafef96abcaa5018c to your computer and use it in GitHub Desktop.
Script showing how db credentials in drushrc.php of an Aegir site can be updated.
This file contains hidden or 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 | |
| $password = 'blahblahblacksheep1'; | |
| $user = 'db_user'; | |
| $db_name = 'test'; | |
| $lines = file('drushrc.php'); | |
| foreach ($lines as $index => $line) { | |
| if (preg_match('/^\$options\[\'db_passwd\'\]\s*\=\s*\'.*?\'\s*\;/', $line)) { | |
| $lines[$index] = "\$options['db_passwd'] = '$password';\n"; | |
| } | |
| elseif (preg_match('/^\$options\[\'db_name\'\]\s*\=\s*\'.*?\'\s*\;/', $line)) { | |
| $lines[$index] = "\$options['db_name'] = '$db_name';\n"; | |
| } | |
| elseif (preg_match('/^\$options\[\'db_user\'\]\s*\=\s*\'.*?\'\s*\;/', $line)) { | |
| $lines[$index] = "\$options['db_user'] = '$user';\n"; | |
| } | |
| } | |
| $new_file = file_put_contents('drushrc.php', implode('', $lines)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment