Elgg  Version 5.1
CronCommand.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
7 
11 class CronCommand extends Command {
12 
16  protected function configure() {
17  $this->setName('cron')
18  ->setDescription(elgg_echo('cli:cron:description'))
19  ->addOption('interval', 'i', InputOption::VALUE_OPTIONAL,
20  elgg_echo('cli:cron:option:interval')
21  )
22  ->addOption('force', 'f', InputOption::VALUE_NONE,
23  elgg_echo('cli:cron:option:force')
24  )
25  ->addOption('time', 't', InputOption::VALUE_OPTIONAL,
26  elgg_echo('cli:cron:option:time')
27  );
28  }
29 
33  protected function command() {
34  $intervals = null;
35  $interval = $this->option('interval');
36  if ($interval) {
37  $intervals = [elgg_strtolower($interval)];
38  }
39 
40  $time = $this->option('time');
41  if (!$time) {
42  $time = 'now';
43  }
44 
45  $time = new \DateTime($time);
46  _elgg_services()->cron->setCurrentTime($time);
47 
48  try {
49  $jobs = _elgg_services()->cron->run($intervals, $this->option('force'));
50  if (!$this->option('quiet')) {
51  foreach ($jobs as $job) {
52  $this->write($job->getOutput());
53  }
54  }
55  } catch (CronException $e) {
56  $this->error($e->getMessage());
57  return self::FAILURE;
58  }
59 
60  return self::SUCCESS;
61  }
62 }
error($message)
Print an error.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
if(!$annotation instanceof ElggAnnotation) $time
Definition: time.php:20
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:161
write($messages, $level=LogLevel::INFO)
Write messages to output buffer.
Definition: BaseCommand.php:93
Abstract command with some utility methods.
Definition: Command.php:12
elgg-cli cron [–interval] [–quiet]
Definition: CronCommand.php:11
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
A generic parent class for cron exceptions.
option($name)
Returns option value.