Skip to content

Commit e419a0c

Browse files
Merge pull request #43 from mrrobot47/fix/saving-password
Add saving global-db password post docker-compose generation
2 parents 5764dcf + 73a8047 commit e419a0c

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace EE\Migration;
4+
5+
use EE;
6+
use EE\Migration\Base;
7+
use EE\Model\Option;
8+
9+
class SaveGLobalDbPassOne extends Base {
10+
11+
public function __construct() {
12+
13+
parent::__construct();
14+
if ( $this->is_first_execution ) {
15+
$this->skip_this_migration = true;
16+
}
17+
}
18+
19+
/**
20+
* Execute nginx config updates.
21+
*
22+
* @throws EE\ExitException
23+
*/
24+
public function up() {
25+
26+
if ( $this->fs->exists( EE_SERVICE_DIR . '/docker-compose.yml' ) ) {
27+
$this->skip_this_migration = false;
28+
}
29+
30+
$db_password = Option::get( GLOBAL_DB );
31+
if ( ! empty( $db_password ) ) {
32+
$this->skip_this_migration = true;
33+
}
34+
35+
if ( $this->skip_this_migration ) {
36+
EE::debug( 'Skipping save-global-db-pass migration as it is not needed.' );
37+
38+
return;
39+
}
40+
41+
EE::debug( 'Starting save-global-db-pass' );
42+
43+
$launch = EE::launch( sprintf( 'cat %s | grep MYSQL_ROOT_PASSWORD | cut -d"=" -f2', EE_SERVICE_DIR . '/docker-compose.yml' ) );
44+
$password = trim( $launch->stdout );
45+
46+
Option::set( GLOBAL_DB, $password );
47+
}
48+
49+
/**
50+
* No need for down.
51+
*
52+
* @throws EE\ExitException
53+
*/
54+
public function down() {
55+
}
56+
}

src/helper/service-utils.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ function generate_global_docker_compose_yml( Filesystem $fs ) {
288288
],
289289
];
290290

291+
Option::set( GLOBAL_DB, $password );
291292
$contents = EE\Utils\mustache_render( SERVICE_TEMPLATE_ROOT . '/global_docker_compose.yml.mustache', $data );
292293
$fs->dumpFile( EE_SERVICE_DIR . '/docker-compose.yml', $contents );
293294
}

0 commit comments

Comments
 (0)