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
73 changes: 73 additions & 0 deletions php/EE/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,12 +765,85 @@ private function set_alias( $alias ) {
}
}

/**
* EE only manages the host it runs on: the WP-CLI ssh/http targets were never wired up, so a command given one
* would silently run here.
*
* @param array $args Command line arguments without the script name.
*/
private function refuse_remote_targets( $args ) {
$hint = 'EasyEngine only manages the server it runs on; run ee on the target server instead.';

if ( $this->alias ) {
$keys = $this->get_remote_alias_keys( $this->alias );
if ( $keys ) {
EE::error( sprintf( "The alias '%s' has a remote target (%s), which is not supported. %s", $this->alias, implode( ', ', $keys ), $hint ) );
}
}

// Raw argv: EE_STRICT_ARGS_MODE drops unknown global flags before they reach assoc_args.
list( , $assoc_args ) = Configurator::extract_assoc( $args );
foreach ( $assoc_args as $assoc_arg ) {
if ( in_array( $assoc_arg[0], array( 'ssh', 'http' ), true ) ) {
EE::error( "The --{$assoc_arg[0]} parameter is not supported. {$hint}" );
}
}

// Keep `ee config unset <key>` and help usable.
if ( empty( $this->arguments ) || in_array( $this->arguments[0], array( 'config', 'help' ), true ) ) {
return;
}

foreach ( array( 'ssh', 'http' ) as $key ) {
if ( ! empty( $this->extra_config[ $key ] ) ) {
Comment thread
mrrobot47 marked this conversation as resolved.
$files = implode( ', ', array_filter( array( $this->global_config_path, $this->project_config_path ) ) );
EE::error( "The '{$key}' config key is not supported. {$hint} Remove it from the config ({$files}, or a file they inherit)." );
}
}
}

/**
* Remote target keys (ssh, http) of an alias, or of any member of a group or of @all.
*
* @param string $alias Alias name.
* @param array $seen Aliases already visited, so groups listing each other don't recurse forever.
*
* @return string[]
*/
private function get_remote_alias_keys( $alias, $seen = array() ) {
if ( isset( $seen[ $alias ] ) || ! isset( $this->aliases[ $alias ] ) ) {
return array();
}
$seen[ $alias ] = true;
$config = $this->aliases[ $alias ];

if ( '@all' === $alias && is_string( $config ) ) {
$config = array_values( array_diff( array_keys( $this->aliases ), array( '@all' ) ) );
}
if ( ! is_array( $config ) ) {
return array();
}
if ( isset( $config[0] ) ) {
$keys = array();
foreach ( $config as $member ) {
$keys = array_merge( $keys, $this->get_remote_alias_keys( $member, $seen ) );
}

return array_values( array_unique( $keys ) );
}

return array_values( array_intersect( array( 'ssh', 'http' ), array_keys( $config ) ) );
}

public function start() {

EE::debug( $this->_global_config_path_debug, 'bootstrap' );
EE::debug( $this->_project_config_path_debug, 'bootstrap' );
EE::debug( 'argv: ' . implode( ' ', $GLOBALS['argv'] ), 'bootstrap' );

// Before init_ee(): migrations must not run for a command we refuse.
$this->refuse_remote_targets( array_slice( $GLOBALS['argv'], 1 ) );

$this->init_ee();

// Enable PHP error reporting to stderr if testing.
Expand Down
Loading