1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Reduce Search Index [RSI]. An extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2020-forever, Dark❶, https://dark1.tech |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace dark1\reducesearchindex\controller; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @ignore |
15
|
|
|
*/ |
16
|
|
|
use dark1\reducesearchindex\core\consts; |
17
|
|
|
use phpbb\language\language; |
18
|
|
|
use phpbb\log\log; |
19
|
|
|
use phpbb\request\request; |
20
|
|
|
use phpbb\template\template; |
21
|
|
|
use phpbb\user; |
22
|
|
|
use phpbb\config\config; |
23
|
|
|
use phpbb\cron\manager as cron_manager; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Reduce Search Index [RSI] ACP controller Cron. |
27
|
|
|
*/ |
28
|
|
|
class acp_cron extends acp_base |
29
|
|
|
{ |
30
|
|
|
/** @var config */ |
31
|
|
|
protected $config; |
32
|
|
|
|
33
|
|
|
/** @var cron_manager */ |
34
|
|
|
protected $cron_manager; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor. |
38
|
|
|
* |
39
|
|
|
* @param language $language Language object |
40
|
|
|
* @param log $log Log object |
41
|
|
|
* @param request $request Request object |
42
|
|
|
* @param template $template Template object |
43
|
|
|
* @param user $user User object |
44
|
|
|
* @param config $config Config object |
45
|
|
|
* @param cron_manager $cron_manager Cron manager |
46
|
|
|
*/ |
47
|
|
|
public function __construct(language $language, log $log, request $request, template $template, user $user, config $config, cron_manager $cron_manager) |
48
|
|
|
{ |
49
|
|
|
parent::__construct($language, $log, $request, $template, $user); |
50
|
|
|
|
51
|
|
|
$this->config = $config; |
52
|
|
|
$this->cron_manager = $cron_manager; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Display the options a user can configure for Cron Mode. |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
* @access public |
60
|
|
|
*/ |
61
|
|
|
public function handle() |
62
|
|
|
{ |
63
|
|
|
// Is the form being submitted to us? |
64
|
|
|
if ($this->request->is_set_post('submit')) |
65
|
|
|
{ |
66
|
|
|
$this->check_form_on_submit(); |
67
|
|
|
|
68
|
|
|
// Set the options the user configured |
69
|
|
|
$this->config->set('dark1_rsi_auto_reduce_sync_enable', $this->request->variable('dark1_rsi_auto_reduce_sync_enable', 0)); |
70
|
|
|
$this->config->set('dark1_rsi_auto_reduce_sync_gc', ($this->request->variable('dark1_rsi_auto_reduce_sync_gc', 0)) * 86400); |
71
|
|
|
|
72
|
|
|
$this->success_form_on_submit(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// Run Cron Task |
76
|
|
|
if ($this->request->is_set_post('runcrontask')) |
77
|
|
|
{ |
78
|
|
|
$this->check_form_on_submit(); |
79
|
|
|
|
80
|
|
|
$cron_task = $this->cron_manager->find_task('dark1.reducesearchindex.cron.auto_reduce_sync'); |
81
|
|
|
$cron_task->run(); |
82
|
|
|
|
83
|
|
|
$this->success_form_on_submit('ACP_RSI_LOG_CRON', ''); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// Set output variables for display in the template |
87
|
|
|
$this->template->assign_vars([ |
88
|
|
|
'RSI_ENABLE_CRON' => $this->config['dark1_rsi_auto_reduce_sync_enable'], |
89
|
|
|
'RSI_CRON_INTERVAL' => ($this->config['dark1_rsi_auto_reduce_sync_gc'] / 86400), |
90
|
|
|
'RSI_CRON_LAST_RUN' => $this->user->format_date($this->config['dark1_rsi_auto_reduce_sync_last_gc'], consts::TIME_FORMAT, true), |
91
|
|
|
'RSI_CRON_NEXT_RUN' => $this->user->format_date($this->config['dark1_rsi_auto_reduce_sync_last_gc'] + $this->config['dark1_rsi_auto_reduce_sync_gc'], consts::TIME_FORMAT, true), |
92
|
|
|
]); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|