Completed
Push — master ( 412f0a...ad95e3 )
by Matt
10s
created

autogroups_check::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
*
4
* Auto Groups extension for the phpBB Forum Software package.
5
*
6
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7
* @license GNU General Public License, version 2 (GPL-2.0)
8
*
9
*/
10
11
namespace phpbb\autogroups\cron;
12
13
/**
14
 * Auto groups cron task.
15
 */
16
class autogroups_check extends \phpbb\cron\task\base
17
{
18
	/** @var \phpbb\config\config */
19
	protected $config;
20
21
	/** @var \phpbb\autogroups\conditions\manager */
22
	protected $manager;
23
24
	/**
25
	 * Constructor
26
	 *
27
	 * @param \phpbb\config\config                 $config  Config object
28
	 * @param \phpbb\autogroups\conditions\manager $manager Auto groups condition manager object
29
	 * @access public
30
	 */
31
	public function __construct(\phpbb\config\config $config, \phpbb\autogroups\conditions\manager $manager)
32
	{
33
		$this->config = $config;
34
		$this->manager = $manager;
35
	}
36
37
	/**
38
	 * Runs this cron task.
39
	 *
40
	 * @return void
41
	 */
42
	public function run()
43
	{
44
		$this->manager->check_conditions();
45
		$this->config->set('autogroups_last_run', time(), false);
46
	}
47
48
	/**
49
	 * Returns whether this cron task should run now, because enough time
50
	 * has passed since it was last run (24 hours).
51
	 *
52
	 * @return bool
53
	 */
54
	public function should_run()
55
	{
56
		return $this->config['autogroups_last_run'] < strtotime('24 hours ago');
57
	}
58
}
59