Skip to content

Commit f913b53

Browse files
committed
Add doc comments and fix phpcs errors
Signed-off-by: Riddhesh Sanghvi <riddheshsanghvi96@gmail.com>
1 parent 5f5da7a commit f913b53

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

src/Cron_Command.php

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*
99
* @package ee-cli
1010
*/
11-
1211
class Cron_Command extends EE_Command {
1312

1413
/**
@@ -41,11 +40,11 @@ public function __construct() {
4140
*
4241
* Entry | Description | Equivalent To
4342
* ----- | ----------- | -------------
44-
* @yearly (or @annually) | Run once a year, midnight, Jan. 1st | 0 0 1 1 *
45-
* @monthly | Run once a month, midnight, first of month | 0 0 1 * *
46-
* @weekly | Run once a week, midnight between Sat/Sun | 0 0 * * 0
47-
* @daily (or @midnight) | Run once a day, midnight | 0 0 * * *
48-
* @hourly | Run once an hour, beginning of hour | 0 * * * *
43+
* @yearly (or @annually) | Run once a year, midnight, Jan. 1st | 0 0 1 1 *
44+
* @monthly | Run once a month, midnight, first of month | 0 0 1 * *
45+
* @weekly | Run once a week, midnight between Sat/Sun | 0 0 * * 0
46+
* @daily (or @midnight) | Run once a day, midnight | 0 0 * * *
47+
* @hourly | Run once an hour, beginning of hour | 0 * * * *
4948
*
5049
* You may also schedule a job to execute at fixed intervals, starting at the time it's added or cron is run.
5150
* This is supported by following format:
@@ -72,9 +71,9 @@ public function __construct() {
7271
*
7372
* # Adds a cron job to host running EasyEngine
7473
* $ ee cron add host --command='wp media regenerate --yes' --schedule='@weekly'
75-
*
7674
*/
7775
public function add( $args, $assoc_args ) {
76+
7877
EE\Utils\delem_log( 'ee cron add start' );
7978

8079
if ( ! isset( $args[0] ) || $args[0] !== 'host' ) {
@@ -95,11 +94,11 @@ public function add( $args, $assoc_args ) {
9594
$this->validate_command( $command );
9695
$command = $this->add_sh_c_wrapper( $command );
9796

98-
Cron::create([
97+
Cron::create( [
9998
'site_url' => $site,
10099
'command' => $command,
101100
'schedule' => $schedule
102-
]);
101+
] );
103102

104103

105104
$this->update_cron_config();
@@ -156,9 +155,9 @@ public function add( $args, $assoc_args ) {
156155
*
157156
* # Updates schedule of cron
158157
* $ ee cron update 1 --schedule='@every 1m'
159-
*
160158
*/
161159
public function update( $args, $assoc_args ) {
160+
162161
EE\Utils\delem_log( 'ee cron add start' );
163162

164163
$data_to_update = [];
@@ -217,17 +216,16 @@ public function update( $args, $assoc_args ) {
217216
* @subcommand list
218217
*/
219218
public function _list( $args, $assoc_args ) {
220-
$where = [];
221-
$all = EE\Utils\get_flag_value( $assoc_args, 'all' );
219+
220+
$all = EE\Utils\get_flag_value( $assoc_args, 'all' );
222221

223222
if ( ( ! isset( $args[0] ) || $args[0] !== 'host' ) && ! $all ) {
224223
$args = auto_site_name( $args, 'cron', 'list' );
225224
}
226225

227226
if ( isset( $args[0] ) ) {
228227
$crons = Cron::where( 'site_url', $args[0] );
229-
}
230-
else {
228+
} else {
231229
$crons = Cron::all();
232230
}
233231

@@ -246,7 +244,6 @@ public function _list( $args, $assoc_args ) {
246244
private function update_cron_config() {
247245

248246
$config = $this->generate_cron_config();
249-
250247
file_put_contents( EE_CONF_ROOT . '/cron/config.ini', $config );
251248
EE_DOCKER::restart_container( 'ee-cron-scheduler' );
252249
}
@@ -255,6 +252,7 @@ private function update_cron_config() {
255252
* Generates and returns cron config from DB
256253
*/
257254
private function generate_cron_config() {
255+
258256
$config_template = file_get_contents( __DIR__ . '/../templates/config.ini.mustache' );
259257
$crons = Cron::all();
260258

@@ -318,7 +316,7 @@ public function run_now( $args ) {
318316
*/
319317
public function delete( $args ) {
320318

321-
$id = $args[0];
319+
$id = $args[0];
322320
$cron = Cron::find( $id );
323321

324322
if ( ! $cron ) {
@@ -333,18 +331,26 @@ public function delete( $args ) {
333331

334332

335333
/**
336-
* Returns php container name of a site
334+
* Returns php container name of a site.
335+
*
336+
* @param string $site Name of the site whose container name is needed.
337+
*
338+
* @return string Container name.
337339
*/
338340
private function site_php_container( $site ) {
341+
339342
return str_replace( '.', '', $site ) . '_php_1';
340343
}
341344

342345
/**
343-
* Ensures given command will not create problem with INI syntax
346+
* Ensures given command will not create problem with INI syntax.
347+
* Semicolons and Hash(#) in commands do not work for now due to limitation of INI style config ofelia uses.
348+
* See https://github.com/EasyEngine/cron-command/issues/4.
349+
*
350+
* @param string $command Command whose syntax needs to be validated.
344351
*/
345352
private function validate_command( $command ) {
346-
// Semicolons and Hash(#) in commands do not work for now due to limitation of INI style config ofelia uses
347-
// See https://github.com/EasyEngine/cron-command/issues/4
353+
348354
if ( strpos( $command, ';' ) !== false ) {
349355
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.' );
350356
}
@@ -353,6 +359,13 @@ private function validate_command( $command ) {
353359
}
354360
}
355361

362+
/**
363+
* Adds wrapper of `sh -c` to execute composite commands through docker exec properly.
364+
*
365+
* @param string $command Passed command.
366+
*
367+
* @return string Command with properly added wrapper.
368+
*/
356369
private function add_sh_c_wrapper( $command ) {
357370
if ( strpos( $command, 'sh -c' ) !== false ) {
358371
return $command;

0 commit comments

Comments
 (0)