Elgg  Version 6.3
CronCommand.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
6 use Psr\Log\LogLevel;
7 use Symfony\Component\Console\Input\InputOption;
8 
12 class CronCommand extends Command {
13 
17  protected function configure() {
18  $this->setName('cron')
19  ->setDescription(elgg_echo('cli:cron:description'))
20  ->addOption('interval', 'i', InputOption::VALUE_OPTIONAL,
21  elgg_echo('cli:cron:option:interval')
22  )
23  ->addOption('force', 'f', InputOption::VALUE_NONE,
24  elgg_echo('cli:cron:option:force')
25  )
26  ->addOption('time', 't', InputOption::VALUE_OPTIONAL,
27  elgg_echo('cli:cron:option:time')
28  );
29  }
30 
34  protected function command() {
35  $intervals = null;
36  $interval = $this->option('interval');
37  if ($interval) {
38  $intervals = [elgg_strtolower($interval)];
39  }
40 
41  $time = $this->option('time');
42  if (!$time) {
43  $time = 'now';
44  }
45 
46  $time = new \DateTime($time);
47  _elgg_services()->cron->setCurrentTime($time);
48 
49  try {
50  _elgg_services()->cron->run($intervals, $this->option('force'));
51  } catch (CronException $e) {
52  elgg_log($e->getMessage(), LogLevel::ERROR);
53  return self::FAILURE;
54  }
55 
56  return self::SUCCESS;
57  }
58 }
if(! $annotation instanceof ElggAnnotation) $time
Definition: time.php:20
option($name)
Returns option value.
Abstract command with some utility methods.
Definition: Command.php:13
elgg-cli cron [–interval] [–quiet]
Definition: CronCommand.php:12
command()
{Command to be executed.This method should return an integer code of the error (or 0 for success)....
Definition: CronCommand.php:34
A generic parent class for cron exceptions.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:88
_elgg_services()
Get the global service provider.
Definition: elgglib.php:337
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:125