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

purge_cache   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 52
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A run() 0 12 2
A is_runnable() 0 4 1
A should_run() 0 4 1
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