~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/php/phpBB3/cron.php

  • Committer: Matt Giuca
  • Date: 2010-07-22 00:46:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1818.
  • Revision ID: matt.giuca@gmail.com-20100722004645-giso3xsjm8o8rflf
Project page: Removed the space before the '*'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
*
4
 
* @package phpBB3
5
 
* @version $Id: cron.php,v 1.21 2007/10/05 14:30:06 acydburn Exp $
6
 
* @copyright (c) 2005 phpBB Group
7
 
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8
 
*
9
 
*/
10
 
 
11
 
/**
12
 
*/
13
 
define('IN_PHPBB', true);
14
 
define('IN_CRON', true);
15
 
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16
 
$phpEx = substr(strrchr(__FILE__, '.'), 1);
17
 
include($phpbb_root_path . 'common.' . $phpEx);
18
 
 
19
 
// Do not update users last page entry
20
 
$user->session_begin(false);
21
 
$auth->acl($user->data);
22
 
 
23
 
$cron_type = request_var('cron_type', '');
24
 
$use_shutdown_function = (@function_exists('register_shutdown_function')) ? true : false;
25
 
 
26
 
// Output transparent gif
27
 
header('Cache-Control: no-cache');
28
 
header('Content-type: image/gif');
29
 
header('Content-length: 43');
30
 
 
31
 
echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
32
 
 
33
 
// test without flush ;)
34
 
// flush();
35
 
 
36
 
//
37
 
if (!isset($config['cron_lock']))
38
 
{
39
 
        set_config('cron_lock', '0', true);
40
 
}
41
 
 
42
 
// make sure cron doesn't run multiple times in parallel
43
 
if ($config['cron_lock'])
44
 
{
45
 
        // if the other process is running more than an hour already we have to assume it
46
 
        // aborted without cleaning the lock
47
 
        $time = explode(' ', $config['cron_lock']);
48
 
        $time = $time[0];
49
 
 
50
 
        if ($time + 3600 >= time())
51
 
        {
52
 
                exit;
53
 
        }
54
 
}
55
 
 
56
 
define('CRON_ID', time() . ' ' . unique_id());
57
 
 
58
 
$sql = 'UPDATE ' . CONFIG_TABLE . "
59
 
        SET config_value = '" . $db->sql_escape(CRON_ID) . "'
60
 
        WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape($config['cron_lock']) . "'";
61
 
$db->sql_query($sql);
62
 
 
63
 
// another cron process altered the table between script start and UPDATE query so exit
64
 
if ($db->sql_affectedrows() != 1)
65
 
{
66
 
        exit;
67
 
}
68
 
 
69
 
/**
70
 
* Run cron-like action
71
 
* Real cron-based layer will be introduced in 3.2
72
 
*/
73
 
switch ($cron_type)
74
 
{
75
 
        case 'queue':
76
 
 
77
 
                if (time() - $config['queue_interval'] <= $config['last_queue_run'] || !file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
78
 
                {
79
 
                        break;
80
 
                }
81
 
 
82
 
                // A user reported using the mail() function while using shutdown does not work. We do not want to risk that.
83
 
                if ($use_shutdown_function && !$config['smtp_delivery'])
84
 
                {
85
 
                        $use_shutdown_function = false;
86
 
                }
87
 
 
88
 
                include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
89
 
                $queue = new queue();
90
 
 
91
 
                if ($use_shutdown_function)
92
 
                {
93
 
                        register_shutdown_function(array(&$queue, 'process'));
94
 
                }
95
 
                else
96
 
                {
97
 
                        $queue->process();
98
 
                }
99
 
 
100
 
        break;
101
 
 
102
 
        case 'tidy_cache':
103
 
 
104
 
                if (time() - $config['cache_gc'] <= $config['cache_last_gc'] || !method_exists($cache, 'tidy'))
105
 
                {
106
 
                        break;
107
 
                }
108
 
 
109
 
                if ($use_shutdown_function)
110
 
                {
111
 
                        register_shutdown_function(array(&$cache, 'tidy'));
112
 
                }
113
 
                else
114
 
                {
115
 
                        $cache->tidy();
116
 
                }
117
 
 
118
 
        break;
119
 
 
120
 
        case 'tidy_search':
121
 
                
122
 
                // Select the search method
123
 
                $search_type = basename($config['search_type']);
124
 
 
125
 
                if (time() - $config['search_gc'] <= $config['search_last_gc'] || !file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
126
 
                {
127
 
                        break;
128
 
                }
129
 
 
130
 
                include_once("{$phpbb_root_path}includes/search/$search_type.$phpEx");
131
 
 
132
 
                // We do some additional checks in the module to ensure it can actually be utilised
133
 
                $error = false;
134
 
                $search = new $search_type($error);
135
 
 
136
 
                if ($error)
137
 
                {
138
 
                        break;
139
 
                }
140
 
 
141
 
                if ($use_shutdown_function)
142
 
                {
143
 
                        register_shutdown_function(array(&$search, 'tidy'));
144
 
                }
145
 
                else
146
 
                {
147
 
                        $search->tidy();
148
 
                }
149
 
 
150
 
        break;
151
 
 
152
 
        case 'tidy_warnings':
153
 
 
154
 
                if (time() - $config['warnings_gc'] <= $config['warnings_last_gc'])
155
 
                {
156
 
                        break;
157
 
                }
158
 
 
159
 
                include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
160
 
 
161
 
                if ($use_shutdown_function)
162
 
                {
163
 
                        register_shutdown_function('tidy_warnings');
164
 
                }
165
 
                else
166
 
                {
167
 
                        tidy_warnings();
168
 
                }
169
 
 
170
 
        break;
171
 
 
172
 
        case 'tidy_database':
173
 
 
174
 
                if (time() - $config['database_gc'] <= $config['database_last_gc'])
175
 
                {
176
 
                        break;
177
 
                }
178
 
 
179
 
                include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
180
 
 
181
 
                if ($use_shutdown_function)
182
 
                {
183
 
                        register_shutdown_function('tidy_database');
184
 
                }
185
 
                else
186
 
                {
187
 
                        tidy_database();
188
 
                }
189
 
 
190
 
        break;
191
 
 
192
 
        case 'tidy_sessions':
193
 
 
194
 
                if (time() - $config['session_gc'] <= $config['session_last_gc'])
195
 
                {
196
 
                        break;
197
 
                }
198
 
 
199
 
                if ($use_shutdown_function)
200
 
                {
201
 
                        register_shutdown_function(array(&$user, 'session_gc'));
202
 
                }
203
 
                else
204
 
                {
205
 
                        $user->session_gc();
206
 
                }
207
 
 
208
 
        break;
209
 
 
210
 
        case 'prune_forum':
211
 
 
212
 
                $forum_id = request_var('f', 0);
213
 
 
214
 
                $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
215
 
                        FROM ' . FORUMS_TABLE . "
216
 
                        WHERE forum_id = $forum_id";
217
 
                $result = $db->sql_query($sql);
218
 
                $row = $db->sql_fetchrow($result);
219
 
                $db->sql_freeresult($result);
220
 
 
221
 
                if (!$row)
222
 
                {
223
 
                        break;
224
 
                }
225
 
 
226
 
                // Do the forum Prune thang
227
 
                if ($row['prune_next'] < time() && $row['enable_prune'])
228
 
                {
229
 
                        include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
230
 
 
231
 
                        if ($row['prune_days'])
232
 
                        {
233
 
                                if ($use_shutdown_function)
234
 
                                {
235
 
                                        register_shutdown_function('auto_prune', $row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
236
 
                                }
237
 
                                else
238
 
                                {
239
 
                                        auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
240
 
                                }
241
 
                        }
242
 
 
243
 
                        if ($row['prune_viewed'])
244
 
                        {
245
 
                                if ($use_shutdown_function)
246
 
                                {
247
 
                                        register_shutdown_function('auto_prune', $row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
248
 
                                }
249
 
                                else
250
 
                                {
251
 
                                        auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
252
 
                                }
253
 
                        }
254
 
                }
255
 
 
256
 
        break;
257
 
}
258
 
 
259
 
// Unloading cache and closing db after having done the dirty work.
260
 
if ($use_shutdown_function)
261
 
{
262
 
        register_shutdown_function('unlock_cron');
263
 
        register_shutdown_function('garbage_collection');
264
 
}
265
 
else
266
 
{
267
 
        unlock_cron();
268
 
        garbage_collection();
269
 
}
270
 
 
271
 
exit;
272
 
 
273
 
 
274
 
/**
275
 
* Unlock cron script
276
 
*/
277
 
function unlock_cron()
278
 
{
279
 
        global $db;
280
 
 
281
 
        $sql = 'UPDATE ' . CONFIG_TABLE . "
282
 
                SET config_value = '0'
283
 
                WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape(CRON_ID) . "'";
284
 
        $db->sql_query($sql);
285
 
}
286
 
 
287
 
?>
 
 
b'\\ No newline at end of file'