Cronjob   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 53
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B autorun() 0 44 5
1
<?php
2
namespace Redaxscript\Bootstrap;
3
4
use Redaxscript\Dater;
5
use Redaxscript\Model;
6
use Redaxscript\Module;
7
8
/**
9
 * children class to boot the cronjob
10
 *
11
 * @since 3.1.0
12
 *
13
 * @package Redaxscript
14
 * @category Bootstrap
15
 * @author Henry Ruhs
16
 */
17
18
class Cronjob extends BootstrapAbstract
19
{
20
	/**
21
	 * automate run
22
	 *
23
	 * @since 3.1.0
24
	 */
25
26 2
	public function autorun() : void
27
	{
28 2
		$dater = new Dater();
29 2
		$dater->init();
30 2
		$this->_registry->set('now', $dater->getDateTime()->getTimestamp());
31 2
		$this->_registry->set('cronUpdate', false);
32
33
		/* set the update */
34
35 2
		if (!$this->_request->getSession('nextUpdate'))
36
		{
37 1
			$this->_request->setSession('nextUpdate', $dater->getDateTime()->modify('+1 minute')->getTimestamp());
38 1
			$this->_registry->set('cronUpdate', true);
39
		}
40
41
		/* reset the update */
42
43 2
		if ($this->_request->getSession('nextUpdate') < $this->_registry->get('now'))
44
		{
45 1
			$this->_request->setSession('nextUpdate', false);
46
		}
47
48
		/* trigger update */
49
50 2
		if ($this->_registry->get('cronUpdate'))
51
		{
52 1
			Module\Hook::trigger('cronUpdate');
53 1
			if ($this->_registry->get('dbStatus') === 2)
54
			{
55 1
				$categoryModel = new Model\Category();
56 1
				$articleModel = new Model\Article();
57 1
				$commentModel = new Model\Comment();
58 1
				$extraModel = new Model\Extra();
59 1
				$now = $this->_registry->get('now');
60
61
				/* publish by date */
62
63 1
				$categoryModel->publishByDate($now);
64 1
				$articleModel->publishByDate($now);
65 1
				$commentModel->publishByDate($now);
66 1
				$extraModel->publishByDate($now);
67
			}
68
		}
69 2
	}
70
}
71