phpBB
Statistics
| Revision:

root / trunk / phpBB / cron.php

History | View | Annotate | Download (2.4 kB)

1 5476 naderman
<?php
2 8146 acydburn
/**
3 5136 acydburn
*
4 5136 acydburn
* @package phpBB3
5 8146 acydburn
* @copyright (c) 2005 phpBB Group
6 11653 git-gate
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7 5136 acydburn
*
8 5136 acydburn
*/
9 5136 acydburn
10 5136 acydburn
/**
11 5136 acydburn
*/
12 5136 acydburn
define('IN_PHPBB', true);
13 5136 acydburn
define('IN_CRON', true);
14 7954 acydburn
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
15 5136 acydburn
$phpEx = substr(strrchr(__FILE__, '.'), 1);
16 5929 acydburn
include($phpbb_root_path . 'common.' . $phpEx);
17 5136 acydburn
18 6048 acydburn
// Do not update users last page entry
19 6048 acydburn
$user->session_begin(false);
20 5957 acydburn
$auth->acl($user->data);
21 5957 acydburn
22 10965 git-gate
function output_image()
23 10965 git-gate
{
24 10965 git-gate
        // Output transparent gif
25 10965 git-gate
        header('Cache-Control: no-cache');
26 10965 git-gate
        header('Content-type: image/gif');
27 10965 git-gate
        header('Content-length: 43');
28 5136 acydburn
29 10965 git-gate
        echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
30 6317 acydburn
31 10965 git-gate
        // Flush here to prevent browser from showing the page as loading while
32 10965 git-gate
        // running cron.
33 10965 git-gate
        flush();
34 8022 acydburn
}
35 8022 acydburn
36 10965 git-gate
function do_cron($cron_lock, $run_tasks)
37 7947 naderman
{
38 10965 git-gate
        global $config;
39 7947 naderman
40 10965 git-gate
        foreach ($run_tasks as $task)
41 7947 naderman
        {
42 10965 git-gate
                if (defined('DEBUG_EXTRA') && $config['use_system_cron'])
43 10965 git-gate
                {
44 10965 git-gate
                        echo "[phpBB cron] Running task '{$task->get_name()}'\n";
45 10965 git-gate
                }
46 10965 git-gate
47 10965 git-gate
                $task->run();
48 7947 naderman
        }
49 10965 git-gate
50 10965 git-gate
        // Unloading cache and closing db after having done the dirty work.
51 10965 git-gate
        $cron_lock->release();
52 10965 git-gate
        garbage_collection();
53 7947 naderman
}
54 7947 naderman
55 10965 git-gate
// Thanks to various fatal errors and lack of try/finally, it is quite easy to leave
56 10965 git-gate
// the cron lock locked, especially when working on cron-related code.
57 10965 git-gate
//
58 10965 git-gate
// Attempt to alleviate the problem by doing setup outside of the lock as much as possible.
59 10965 git-gate
//
60 10965 git-gate
// If DEBUG_EXTRA is defined and cron lock cannot be obtained, a message will be printed.
61 7947 naderman
62 10965 git-gate
if ($config['use_system_cron'])
63 10965 git-gate
{
64 11557 git-gate
        $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver());
65 10965 git-gate
}
66 10965 git-gate
else
67 7947 naderman
{
68 10965 git-gate
        $cron_type = request_var('cron_type', '');
69 10965 git-gate
70 10965 git-gate
        // Comment this line out for debugging so the page does not return an image.
71 10965 git-gate
        output_image();
72 7947 naderman
}
73 7947 naderman
74 10965 git-gate
$cron_lock = new phpbb_lock_db('cron_lock', $config, $db);
75 10965 git-gate
if ($cron_lock->acquire())
76 5136 acydburn
{
77 10965 git-gate
        if ($config['use_system_cron'])
78 10965 git-gate
        {
79 10965 git-gate
                $run_tasks = $cron->find_all_ready_tasks();
80 10965 git-gate
        }
81 10965 git-gate
        else
82 10965 git-gate
        {
83 10965 git-gate
                // If invalid task is specified, empty $run_tasks is passed to do_cron which then does nothing
84 10965 git-gate
                $run_tasks = array();
85 10965 git-gate
                $task = $cron->find_task($cron_type);
86 10965 git-gate
                if ($task)
87 5929 acydburn
                {
88 10965 git-gate
                        if ($task->is_parametrized())
89 5272 acydburn
                        {
90 10965 git-gate
                                $task->parse_parameters($request);
91 5272 acydburn
                        }
92 10965 git-gate
                        if ($task->is_ready())
93 5272 acydburn
                        {
94 10965 git-gate
                                $run_tasks = array($task);
95 5272 acydburn
                        }
96 5272 acydburn
                }
97 10965 git-gate
        }
98 11050 git-gate
99 11050 git-gate
        do_cron($cron_lock, $run_tasks);
100 5136 acydburn
}
101 6055 acydburn
else
102 6055 acydburn
{
103 10965 git-gate
        if (defined('DEBUG_EXTRA'))
104 10965 git-gate
        {
105 10965 git-gate
                echo "Could not obtain cron lock.\n";
106 10965 git-gate
        }
107 6055 acydburn
}