Conditions | 4 |
Paths | 4 |
Total Lines | 36 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 9.8312 |
Changes | 0 |
1 | <?php |
||
20 | 1 | protected function execute(InputInterface $input, OutputInterface $output) |
|
21 | { |
||
22 | |||
23 | 1 | $doctrine = $this->getContainer()->get('doctrine'); |
|
24 | |||
25 | 1 | $crons = $doctrine->getManager()->getRepository('AppBundle:Action')->findBy(['type'=>'cron']); |
|
26 | |||
27 | /** @var Action $cronAction */ |
||
28 | 1 | foreach ($crons as $cronAction) { |
|
29 | $args = json_decode($cronAction->getArguments(), true); |
||
30 | |||
31 | if (isset($args['disabled'])) { |
||
32 | continue; |
||
33 | } |
||
34 | |||
35 | if (time() - $args['last'] >= $args['every']) { |
||
36 | $output->writeln( |
||
37 | 'Running '.$cronAction->getExecutor().' for "'. |
||
38 | $cronAction->getDevice()->getName().'" device' |
||
39 | ); |
||
40 | $this-> |
||
41 | getContainer() |
||
42 | ->get('actions') |
||
43 | ->executeReal( |
||
44 | $cronAction, |
||
45 | 'cron', |
||
46 | ['container'=>$this->getContainer()] |
||
47 | ); |
||
48 | $args['last'] = time(); |
||
49 | $cronAction->setArguments(json_encode($args)); |
||
50 | $doctrine->getManager()->persist($cronAction); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | 1 | $doctrine->getManager()->flush(); |
|
55 | 1 | } |
|
56 | } |
||
57 |