Elgg  Version 3.0
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('Execute cron handlers for all or specified interval')
18  ->addOption('interval', 'i', InputOption::VALUE_OPTIONAL,
19  'Name of the interval (e.g. hourly)'
20  )
21  ->addOption('force', 'f', InputOption::VALUE_NONE,
22  'Force cron commands to run even if they are not yet due'
23  )
24  ->addOption('time', 't', InputOption::VALUE_OPTIONAL,
25  'Time of the cron initialization'
26  );
27  }
28 
32  protected function command() {
33 
34  $intervals = null;
35  $interval = $this->option('interval');
36  if ($interval) {
37  $intervals = [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(!$entity instanceof ElggEntity) $time
Definition: time.php:21
write($messages, $level=LogLevel::INFO)
Write messages to output buffer.
Definition: BaseCommand.php:85
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:1292
option($name)
Returns option value.