Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
P
provision
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Drupal.org issue queue
Drupal.org issue queue
Security & Compliance
Security & Compliance
Dependency List
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
project
provision
Commits
917c8c68
Commit
917c8c68
authored
Aug 07, 2019
by
Jon Pugh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#3073299
: Add hook_provision_prepare_environment() and documentation.
parent
0bbae723
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
platform/provision_drupal.drush.inc
platform/provision_drupal.drush.inc
+8
-0
provision.api.php
provision.api.php
+31
-0
No files found.
platform/provision_drupal.drush.inc
View file @
917c8c68
...
...
@@ -645,6 +645,9 @@ function provision_parse_info_file($filename) {
* The real credentials are stored in the Apache vhost of the relevant site, to prevent leaking of
* sensitive data to site administrators with PHP access who might otherwise access such credentials
* potentially of other sites' settings.php in a multisite set-up.
*
* Fire hook_provision_prepare_environment() so other scripts can react to this
* step and add more information or take other actions.
*/
function
provision_prepare_environment
()
{
$fields
=
array
(
'db_type'
,
'db_host'
,
'db_user'
,
'db_passwd'
,
'db_name'
,
'db_port'
);
...
...
@@ -656,6 +659,11 @@ function provision_prepare_environment() {
if
(
drush_drupal_major_version
()
>=
7
)
{
$_SERVER
[
'db_type'
]
=
(
$_SERVER
[
'db_type'
]
==
'mysqli'
)
?
'mysql'
:
$_SERVER
[
'db_type'
];
}
// Invoke provision_prepare_environment: Allow other scripts to react to the
// preparation of the environment variables.
drush_command_invoke_all
(
'provision_prepare_environment'
);
}
...
...
provision.api.php
View file @
917c8c68
...
...
@@ -418,3 +418,34 @@ function hook_provision_mysql_regex_alter(&$regexes) {
'#/\*!50001 CREATE ALGORITHM=UNDEFINED \*/#'
=>
"/*!50001 CREATE */"
,
);
}
/**
* Implements hook_provision_prepare_environment()
*
* React to the setting up of $_SERVER variables such as db_name and db_passwd.
*
* Runs right after writing sites/$URI/drushrc.php.
* Database credentials are available in the $_SERVER variables.
*
* @see provision_prepare_environment()
*/
function
hook_provision_prepare_environment
()
{
// Write a .env file in the root of the project with the Drupal DB credentials.
// This file could be used by other tools to access the site's database.
$file_name
=
d
()
->
root
.
'/.env'
;
$file_contents
=
<<<ENV
MYSQL_DATABASE={$_SERVER['db_name']}
MYSQL_USER={$_SERVER['db_name']}
MYSQL_PASSWORD={$_SERVER['db_name']}
ENV;
// Make writable, then write the file.
if
(
file_exists
(
$file_name
)
&&
!
is_writable
(
$file_name
))
{
provision_file
()
->
chmod
(
$file_name
,
0660
);
}
file_put_contents
(
$file_name
,
$file_contents
);
// Hide sensitive information from any other users.
provision_file
()
->
chmod
(
$file_name
,
0400
);
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment