|
indvdum@0
|
1 |
<?php
|
|
indvdum@0
|
2 |
/**
|
|
indvdum@0
|
3 |
*
|
|
indvdum@0
|
4 |
* @package phpBB3
|
|
indvdum@0
|
5 |
* @version $Id$
|
|
indvdum@0
|
6 |
* @copyright (c) 2005 phpBB Group
|
|
indvdum@0
|
7 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
indvdum@0
|
8 |
*
|
|
indvdum@0
|
9 |
*/
|
|
indvdum@0
|
10 |
|
|
indvdum@0
|
11 |
/**
|
|
indvdum@0
|
12 |
*/
|
|
indvdum@0
|
13 |
define('IN_PHPBB', true);
|
|
indvdum@0
|
14 |
define('IN_CRON', true);
|
|
indvdum@0
|
15 |
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
|
indvdum@0
|
16 |
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
|
indvdum@0
|
17 |
include($phpbb_root_path . 'common.' . $phpEx);
|
|
indvdum@0
|
18 |
|
|
indvdum@0
|
19 |
// Do not update users last page entry
|
|
indvdum@0
|
20 |
$user->session_begin(false);
|
|
indvdum@0
|
21 |
$auth->acl($user->data);
|
|
indvdum@0
|
22 |
|
|
indvdum@0
|
23 |
$cron_type = request_var('cron_type', '');
|
|
indvdum@0
|
24 |
|
|
indvdum@0
|
25 |
// Output transparent gif
|
|
indvdum@0
|
26 |
header('Cache-Control: no-cache');
|
|
indvdum@0
|
27 |
header('Content-type: image/gif');
|
|
indvdum@0
|
28 |
header('Content-length: 43');
|
|
indvdum@0
|
29 |
|
|
indvdum@0
|
30 |
echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
|
|
indvdum@0
|
31 |
|
|
indvdum@0
|
32 |
// Flush here to prevent browser from showing the page as loading while running cron.
|
|
indvdum@0
|
33 |
flush();
|
|
indvdum@0
|
34 |
|
|
indvdum@0
|
35 |
if (!isset($config['cron_lock']))
|
|
indvdum@0
|
36 |
{
|
|
indvdum@0
|
37 |
set_config('cron_lock', '0', true);
|
|
indvdum@0
|
38 |
}
|
|
indvdum@0
|
39 |
|
|
indvdum@0
|
40 |
// make sure cron doesn't run multiple times in parallel
|
|
indvdum@0
|
41 |
if ($config['cron_lock'])
|
|
indvdum@0
|
42 |
{
|
|
indvdum@0
|
43 |
// if the other process is running more than an hour already we have to assume it
|
|
indvdum@0
|
44 |
// aborted without cleaning the lock
|
|
indvdum@0
|
45 |
$time = explode(' ', $config['cron_lock']);
|
|
indvdum@0
|
46 |
$time = $time[0];
|
|
indvdum@0
|
47 |
|
|
indvdum@0
|
48 |
if ($time + 3600 >= time())
|
|
indvdum@0
|
49 |
{
|
|
indvdum@0
|
50 |
exit;
|
|
indvdum@0
|
51 |
}
|
|
indvdum@0
|
52 |
}
|
|
indvdum@0
|
53 |
|
|
indvdum@0
|
54 |
define('CRON_ID', time() . ' ' . unique_id());
|
|
indvdum@0
|
55 |
|
|
indvdum@0
|
56 |
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
|
indvdum@0
|
57 |
SET config_value = '" . $db->sql_escape(CRON_ID) . "'
|
|
indvdum@0
|
58 |
WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape($config['cron_lock']) . "'";
|
|
indvdum@0
|
59 |
$db->sql_query($sql);
|
|
indvdum@0
|
60 |
|
|
indvdum@0
|
61 |
// another cron process altered the table between script start and UPDATE query so exit
|
|
indvdum@0
|
62 |
if ($db->sql_affectedrows() != 1)
|
|
indvdum@0
|
63 |
{
|
|
indvdum@0
|
64 |
exit;
|
|
indvdum@0
|
65 |
}
|
|
indvdum@0
|
66 |
|
|
indvdum@0
|
67 |
/**
|
|
indvdum@0
|
68 |
* Run cron-like action
|
|
indvdum@0
|
69 |
* Real cron-based layer will be introduced in 3.2
|
|
indvdum@0
|
70 |
*/
|
|
indvdum@0
|
71 |
switch ($cron_type)
|
|
indvdum@0
|
72 |
{
|
|
indvdum@0
|
73 |
case 'queue':
|
|
indvdum@0
|
74 |
|
|
indvdum@0
|
75 |
if (time() - $config['queue_interval'] <= $config['last_queue_run'] || !file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
|
|
indvdum@0
|
76 |
{
|
|
indvdum@0
|
77 |
break;
|
|
indvdum@0
|
78 |
}
|
|
indvdum@0
|
79 |
|
|
indvdum@0
|
80 |
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
|
indvdum@0
|
81 |
$queue = new queue();
|
|
indvdum@0
|
82 |
|
|
indvdum@0
|
83 |
$queue->process();
|
|
indvdum@0
|
84 |
|
|
indvdum@0
|
85 |
break;
|
|
indvdum@0
|
86 |
|
|
indvdum@0
|
87 |
case 'tidy_cache':
|
|
indvdum@0
|
88 |
|
|
indvdum@0
|
89 |
if (time() - $config['cache_gc'] <= $config['cache_last_gc'] || !method_exists($cache, 'tidy'))
|
|
indvdum@0
|
90 |
{
|
|
indvdum@0
|
91 |
break;
|
|
indvdum@0
|
92 |
}
|
|
indvdum@0
|
93 |
|
|
indvdum@0
|
94 |
$cache->tidy();
|
|
indvdum@0
|
95 |
|
|
indvdum@0
|
96 |
break;
|
|
indvdum@0
|
97 |
|
|
indvdum@0
|
98 |
case 'tidy_search':
|
|
indvdum@0
|
99 |
|
|
indvdum@0
|
100 |
// Select the search method
|
|
indvdum@0
|
101 |
$search_type = basename($config['search_type']);
|
|
indvdum@0
|
102 |
|
|
indvdum@0
|
103 |
if (time() - $config['search_gc'] <= $config['search_last_gc'] || !file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
|
|
indvdum@0
|
104 |
{
|
|
indvdum@0
|
105 |
break;
|
|
indvdum@0
|
106 |
}
|
|
indvdum@0
|
107 |
|
|
indvdum@0
|
108 |
include_once("{$phpbb_root_path}includes/search/$search_type.$phpEx");
|
|
indvdum@0
|
109 |
|
|
indvdum@0
|
110 |
// We do some additional checks in the module to ensure it can actually be utilised
|
|
indvdum@0
|
111 |
$error = false;
|
|
indvdum@0
|
112 |
$search = new $search_type($error);
|
|
indvdum@0
|
113 |
|
|
indvdum@0
|
114 |
if ($error)
|
|
indvdum@0
|
115 |
{
|
|
indvdum@0
|
116 |
break;
|
|
indvdum@0
|
117 |
}
|
|
indvdum@0
|
118 |
|
|
indvdum@0
|
119 |
$search->tidy();
|
|
indvdum@0
|
120 |
|
|
indvdum@0
|
121 |
break;
|
|
indvdum@0
|
122 |
|
|
indvdum@0
|
123 |
case 'tidy_warnings':
|
|
indvdum@0
|
124 |
|
|
indvdum@0
|
125 |
if (time() - $config['warnings_gc'] <= $config['warnings_last_gc'])
|
|
indvdum@0
|
126 |
{
|
|
indvdum@0
|
127 |
break;
|
|
indvdum@0
|
128 |
}
|
|
indvdum@0
|
129 |
|
|
indvdum@0
|
130 |
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|
indvdum@0
|
131 |
|
|
indvdum@0
|
132 |
tidy_warnings();
|
|
indvdum@0
|
133 |
|
|
indvdum@0
|
134 |
break;
|
|
indvdum@0
|
135 |
|
|
indvdum@0
|
136 |
case 'tidy_database':
|
|
indvdum@0
|
137 |
|
|
indvdum@0
|
138 |
if (time() - $config['database_gc'] <= $config['database_last_gc'])
|
|
indvdum@0
|
139 |
{
|
|
indvdum@0
|
140 |
break;
|
|
indvdum@0
|
141 |
}
|
|
indvdum@0
|
142 |
|
|
indvdum@0
|
143 |
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|
indvdum@0
|
144 |
|
|
indvdum@0
|
145 |
tidy_database();
|
|
indvdum@0
|
146 |
|
|
indvdum@0
|
147 |
break;
|
|
indvdum@0
|
148 |
|
|
indvdum@0
|
149 |
case 'tidy_sessions':
|
|
indvdum@0
|
150 |
|
|
indvdum@0
|
151 |
if (time() - $config['session_gc'] <= $config['session_last_gc'])
|
|
indvdum@0
|
152 |
{
|
|
indvdum@0
|
153 |
break;
|
|
indvdum@0
|
154 |
}
|
|
indvdum@0
|
155 |
|
|
indvdum@0
|
156 |
$user->session_gc();
|
|
indvdum@0
|
157 |
|
|
indvdum@0
|
158 |
break;
|
|
indvdum@0
|
159 |
|
|
indvdum@0
|
160 |
case 'prune_forum':
|
|
indvdum@0
|
161 |
|
|
indvdum@0
|
162 |
$forum_id = request_var('f', 0);
|
|
indvdum@0
|
163 |
|
|
indvdum@0
|
164 |
$sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
|
|
indvdum@0
|
165 |
FROM ' . FORUMS_TABLE . "
|
|
indvdum@0
|
166 |
WHERE forum_id = $forum_id";
|
|
indvdum@0
|
167 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
168 |
$row = $db->sql_fetchrow($result);
|
|
indvdum@0
|
169 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
170 |
|
|
indvdum@0
|
171 |
if (!$row)
|
|
indvdum@0
|
172 |
{
|
|
indvdum@0
|
173 |
break;
|
|
indvdum@0
|
174 |
}
|
|
indvdum@0
|
175 |
|
|
indvdum@0
|
176 |
// Do the forum Prune thang
|
|
indvdum@0
|
177 |
if ($row['prune_next'] < time() && $row['enable_prune'])
|
|
indvdum@0
|
178 |
{
|
|
indvdum@0
|
179 |
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|
indvdum@0
|
180 |
|
|
indvdum@0
|
181 |
if ($row['prune_days'])
|
|
indvdum@0
|
182 |
{
|
|
indvdum@0
|
183 |
auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
|
|
indvdum@0
|
184 |
}
|
|
indvdum@0
|
185 |
|
|
indvdum@0
|
186 |
if ($row['prune_viewed'])
|
|
indvdum@0
|
187 |
{
|
|
indvdum@0
|
188 |
auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
|
|
indvdum@0
|
189 |
}
|
|
indvdum@0
|
190 |
}
|
|
indvdum@0
|
191 |
|
|
indvdum@0
|
192 |
break;
|
|
indvdum@0
|
193 |
}
|
|
indvdum@0
|
194 |
|
|
indvdum@0
|
195 |
// Unloading cache and closing db after having done the dirty work.
|
|
indvdum@0
|
196 |
unlock_cron();
|
|
indvdum@0
|
197 |
garbage_collection();
|
|
indvdum@0
|
198 |
|
|
indvdum@0
|
199 |
exit;
|
|
indvdum@0
|
200 |
|
|
indvdum@0
|
201 |
|
|
indvdum@0
|
202 |
/**
|
|
indvdum@0
|
203 |
* Unlock cron script
|
|
indvdum@0
|
204 |
*/
|
|
indvdum@0
|
205 |
function unlock_cron()
|
|
indvdum@0
|
206 |
{
|
|
indvdum@0
|
207 |
global $db;
|
|
indvdum@0
|
208 |
|
|
indvdum@0
|
209 |
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
|
indvdum@0
|
210 |
SET config_value = '0'
|
|
indvdum@0
|
211 |
WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape(CRON_ID) . "'";
|
|
indvdum@0
|
212 |
$db->sql_query($sql);
|
|
indvdum@0
|
213 |
}
|
|
indvdum@0
|
214 |
|
|
indvdum@0
|
215 |
?> |