2006-01-19 16:38:00 +00:00
|
|
|
<?php
|
2007-10-05 14:30:11 +00:00
|
|
|
/**
|
2005-04-30 14:28:07 +00:00
|
|
|
*
|
|
|
|
* @package phpBB3
|
|
|
|
* @version $Id$
|
2007-10-05 14:30:11 +00:00
|
|
|
* @copyright (c) 2005 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
2005-04-30 14:28:07 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
define('IN_PHPBB', true);
|
|
|
|
define('IN_CRON', true);
|
2007-07-26 15:51:11 +00:00
|
|
|
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
2005-04-30 14:28:07 +00:00
|
|
|
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
2006-05-18 18:18:32 +00:00
|
|
|
include($phpbb_root_path . 'common.' . $phpEx);
|
2005-04-30 14:28:07 +00:00
|
|
|
|
2006-06-11 18:13:52 +00:00
|
|
|
// Do not update users last page entry
|
|
|
|
$user->session_begin(false);
|
2006-05-21 16:54:19 +00:00
|
|
|
$auth->acl($user->data);
|
|
|
|
|
2005-04-30 14:28:07 +00:00
|
|
|
$cron_type = request_var('cron_type', '');
|
|
|
|
|
2006-08-25 15:15:53 +00:00
|
|
|
// Output transparent gif
|
|
|
|
header('Cache-Control: no-cache');
|
|
|
|
header('Content-type: image/gif');
|
|
|
|
header('Content-length: 43');
|
|
|
|
|
|
|
|
echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
|
|
|
|
|
2011-03-12 14:40:20 +01:00
|
|
|
// Flush here to prevent browser from showing the page as loading while running cron.
|
|
|
|
flush();
|
2006-08-25 15:15:53 +00:00
|
|
|
|
2007-08-12 18:16:01 +00:00
|
|
|
if (!isset($config['cron_lock']))
|
|
|
|
{
|
|
|
|
set_config('cron_lock', '0', true);
|
|
|
|
}
|
|
|
|
|
2007-07-25 17:58:39 +00:00
|
|
|
// make sure cron doesn't run multiple times in parallel
|
|
|
|
if ($config['cron_lock'])
|
|
|
|
{
|
|
|
|
// if the other process is running more than an hour already we have to assume it
|
|
|
|
// aborted without cleaning the lock
|
|
|
|
$time = explode(' ', $config['cron_lock']);
|
|
|
|
$time = $time[0];
|
|
|
|
|
|
|
|
if ($time + 3600 >= time())
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define('CRON_ID', time() . ' ' . unique_id());
|
|
|
|
|
|
|
|
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
|
|
|
SET config_value = '" . $db->sql_escape(CRON_ID) . "'
|
|
|
|
WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape($config['cron_lock']) . "'";
|
|
|
|
$db->sql_query($sql);
|
|
|
|
|
|
|
|
// another cron process altered the table between script start and UPDATE query so exit
|
|
|
|
if ($db->sql_affectedrows() != 1)
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2005-10-19 18:00:10 +00:00
|
|
|
/**
|
|
|
|
* Run cron-like action
|
|
|
|
* Real cron-based layer will be introduced in 3.2
|
|
|
|
*/
|
2005-04-30 14:28:07 +00:00
|
|
|
switch ($cron_type)
|
|
|
|
{
|
|
|
|
case 'queue':
|
2006-05-18 18:18:32 +00:00
|
|
|
|
|
|
|
if (time() - $config['queue_interval'] <= $config['last_queue_run'] || !file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
2005-04-30 14:28:07 +00:00
|
|
|
$queue = new queue();
|
2006-05-18 18:18:32 +00:00
|
|
|
|
2011-03-12 14:29:34 +01:00
|
|
|
$queue->process();
|
2006-05-18 18:18:32 +00:00
|
|
|
|
2005-10-19 18:00:10 +00:00
|
|
|
break;
|
2005-04-30 14:28:07 +00:00
|
|
|
|
|
|
|
case 'tidy_cache':
|
2006-05-18 18:18:32 +00:00
|
|
|
|
|
|
|
if (time() - $config['cache_gc'] <= $config['cache_last_gc'] || !method_exists($cache, 'tidy'))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-12 14:29:34 +01:00
|
|
|
$cache->tidy();
|
2006-05-18 18:18:32 +00:00
|
|
|
|
2005-10-19 18:00:10 +00:00
|
|
|
break;
|
2005-04-30 14:28:07 +00:00
|
|
|
|
2006-01-18 19:26:04 +00:00
|
|
|
case 'tidy_search':
|
2006-05-18 18:18:32 +00:00
|
|
|
|
2006-01-19 16:38:00 +00:00
|
|
|
// Select the search method
|
2006-05-18 18:18:32 +00:00
|
|
|
$search_type = basename($config['search_type']);
|
2006-01-19 16:38:00 +00:00
|
|
|
|
2006-05-18 18:18:32 +00:00
|
|
|
if (time() - $config['search_gc'] <= $config['search_last_gc'] || !file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
|
2006-01-19 16:38:00 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2006-05-18 18:18:32 +00:00
|
|
|
|
2006-01-19 16:38:00 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-12 14:29:34 +01:00
|
|
|
$search->tidy();
|
2006-05-18 18:18:32 +00:00
|
|
|
|
|
|
|
break;
|
2006-01-18 19:26:04 +00:00
|
|
|
|
2006-03-04 17:34:04 +00:00
|
|
|
case 'tidy_warnings':
|
2006-05-18 18:18:32 +00:00
|
|
|
|
|
|
|
if (time() - $config['warnings_gc'] <= $config['warnings_last_gc'])
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
2006-03-04 17:34:04 +00:00
|
|
|
|
2011-03-12 14:29:34 +01:00
|
|
|
tidy_warnings();
|
2006-05-18 18:18:32 +00:00
|
|
|
|
2006-03-04 17:34:04 +00:00
|
|
|
break;
|
|
|
|
|
2005-04-30 14:28:07 +00:00
|
|
|
case 'tidy_database':
|
2006-05-18 18:18:32 +00:00
|
|
|
|
|
|
|
if (time() - $config['database_gc'] <= $config['database_last_gc'])
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
2005-04-30 14:28:07 +00:00
|
|
|
|
2011-03-12 14:29:34 +01:00
|
|
|
tidy_database();
|
2006-05-18 18:18:32 +00:00
|
|
|
|
2005-10-19 18:00:10 +00:00
|
|
|
break;
|
2006-01-19 16:38:00 +00:00
|
|
|
|
2005-10-19 18:00:10 +00:00
|
|
|
case 'tidy_sessions':
|
2006-05-18 18:18:32 +00:00
|
|
|
|
|
|
|
if (time() - $config['session_gc'] <= $config['session_last_gc'])
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-12 14:29:34 +01:00
|
|
|
$user->session_gc();
|
2006-05-18 18:18:32 +00:00
|
|
|
|
2005-10-19 18:00:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'prune_forum':
|
|
|
|
|
|
|
|
$forum_id = request_var('f', 0);
|
2006-01-19 16:38:00 +00:00
|
|
|
|
2005-10-19 18:00:10 +00:00
|
|
|
$sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
|
|
|
|
FROM ' . FORUMS_TABLE . "
|
|
|
|
WHERE forum_id = $forum_id";
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
$row = $db->sql_fetchrow($result);
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
if (!$row)
|
|
|
|
{
|
|
|
|
break;
|
2005-07-04 11:53:57 +00:00
|
|
|
}
|
2005-10-19 18:00:10 +00:00
|
|
|
|
|
|
|
// Do the forum Prune thang
|
|
|
|
if ($row['prune_next'] < time() && $row['enable_prune'])
|
|
|
|
{
|
2006-05-18 18:18:32 +00:00
|
|
|
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
2005-10-19 18:00:10 +00:00
|
|
|
|
|
|
|
if ($row['prune_days'])
|
|
|
|
{
|
2011-03-12 14:29:34 +01:00
|
|
|
auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
|
2005-10-19 18:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($row['prune_viewed'])
|
|
|
|
{
|
2011-03-12 14:29:34 +01:00
|
|
|
auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
|
2005-10-19 18:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2005-04-30 14:28:07 +00:00
|
|
|
}
|
|
|
|
|
2006-06-13 15:06:32 +00:00
|
|
|
// Unloading cache and closing db after having done the dirty work.
|
2011-03-12 14:29:34 +01:00
|
|
|
unlock_cron();
|
|
|
|
garbage_collection();
|
2006-06-12 22:16:27 +00:00
|
|
|
|
2005-04-30 14:28:07 +00:00
|
|
|
exit;
|
|
|
|
|
2007-09-12 15:32:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlock cron script
|
|
|
|
*/
|
|
|
|
function unlock_cron()
|
|
|
|
{
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
|
|
|
SET config_value = '0'
|
|
|
|
WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape(CRON_ID) . "'";
|
|
|
|
$db->sql_query($sql);
|
|
|
|
}
|
|
|
|
|
2005-04-30 14:28:07 +00:00
|
|
|
?>
|