Elgg  Version 4.3
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 
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 
47  _elgg_services()->cron->setCurrentTime($time);
48  $jobs = _elgg_services()->cron->run($intervals, $this->option('force'));
49 
50  if (!$this->option('quiet')) {
51  foreach ($jobs as $job) {
52  $this->write($job->getOutput());
53  }
54  }
55 
56  return 0;
57  }
58 }
if(!$annotation instanceof ElggAnnotation) $time
Definition: time.php:20
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:154
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
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:638
option($name)
Returns option value.