Skip to content

Commit

Permalink
enable use of environment variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
mch0lic committed Aug 11, 2021
1 parent 804085f commit 6f54202
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 10 additions & 8 deletions src/GDPR_Dump_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public function __invoke( $args, $assoc_args ) {
$assoc_args
);

// Environment variables passed to shell.
$env_variables = array(
'DB_HOST' => DB_HOST,
'DB_USER' => DB_USER,
'DB_PASSWORD' => DB_PASSWORD,
'DB_NAME' => DB_NAME,
);

$root_path = rtrim( ABSPATH, '/' );
$gdpr_dump_bin = $this->get_gdpr_dump_bin();
$config = $this->get_config_file( $root_path, $assoc_args );
Expand All @@ -57,8 +65,7 @@ public function __invoke( $args, $assoc_args ) {
WP_CLI::debug( sprintf( 'Running command: %s', $command ) );
}

$process_run = Process::create( $command )->run();

$process_run = Process::create( $command, null, $env_variables )->run();
if ( 0 !== $process_run->return_code ) {
if ( ! empty( $process_run->stderr ) ) {
WP_CLI::error( $process_run->stderr );
Expand Down Expand Up @@ -138,8 +145,7 @@ private function get_default_config_path() {
$tmp_dir = rtrim( WP_CLI\Utils\get_temp_dir(), DIRECTORY_SEPARATOR );
$package_root = dirname( dirname( __FILE__ ) );
$template_path = $package_root . '/templates/';

$config_file = Utils\normalize_path( $tmp_dir . DIRECTORY_SEPARATOR . 'wordpress.yml' );
$config_file = Utils\normalize_path( $tmp_dir . DIRECTORY_SEPARATOR . 'wordpress.yml' );
if ( file_exists( $config_file ) ) {
unlink( $config_file );
}
Expand All @@ -149,10 +155,6 @@ private function get_default_config_path() {
WP_CLI\Utils\mustache_render(
"{$template_path}/wordpress.mustache",
array(
'db_host' => DB_HOST,
'db_user' => DB_USER,
'db_pass' => DB_PASSWORD,
'db_name' => DB_NAME,
'table_prefix' => ! empty( $table_prefix ) ? $table_prefix : 'wp_',
'backup_filename' => 'backup-{YmdHis}.sql',
)
Expand Down
8 changes: 4 additions & 4 deletions templates/wordpress.mustache
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
database:
host: "{{db_host}}"
user: "{{db_user}}"
password: "{{db_pass}}"
name: "{{db_name}}"
host: "%env(DB_HOST)%"
user: "%env(DB_USER)%"
password: "%env(DB_PASSWORD)%"
name: "%env(DB_NAME)%"

dump:
output: "backup-{YmdHis}.sql"
Expand Down

0 comments on commit 6f54202

Please sign in to comment.