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