Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions src/Admin_Tools_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class Admin_Tools_Command extends EE_Command {
private $fs;

/**
* @var array $db Object containing essential site related information.
* @var array $site_data Object containing essential site related information.
*/
private $db;
private $site_data;

public function __construct() {

Expand Down Expand Up @@ -60,7 +60,7 @@ public function install() {
if ( empty( $tools_file ) ) {
EE::error( 'admin-tools file is empty. Can\'t proceed further.' );
}
$tools = json_decode( $tools_file, true );
$tools = json_decode( $tools_file, true );
$json_error = json_last_error();
if ( $json_error != JSON_ERROR_NONE ) {
EE::debug( 'Json last error: ' . $json_error );
Expand Down Expand Up @@ -100,40 +100,40 @@ public function install() {
public function up( $args, $assoc_args ) {

EE\Utils\delem_log( 'admin-tools ' . __FUNCTION__ . ' start' );
$args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ );
$force = EE\Utils\get_flag_value( $assoc_args, 'force' );
$this->db = Site::find( EE\Utils\remove_trailing_slash( $args[0] ) );
if ( ! $this->db || ! $this->db->site_enabled ) {
$args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ );
$force = EE\Utils\get_flag_value( $assoc_args, 'force' );
$this->site_data = Site::find( EE\Utils\remove_trailing_slash( $args[0] ) );
if ( ! $this->site_data || ! $this->site_data->site_enabled ) {
EE::error( sprintf( 'Site %s does not exist / is not enabled.', $args[0] ) );
}

if ( $this->db->admin_tools && ! $force ) {
EE::error( sprintf( 'admin-tools already seem to be enabled for %s', $this->db->site_url ) );
if ( $this->site_data->admin_tools && ! $force ) {
EE::error( sprintf( 'admin-tools already seem to be enabled for %s', $this->site_data->site_url ) );
}

chdir( $this->db->site_fs_path );
chdir( $this->site_data->site_fs_path );

$launch = EE::launch( 'docker-compose config --services' );
$services = explode( PHP_EOL, trim( $launch->stdout ) );
$min_req_services = [ 'nginx', 'php' ];

if ( count( array_intersect( $services, $min_req_services ) ) !== count( $min_req_services ) ) {
EE::error( sprintf( '%s site-type of %s-command does not support admin-tools.', $this->db->app_sub_type, $this->db->site_type ) );
EE::error( sprintf( '%s site-type of %s-command does not support admin-tools.', $this->site_data->app_sub_type, $this->site_data->site_type ) );
}

if ( ! $this->is_installed() ) {
EE::log( 'It seems admin-tools have not yet been installed.' );
$this->install();
}

$this->move_config_file( 'docker-compose-admin.mustache', $this->db->site_fs_path . '/docker-compose-admin.yml' );
$this->move_config_file( 'docker-compose-admin.mustache', $this->site_data->site_fs_path . '/docker-compose-admin.yml' );

if ( EE::exec( 'docker-compose -f docker-compose.yml -f docker-compose-admin.yml up -d nginx' ) ) {
EE::success( sprintf( 'admin-tools enabled for %s site.', $this->db->site_url ) );
$this->db->admin_tools = 1;
$this->db->save();
EE::success( sprintf( 'admin-tools enabled for %s site.', $this->site_data->site_url ) );
$this->site_data->admin_tools = 1;
$this->site_data->save();
} else {
EE::error( sprintf( 'Error in enabling admin-tools for %s site. Check logs.', $this->db->site_url ) );
EE::error( sprintf( 'Error in enabling admin-tools for %s site. Check logs.', $this->site_data->site_url ) );
}

EE\Utils\delem_log( 'admin-tools ' . __FUNCTION__ . ' stop' );
Expand All @@ -153,21 +153,21 @@ public function up( $args, $assoc_args ) {
public function down( $args, $assoc_args ) {

EE\Utils\delem_log( 'admin-tools ' . __FUNCTION__ . ' start' );
$args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ );
$force = EE\Utils\get_flag_value( $assoc_args, 'force' );
$this->db = Site::find( EE\Utils\remove_trailing_slash( $args[0] ) );
if ( ! $this->db || ! $this->db->site_enabled ) {
$args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ );
$force = EE\Utils\get_flag_value( $assoc_args, 'force' );
$this->site_data = Site::find( EE\Utils\remove_trailing_slash( $args[0] ) );
if ( ! $this->site_data || ! $this->site_data->site_enabled ) {
EE::error( sprintf( 'Site %s does not exist / is not enabled.', $args[0] ) );
}

if ( ! $this->db->admin_tools && ! $force ) {
EE::error( sprintf( 'admin-tools already seem to be enabled for %s', $this->db->site_url ) );
if ( ! $this->site_data->admin_tools && ! $force ) {
EE::error( sprintf( 'admin-tools already seem to be enabled for %s', $this->site_data->site_url ) );
}

EE::docker()::docker_compose_up( $this->db->site_fs_path, [ 'nginx', 'php' ] );
EE::success( sprintf( 'admin-tools disabled for %s site.', $this->db->site_url ) );
$this->db->admin_tools = 0;
$this->db->save();
EE::docker()::docker_compose_up( $this->site_data->site_fs_path, [ 'nginx', 'php' ] );
EE::success( sprintf( 'admin-tools disabled for %s site.', $this->site_data->site_url ) );
$this->site_data->admin_tools = 0;
$this->site_data->save();
EE\Utils\delem_log( 'admin-tools ' . __FUNCTION__ . ' stop' );
}

Expand Down