Blame Identity/Webenv/App/phpBB/3.0.4/cron.php

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