|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @package phpBB3
|
|
|
4c79b5 |
* @version $Id: cron.php 8479 2008-03-29 00:22:48Z naderman $
|
|
|
4c79b5 |
* @copyright (c) 2005 phpBB Group
|
|
|
4c79b5 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
define('IN_PHPBB', true);
|
|
|
4c79b5 |
define('IN_CRON', true);
|
|
|
4c79b5 |
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
|
|
4c79b5 |
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
|
|
4c79b5 |
include($phpbb_root_path . 'common.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Do not update users last page entry
|
|
|
4c79b5 |
$user->session_begin(false);
|
|
|
4c79b5 |
$auth->acl($user->data);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cron_type = request_var('cron_type', '');
|
|
|
4c79b5 |
$use_shutdown_function = (@function_exists('register_shutdown_function')) ? true : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Output transparent gif
|
|
|
4c79b5 |
header('Cache-Control: no-cache');
|
|
|
4c79b5 |
header('Content-type: image/gif');
|
|
|
4c79b5 |
header('Content-length: 43');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// test without flush ;)
|
|
|
4c79b5 |
// flush();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
//
|
|
|
4c79b5 |
if (!isset($config['cron_lock']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
set_config('cron_lock', '0', true);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// make sure cron doesn't run multiple times in parallel
|
|
|
4c79b5 |
if ($config['cron_lock'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// if the other process is running more than an hour already we have to assume it
|
|
|
4c79b5 |
// aborted without cleaning the lock
|
|
|
4c79b5 |
$time = explode(' ', $config['cron_lock']);
|
|
|
4c79b5 |
$time = $time[0];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($time + 3600 >= time())
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
define('CRON_ID', time() . ' ' . unique_id());
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
|
|
4c79b5 |
SET config_value = '" . $db->sql_escape(CRON_ID) . "'
|
|
|
4c79b5 |
WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape($config['cron_lock']) . "'";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// another cron process altered the table between script start and UPDATE query so exit
|
|
|
4c79b5 |
if ($db->sql_affectedrows() != 1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Run cron-like action
|
|
|
4c79b5 |
* Real cron-based layer will be introduced in 3.2
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
switch ($cron_type)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'queue':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (time() - $config['queue_interval'] <= $config['last_queue_run'] || !file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// A user reported using the mail() function while using shutdown does not work. We do not want to risk that.
|
|
|
4c79b5 |
if ($use_shutdown_function && !$config['smtp_delivery'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$use_shutdown_function = false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
|
|
4c79b5 |
$queue = new queue();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($use_shutdown_function)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
register_shutdown_function(array(&$queue, 'process'));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$queue->process();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'tidy_cache':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (time() - $config['cache_gc'] <= $config['cache_last_gc'] || !method_exists($cache, 'tidy'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($use_shutdown_function)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
register_shutdown_function(array(&$cache, 'tidy'));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cache->tidy();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'tidy_search':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Select the search method
|
|
|
4c79b5 |
$search_type = basename($config['search_type']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (time() - $config['search_gc'] <= $config['search_last_gc'] || !file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
include_once("{$phpbb_root_path}includes/search/$search_type.$phpEx");
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// We do some additional checks in the module to ensure it can actually be utilised
|
|
|
4c79b5 |
$error = false;
|
|
|
4c79b5 |
$search = new $search_type($error);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($error)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($use_shutdown_function)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
register_shutdown_function(array(&$search, 'tidy'));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$search->tidy();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'tidy_warnings':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (time() - $config['warnings_gc'] <= $config['warnings_last_gc'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($use_shutdown_function)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
register_shutdown_function('tidy_warnings');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
tidy_warnings();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'tidy_database':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (time() - $config['database_gc'] <= $config['database_last_gc'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($use_shutdown_function)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
register_shutdown_function('tidy_database');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
tidy_database();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'tidy_sessions':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (time() - $config['session_gc'] <= $config['session_last_gc'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($use_shutdown_function)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
register_shutdown_function(array(&$user, 'session_gc'));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$user->session_gc();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'prune_forum':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_id = request_var('f', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Do the forum Prune thang
|
|
|
4c79b5 |
if ($row['prune_next'] < time() && $row['enable_prune'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row['prune_days'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($use_shutdown_function)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
register_shutdown_function('auto_prune', $row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row['prune_viewed'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($use_shutdown_function)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
register_shutdown_function('auto_prune', $row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Unloading cache and closing db after having done the dirty work.
|
|
|
4c79b5 |
if ($use_shutdown_function)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
register_shutdown_function('unlock_cron');
|
|
|
4c79b5 |
register_shutdown_function('garbage_collection');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
unlock_cron();
|
|
|
4c79b5 |
garbage_collection();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Unlock cron script
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function unlock_cron()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
|
|
4c79b5 |
SET config_value = '0'
|
|
|
4c79b5 |
WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape(CRON_ID) . "'";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|