Completed
Push — master ( 61e19c...9c38d8 )
by Jeroen
120:24 queued 62:19
created

CronCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 8
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Elgg\Cli;
4
5
use Symfony\Component\Console\Input\InputOption;
6
7
/**
8
 * elgg-cli cron [--interval] [--quiet]
9
 */
10
class CronCommand extends Command {
11
12
	/**
13
	 * {@inheritdoc}
14
	 */
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('time', 't', InputOption::VALUE_OPTIONAL,
22
				'Time of the cron initialization'
23
			);
24
	}
25
26
	/**
27
	 * {@inheritdoc}
28
	 */
29
	protected function command() {
30
31
		$intervals = null;
32
		$interval = $this->option('interval');
33
		if ($interval) {
34
			$intervals = [strtolower($interval)];
35
		}
36
37
		$time = $this->option('time');
38
		if (!$time) {
39
			$time = 'now';
40
		}
41
42
		$time = new \DateTime($time);
43
44
		_elgg_services()->cron->setCurrentTime($time);
45
		$jobs = _elgg_services()->cron->run($intervals);
46
47
		if (!$this->option('quiet')) {
48
			foreach ($jobs as $job) {
49
				$this->write($job->getOutput());
50
			}
51
		}
52
53
		return 1;
54
	}
55
56
}