aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/cron/standard.php
blob: 1cb8738f171dfec743b16c3e04196682ac0f392b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* Standard cron tasks
* @package phpBB3
*/
class cron_tasks_standard
{
	var $tasks = array(
		// key: cron type
		// values: config name for enable/disable flag,
		//         whether to check condition function to determine if the task can/should be run,
		//         config name for interval,
		//         config name for last run time,
		//         whether task should be considered in phpbb cron mode,
		//         whether task should be considered in system cron mode,
		//         whether task requires special code generation
		'prune_all_forums' => array(
			'custom_condition' => true,
			'run_from_system' => true,
		),
		'prune_forum' => array(
			'custom_condition' => true,
			'custom_code' => true,
		),
		'queue' => array(
			'custom_condition' => true,
			'interval_config' => 'queue_interval_config',
			'last_run_config' => 'last_queue_run',
			'run_from_phpbb' => true,
			'run_from_system' => true,
			'shutdown_function_condition' => true,
		),
		'tidy_cache' => array(
			'custom_condition' => true,
			'interval_config' => 'cache_gc',
			'last_run_config' => 'cache_last_gc',
			'run_from_phpbb' => true,
			'run_from_system' => true,
		),
		'tidy_database' => array(
			'interval_config' => 'database_gc',
			'last_run_config' => 'database_last_gc',
			'run_from_phpbb' => true,
			'run_from_system' => true,
		),
		'tidy_search' => array(
			'interval_config' => 'search_gc',
			'last_run_config' => 'search_last_gc',
			'run_from_phpbb' => true,
			'run_from_system' => true,
		),
		'tidy_sessions' => array(
			'interval_config' => 'session_gc',
			'last_run_config' => 'session_last_gc',
			'run_from_phpbb' => true,
			'run_from_system' => true,
		),
		'tidy_warnings' => array(
			'enable_config' => 'warnings_expire_days',
			'interval_config' => 'warnings_gc',
			'last_run_config' => 'warnings_last_gc',
			'run_from_phpbb' => true,
			'run_from_system' => true,
		),
	);
	
	function prune_forum_condition($forum_data) {
		return $forum_data['enable_prune'] && $forum_data['prune_next'] < time();
	}
	
	function prune_forum_code($forum_id) {
		global $phpbb_root_path, $phpEx;
		return '<img src="' . append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=prune_forum&amp;f=' . $forum_id) . '" alt="cron" width="1" height="1" />';
	}
	
	function run_prune_forum() {
	}
	
	function queue_condition() {
		global $phpbb_root_path, $phpEx;
		return file_exists($phpbb_root_path . 'cache/queue.' . $phpEx);
	}
	
	function queue_shutdown_function_condition() {
		global $config;
		return !$config['smtp_delivery'];
	}
	
	function run_queue() {
		global $phpbb_root_path, $phpEx;
		include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
		$queue = new queue();
		$queue->process();
	}
	
	function tidy_cache_condition() {
		global $cache;
		return method_exists($cache, 'tidy');
	}
	
	function run_tidy_cache() {
		global $cache;
		$cache->tidy();
	}
	
	function run_tidy_database() {
		include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
		tidy_database();
	}
	
	function tidy_search_condition() {
		global $phpbb_root_path, $phpEx, $config;
		
		// Select the search method
		$search_type = basename($config['search_type']);
		
		return file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx);
	}
	
	function run_tidy_search() {
		global $phpbb_root_path, $phpEx, $config, $error;
		
		// Select the search method
		$search_type = basename($config['search_type']);
		
		include_once("{$phpbb_root_path}includes/search/$search_type.$phpEx");

		// We do some additional checks in the module to ensure it can actually be utilised
		$error = false;
		$search = new $search_type($error);
		
		if (!$error) {
			$search->tidy();
		}
	}
	
	function run_tidy_sessions() {
		global $user;
		$user->session_gc();
	}
	
	function run_tidy_warnings() {
		include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
		tidy_warnings();
	}
}