Skip to content

Commit b74109b

Browse files
committed
Merge branch 'mrrobot47-update/db-and-docker-functions' into develop-v4
2 parents c967c63 + 56e8add commit b74109b

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

php/class-ee-db.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public function __construct() {
99
self::init_db();
1010
}
1111
}
12-
12+
1313
public function __destruct() {
1414
self::$db->close();
1515
}
@@ -34,7 +34,7 @@ public static function init_db() {
3434
public static function create() {
3535
self::$db = new SQLite3( DB );
3636
$query = "CREATE TABLE sites (
37-
id INTEGER NOT NULL,
37+
id INTEGER NOT NULL,
3838
sitename VARCHAR,
3939
site_type VARCHAR,
4040
site_title VARCHAR,
@@ -56,19 +56,31 @@ public static function create() {
5656
wp_pass VARCHAR,
5757
email VARCHAR,
5858
php_version VARCHAR,
59-
PRIMARY KEY (id),
59+
PRIMARY KEY (id),
6060
UNIQUE (sitename),
61-
CHECK (is_enabled IN (0, 1)),
61+
CHECK (is_enabled IN (0, 1)),
6262
CHECK (is_ssl IN (0, 1))
6363
);";
6464

65-
self::$db->exec( $query );
66-
67-
$query = "CREATE TABLE migrations (
65+
$query .= "CREATE TABLE migrations (
6866
migration VARCHAR,
6967
timestamp DATETIME
7068
);";
7169

70+
$query .= "CREATE TABLE services (
71+
id INTEGER NOT NULL,
72+
sitename VARCHAR,
73+
phpmyadmin BOOLEAN DEFAULT 0,
74+
mailhog BOOLEAN DEFAULT 0,
75+
postfix BOOLEAN DEFAULT 0,
76+
phpredisadmin BOOLEAN DEFAULT 0,
77+
adminer BOOLEAN DEFAULT 0,
78+
anemometer BOOLEAN DEFAULT 0,
79+
debug BOOLEAN DEFAULT 0,
80+
PRIMARY KEY (id),
81+
FOREIGN KEY (id) REFERENCES sites(id)
82+
);";
83+
7284
self::$db->exec( $query );
7385
}
7486

@@ -79,7 +91,7 @@ public static function create() {
7991
*
8092
* @return bool
8193
*/
82-
public static function insert( $data, $table_name='sites' ) {
94+
public static function insert( $data, $table_name = 'sites' ) {
8395

8496
if ( empty ( self::$db ) ) {
8597
self::init_db();
@@ -109,7 +121,7 @@ public static function insert( $data, $table_name='sites' ) {
109121
*
110122
* @return array|bool
111123
*/
112-
public static function select( $columns = array(), $where = array(), $table_name='sites' ) {
124+
public static function select( $columns = array(), $where = array(), $table_name = 'sites', $limit = null ) {
113125

114126
if ( empty ( self::$db ) ) {
115127
self::init_db();
@@ -134,6 +146,10 @@ public static function select( $columns = array(), $where = array(), $table_name
134146
$select_data_query .= " WHERE $conditions";
135147
}
136148

149+
if ( ! empty( $limit ) ) {
150+
$select_data_query .= " LIMIT $limit";
151+
}
152+
137153
$select_data_exec = self::$db->query( $select_data_query );
138154
$select_data = array();
139155
if ( $select_data_exec ) {
@@ -157,7 +173,7 @@ public static function select( $columns = array(), $where = array(), $table_name
157173
*
158174
* @return bool
159175
*/
160-
public static function update( $data, $where, $table_name='sites' ) {
176+
public static function update( $data, $where, $table_name = 'sites' ) {
161177
if ( empty ( self::$db ) ) {
162178
self::init_db();
163179
}
@@ -192,7 +208,7 @@ public static function update( $data, $where, $table_name='sites' ) {
192208
*
193209
* @return bool
194210
*/
195-
public static function delete( $where, $table_name='sites' ) {
211+
public static function delete( $where, $table_name = 'sites' ) {
196212

197213
$conditions = array();
198214
foreach ( $where as $key => $value ) {
@@ -268,9 +284,10 @@ public static function get_migrations() {
268284
}
269285

270286
$sites = self::select( [ 'migration' ], [], 'migrations' );
271-
if( empty( $sites ) ) {
287+
if ( empty( $sites ) ) {
272288
return [];
273289
}
290+
274291
return array_column( $sites, 'migration' );
275292
}
276293
}

php/class-ee-docker.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,21 @@ public static function disconnect_site_network_from( $site_name, $from_container
152152
/**
153153
* Function to boot the containers.
154154
*
155-
* @param String $dir Path to docker-compose.yml.
155+
* @param String $dir Path to docker-compose.yml.
156+
* @param array $services Services to bring up.
156157
*
157158
* @return bool success.
158159
*/
159-
public static function docker_compose_up( $dir ) {
160+
public static function docker_compose_up( $dir, $services = [] ) {
160161
$chdir_return_code = chdir( $dir );
161162
if ( $chdir_return_code ) {
162-
return default_launch( 'docker-compose up -d' );
163+
if ( empty( $services ) ) {
164+
return default_launch( 'docker-compose up -d' );
165+
} else {
166+
$all_services = implode( ' ', $services );
167+
168+
return default_launch( "docker-compose up -d $all_services" );
169+
}
163170
}
164171

165172
return false;
@@ -168,14 +175,21 @@ public static function docker_compose_up( $dir ) {
168175
/**
169176
* Function to destroy the containers.
170177
*
171-
* @param String $dir Path to docker-compose.yml.
178+
* @param String $dir Path to docker-compose.yml.
179+
* @param array $services Services to bring up.
172180
*
173181
* @return bool success.
174182
*/
175-
public static function docker_compose_down( $dir ) {
183+
public static function docker_compose_down( $dir, $services = [] ) {
176184
$chdir_return_code = chdir( $dir );
177185
if ( $chdir_return_code ) {
178-
return default_launch( 'docker-compose down' );
186+
if ( empty( $services ) ) {
187+
return default_launch( 'docker-compose up -d' );
188+
} else {
189+
$all_services = implode( ' ', $services );
190+
191+
return default_launch( "docker-compose up $all_services -d" );
192+
}
179193
}
180194

181195
return false;

0 commit comments

Comments
 (0)