Skip to content

Commit

Permalink
Merge branch 'develop' for v1.0.0-beta.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mbtamuli committed Aug 6, 2018
2 parents 34b27c0 + 8bc1437 commit 7dae17a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Cron_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function add( $args, $assoc_args ) {
EE\Utils\delem_log( 'ee cron add start' );

if ( ! isset( $args[0] ) || $args[0] !== 'host' ) {
$args = EE\Utils\set_site_arg( $args, 'cron' );
$args = EE\SiteUtils\auto_site_name( $args, 'cron', __FUNCTION__ );
}

$site = EE\Utils\remove_trailing_slash( $args[0] );
Expand All @@ -89,7 +89,7 @@ public function add( $args, $assoc_args ) {
}
}

$this->semi_colon_check( $command );
$this->validate_command( $command );
$command = $this->add_sh_c_wrapper( $command );

EE::db()->insert(
Expand Down Expand Up @@ -171,7 +171,7 @@ public function update( $args, $assoc_args ) {
$data_to_update['sitename'] = $site;
}
if ( $command ) {
$this->semi_colon_check( $command );
$this->validate_command( $command );
$command = $this->add_sh_c_wrapper( $command );
$data_to_update['command'] = $command;
}
Expand Down Expand Up @@ -219,7 +219,7 @@ public function _list( $args, $assoc_args ) {
$all = EE\Utils\get_flag_value( $assoc_args, 'all' );

if ( ( ! isset( $args[0] ) || $args[0] !== 'host' ) && ! $all ) {
$args = EE\Utils\set_site_arg( $args, 'cron' );
$args = EE\SiteUtils\auto_site_name( $args, 'cron', 'list' );
}

if ( isset( $args[0] ) ) {
Expand Down Expand Up @@ -293,7 +293,7 @@ public function run_now( $args ) {
}
$container = $this->site_php_container( $result[0]['sitename'] );
$command = $result[0]['command'];
\EE\Utils\default_launch( "docker exec $container $command", true, true );
EE::exec( "docker exec $container $command", true, true );
}

/**
Expand Down Expand Up @@ -332,12 +332,18 @@ private function site_php_container( $site ) {
return str_replace( '.', '', $site ) . '_php_1';
}

private function semi_colon_check( $command ) {
// Semicolons in commands do not work for now due to limitation of INI style config ofelia uses
/**
* Ensures given command will not create problem with INI syntax
*/
private function validate_command( $command ) {
// Semicolons and Hash(#) in commands do not work for now due to limitation of INI style config ofelia uses
// See https://github.com/EasyEngine/cron-command/issues/4
if ( strpos( $command, ';' ) !== false ) {
EE::error( 'Command chaining using `;` - semi-colon is not supported currently. You can either use `&&` or `||` or creating a second cron job for the chained command.' );
}
if ( strpos( $command, '#' ) !== false ) {
EE::error( 'EasyEngine does not support commands with #' );
}
}

private function add_sh_c_wrapper( $command ) {
Expand Down

0 comments on commit 7dae17a

Please sign in to comment.