2009-10-04 18:14:59 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package phpBB3
|
|
|
|
* @copyright (c) 2005 phpBB Group
|
2011-12-31 13:32:52 +00:00
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
2009-10-04 18:14:59 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
define('IN_PHPBB', true);
|
|
|
|
define('IN_CRON', true);
|
|
|
|
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
|
|
|
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
|
|
|
include($phpbb_root_path . 'common.' . $phpEx);
|
|
|
|
|
|
|
|
// Do not update users last page entry
|
|
|
|
$user->session_begin(false);
|
|
|
|
$auth->acl($user->data);
|
|
|
|
|
2010-04-15 10:11:40 -04:00
|
|
|
function output_image()
|
|
|
|
{
|
2010-04-14 16:14:32 -04:00
|
|
|
// Output transparent gif
|
|
|
|
header('Cache-Control: no-cache');
|
|
|
|
header('Content-type: image/gif');
|
|
|
|
header('Content-length: 43');
|
2009-10-04 18:14:59 +00:00
|
|
|
|
2010-04-14 16:14:32 -04:00
|
|
|
echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
|
2009-10-04 18:14:59 +00:00
|
|
|
|
2011-01-13 03:01:39 +01:00
|
|
|
// Flush here to prevent browser from showing the page as loading while
|
|
|
|
// running cron.
|
2011-01-12 23:02:00 +01:00
|
|
|
flush();
|
2009-10-04 18:14:59 +00:00
|
|
|
}
|
|
|
|
|
2011-01-07 20:58:28 +01:00
|
|
|
function do_cron($cron_lock, $run_tasks)
|
2010-04-15 10:11:40 -04:00
|
|
|
{
|
2011-01-07 20:58:28 +01:00
|
|
|
global $config;
|
2010-04-15 10:11:40 -04:00
|
|
|
|
2010-04-17 06:32:15 -04:00
|
|
|
foreach ($run_tasks as $task)
|
2010-04-15 10:11:40 -04:00
|
|
|
{
|
2010-08-19 16:32:21 -04:00
|
|
|
if (defined('DEBUG_EXTRA') && $config['use_system_cron'])
|
|
|
|
{
|
|
|
|
echo "[phpBB cron] Running task '{$task->get_name()}'\n";
|
|
|
|
}
|
|
|
|
|
2010-04-17 06:32:15 -04:00
|
|
|
$task->run();
|
2009-10-04 18:14:59 +00:00
|
|
|
}
|
2010-04-15 10:11:40 -04:00
|
|
|
|
2010-04-14 16:14:32 -04:00
|
|
|
// Unloading cache and closing db after having done the dirty work.
|
2011-01-13 02:03:16 +01:00
|
|
|
$cron_lock->release();
|
2010-04-14 16:14:32 -04:00
|
|
|
garbage_collection();
|
2009-10-04 18:14:59 +00:00
|
|
|
}
|
|
|
|
|
2010-05-09 14:58:45 -04:00
|
|
|
// Thanks to various fatal errors and lack of try/finally, it is quite easy to leave
|
|
|
|
// the cron lock locked, especially when working on cron-related code.
|
|
|
|
//
|
|
|
|
// Attempt to alleviate the problem by doing setup outside of the lock as much as possible.
|
|
|
|
//
|
|
|
|
// If DEBUG_EXTRA is defined and cron lock cannot be obtained, a message will be printed.
|
|
|
|
|
|
|
|
if ($config['use_system_cron'])
|
|
|
|
{
|
2011-08-31 17:49:48 -04:00
|
|
|
$cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver());
|
2010-05-09 14:58:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cron_type = request_var('cron_type', '');
|
|
|
|
|
2011-01-13 03:01:39 +01:00
|
|
|
// Comment this line out for debugging so the page does not return an image.
|
2010-05-09 14:58:45 -04:00
|
|
|
output_image();
|
|
|
|
}
|
|
|
|
|
2011-01-07 20:58:28 +01:00
|
|
|
$cron_lock = new phpbb_lock_db('cron_lock', $config, $db);
|
2011-01-13 02:03:16 +01:00
|
|
|
if ($cron_lock->acquire())
|
2010-04-15 10:11:40 -04:00
|
|
|
{
|
|
|
|
if ($config['use_system_cron'])
|
|
|
|
{
|
2010-04-17 06:32:15 -04:00
|
|
|
$run_tasks = $cron->find_all_ready_tasks();
|
2010-04-15 10:11:40 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-18 13:48:32 -04:00
|
|
|
// If invalid task is specified, empty $run_tasks is passed to do_cron which then does nothing
|
|
|
|
$run_tasks = array();
|
2010-04-17 06:32:15 -04:00
|
|
|
$task = $cron->find_task($cron_type);
|
2010-04-18 13:48:32 -04:00
|
|
|
if ($task)
|
|
|
|
{
|
|
|
|
if ($task->is_parametrized())
|
|
|
|
{
|
2010-10-29 13:29:00 +02:00
|
|
|
$task->parse_parameters($request);
|
2010-04-17 06:32:15 -04:00
|
|
|
}
|
2010-04-18 13:48:32 -04:00
|
|
|
if ($task->is_ready())
|
|
|
|
{
|
2010-04-17 06:32:15 -04:00
|
|
|
$run_tasks = array($task);
|
2009-10-04 18:14:59 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-14 16:14:32 -04:00
|
|
|
}
|
2011-03-12 15:07:31 +01:00
|
|
|
|
|
|
|
do_cron($cron_lock, $run_tasks);
|
2009-10-04 18:14:59 +00:00
|
|
|
}
|
2010-05-09 14:58:45 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (defined('DEBUG_EXTRA'))
|
|
|
|
{
|
2010-08-19 16:32:21 -04:00
|
|
|
echo "Could not obtain cron lock.\n";
|
2010-05-09 14:58:45 -04:00
|
|
|
}
|
|
|
|
}
|