Elgg  Version master
CronCommand.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
6 
10 class CronCommand extends Command {
11 
15  protected function configure() {
16  $this->setName('cron')
17  ->setDescription(elgg_echo('cli:cron:description'))
18  ->addOption('interval', 'i', InputOption::VALUE_OPTIONAL,
19  elgg_echo('cli:cron:option:interval')
20  )
21  ->addOption('force', 'f', InputOption::VALUE_NONE,
22  elgg_echo('cli:cron:option:force')
23  )
24  ->addOption('time', 't', InputOption::VALUE_OPTIONAL,
25  elgg_echo('cli:cron:option:time')
26  );
27  }
28 
32  protected function command() {
33  $intervals = null;
34  $interval = $this->option('interval');
35  if ($interval) {
36  $intervals = [elgg_strtolower($interval)];
37  }
38 
39  $time = $this->option('time');
40  if (!$time) {
41  $time = 'now';
42  }
43 
44  $time = new \DateTime($time);
45 
46  _elgg_services()->cron->setCurrentTime($time);
47  $jobs = _elgg_services()->cron->run($intervals, $this->option('force'));
48 
49  if (!$this->option('quiet')) {
50  foreach ($jobs as $job) {
51  $this->write($job->getOutput());
52  }
53  }
54 
55  return self::SUCCESS;
56  }
57 }
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:10
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
option($name)
Returns option value.