Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct validation #9

Merged
merged 2 commits into from
Aug 6, 2018
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
18 changes: 12 additions & 6 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 @@ -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