6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 define('IN_PHPBB', true);
14 define('IN_CRON', true);
15 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16 $phpEx = substr(strrchr(__FILE__, '.'), 1);
17 include($phpbb_root_path . 'common.' . $phpEx);
19 // Do not update users last page entry
20 $user->session_begin(false);
21 $auth->acl($user->data);
23 $cron_type = request_var('cron_type', '');
25 // Output transparent gif
26 header('Cache-Control: no-cache');
27 header('Content-type: image/gif');
28 header('Content-length: 43');
30 echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
32 // Flush here to prevent browser from showing the page as loading while running cron.
35 if (!isset($config['cron_lock']))
37 set_config('cron_lock', '0', true);
40 // make sure cron doesn't run multiple times in parallel
41 if ($config['cron_lock'])
43 // if the other process is running more than an hour already we have to assume it
44 // aborted without cleaning the lock
45 $time = explode(' ', $config['cron_lock']);
48 if ($time + 3600 >= time())
54 define('CRON_ID', time() . ' ' . unique_id());
56 $sql = 'UPDATE ' . CONFIG_TABLE . "
57 SET config_value = '" . $db->sql_escape(CRON_ID) . "'
58 WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape($config['cron_lock']) . "'";
61 // another cron process altered the table between script start and UPDATE query so exit
62 if ($db->sql_affectedrows() != 1)
68 * Run cron-like action
69 * Real cron-based layer will be introduced in 3.2
75 if (time() - $config['queue_interval'] <= $config['last_queue_run'] || !file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
80 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
89 if (time() - $config['cache_gc'] <= $config['cache_last_gc'] || !method_exists($cache, 'tidy'))
100 // Select the search method
101 $search_type = basename($config['search_type']);
103 if (time() - $config['search_gc'] <= $config['search_last_gc'] || !file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
108 include_once("{$phpbb_root_path}includes/search/$search_type.$phpEx");
110 // We do some additional checks in the module to ensure it can actually be utilised
112 $search = new $search_type($error);
123 case 'tidy_warnings':
125 if (time() - $config['warnings_gc'] <= $config['warnings_last_gc'])
130 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
136 case 'tidy_database':
138 if (time() - $config['database_gc'] <= $config['database_last_gc'])
143 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
149 case 'tidy_sessions':
151 if (time() - $config['session_gc'] <= $config['session_last_gc'])
162 $forum_id = request_var('f', 0);
164 $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
165 FROM ' . FORUMS_TABLE . "
166 WHERE forum_id = $forum_id";
167 $result = $db->sql_query($sql);
168 $row = $db->sql_fetchrow($result);
169 $db->sql_freeresult($result);
176 // Do the forum Prune thang
177 if ($row['prune_next'] < time() && $row['enable_prune'])
179 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
181 if ($row['prune_days'])
183 auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
186 if ($row['prune_viewed'])
188 auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
195 // Unloading cache and closing db after having done the dirty work.
197 garbage_collection();
205 function unlock_cron()
209 $sql = 'UPDATE ' . CONFIG_TABLE . "
210 SET config_value = '0'
211 WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape(CRON_ID) . "'";
212 $db->sql_query($sql);