Completed
Push — master ( 42e677...2a102b )
by Matt
18s queued 11s
created

purge_cache::should_run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * phpBB Media Embed PlugIn extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2020 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\mediaembed\cron;
12
13
use phpbb\config\config;
14
use phpbb\mediaembed\cache\cache;
15
16
/**
17
 * Media Embed cron task.
18
 */
19
class purge_cache extends \phpbb\cron\task\base
20
{
21
	/** @var config $config */
22
	protected $config;
23
24
	/** @var cache $cache */
25
	protected $cache;
26
27
	/**
28
	 * Constructor
29
	 *
30
	 * @param config $config Config object
31
	 * @param cache  $cache  MediaEmbed cache object
32
	 */
33
	public function __construct(config $config, cache $cache)
34
	{
35
		$this->config = $config;
36
		$this->cache = $cache;
37
	}
38
39
	/**
40
	 * {@inheritDoc}
41
	 */
42
	public function run()
43
	{
44
		try
45
		{
46
			$this->cache->purge_mediaembed_cache();
47
			$this->config->set('mediaembed_last_gc', time(), false);
48
		}
49
		catch (\RuntimeException $e)
50
		{
51
			return;
52
		}
53
	}
54
55
	/**
56
	 * {@inheritDoc}
57
	 */
58
	public function is_runnable()
59
	{
60
		return (bool) $this->config['media_embed_enable_cache'];
61
	}
62
63
	/**
64
	 * {@inheritDoc}
65
	 */
66
	public function should_run()
67
	{
68
		return $this->config['mediaembed_last_gc'] < strtotime('24 hours ago');
69
	}
70
}
71