Blame Identity/Models/Html/phpBB/3.0.4/cron.php

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