Passed
Pull Request — master (#5)
by Dark❶
07:47
created

acp_prune   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 27
c 1
b 0
f 0
dl 0
loc 75
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 34 3
A __construct() 0 7 1
1
<?php
2
/**
3
 *
4
 * User Notification Control [UNC]. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2020-2021, Dark❶, https://dark1.tech
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace dark1\usernotificationcontrol\controller;
12
13
/**
14
 * @ignore
15
 */
16
use phpbb\language\language;
17
use phpbb\log\log;
18
use phpbb\request\request;
19
use phpbb\template\template;
20
use phpbb\user;
21
use phpbb\config\config;
22
use phpbb\cron\manager as cron_manager;
23
use phpbb\db\driver\driver_interface as db_driver;
24
25
/**
26
 * User Notification Control [UNC] ACP controller Prune.
27
 */
28
class acp_prune extends acp_base
29
{
30
	/** @var config */
31
	protected $config;
32
33
	/** @var cron_manager */
34
	protected $cron_manager;
35
36
	/** @var db_driver */
37
	protected $db;
38
39
	/** Time Format */
40
	const TIME_FORMAT	= 'Y-m-d h:i:s A P';
41
42
	/**
43
	 * Constructor.
44
	 *
45
	 * @param language			$language		Language object
46
	 * @param log				$log			Log object
47
	 * @param request			$request		Request object
48
	 * @param template			$template		Template object
49
	 * @param user				$user			User object
50
	 * @param config			$config			Config object
51
	 * @param cron_manager		$cron_manager	Cron manager
52
	 * @param db_driver			$db				Database object
53
	 */
54
	public function __construct(language $language, log $log, request $request, template $template, user $user, config $config, cron_manager $cron_manager, db_driver $db)
55
	{
56
		parent::__construct($language, $log, $request, $template, $user);
57
58
		$this->config			= $config;
59
		$this->cron_manager		= $cron_manager;
60
		$this->db				= $db;
61
	}
62
63
	/**
64
	 * Display the options a user can configure for Cron Mode.
65
	 *
66
	 * @return void
67
	 * @access public
68
	 */
69
	public function handle()
70
	{
71
		// Is the form being submitted to us?
72
		if ($this->request->is_set_post('submit'))
73
		{
74
			$this->check_form_on_submit();
75
76
			// Set the options the user configured
77
			$this->config->set('dark1_unc_all_notify_expire_days', $this->request->variable('dark1_unc_all_notify_expire_days', 0));
78
			$this->config->set('dark1_unc_auto_prune_notify_enable', $this->request->variable('dark1_unc_auto_prune_notify_enable', 0));
79
			$this->config->set('dark1_unc_auto_prune_notify_gc', ($this->request->variable('dark1_unc_auto_prune_notify_gc', 0)) * 86400);
80
81
			$this->success_form_on_submit();
82
		}
83
84
		// Run Cron Task
85
		if ($this->request->is_set_post('runcrontask'))
86
		{
87
			$this->check_form_on_submit();
88
89
			$cron_task = $this->cron_manager->find_task('dark1.usernotificationcontrol.cron.auto_prune_notify');
90
			$cron_task->run();
91
92
			$this->success_form_on_submit();
93
		}
94
95
		// Set output variables for display in the template
96
		$this->template->assign_vars([
97
			'UNC_READ_EXPIRE'		=> $this->config['read_notification_expire_days'],
98
			'UNC_ALL_EXPIRE'		=> $this->config['dark1_unc_all_notify_expire_days'],
99
			'UNC_ENABLE_CRON'		=> $this->config['dark1_unc_auto_prune_notify_enable'],
100
			'UNC_CRON_INTERVAL'		=> ($this->config['dark1_unc_auto_prune_notify_gc'] / 86400),
101
			'UNC_CRON_LAST_RUN'		=> $this->user->format_date($this->config['dark1_unc_auto_prune_notify_last_gc'], self::TIME_FORMAT, true),
102
			'UNC_CRON_NEXT_RUN'		=> $this->user->format_date($this->config['dark1_unc_auto_prune_notify_last_gc'] + $this->config['dark1_unc_auto_prune_notify_gc'], self::TIME_FORMAT, true),
103
		]);
104
	}
105
}
106