| 1 |
<?php</span> |
|---|
| 2 |
<span class="code-lang">define('IN_CLEANUP', true); |
|---|
| 3 |
|
|---|
| 4 |
class cleanup { |
|---|
| 5 |
|
|---|
| 6 |
function cleanup () { |
|---|
| 7 |
$this->initialize_cleanup(); |
|---|
| 8 |
} |
|---|
| 9 |
|
|---|
| 10 |
function initialize_cleanup () { |
|---|
| 11 |
global $config, $db; |
|---|
| 12 |
|
|---|
| 13 |
$db->sql_return_on_error(true); |
|---|
| 14 |
|
|---|
| 15 |
if ( !isset($config['cleanup_lock']) ) { |
|---|
| 16 |
set_config('cleanup_lock', '0', true); |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
if ( $config['cleanup_lock'] ) { |
|---|
| 21 |
|
|---|
| 22 |
// aborted without cleaning the lock |
|---|
| 23 |
$time = explode(' ', $config['cleanup_lock']); |
|---|
| 24 |
$time = $time[0]; |
|---|
| 25 |
|
|---|
| 26 |
if ( $time + 1800 >= time() ) { |
|---|
| 27 |
return; |
|---|
| 28 |
} |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
define('CLEANUP_ID', time() . ' ' . uniqid(rand(), true)); |
|---|
| 32 |
|
|---|
| 33 |
$sql = 'UPDATE ' . CONFIG_TABLE . " SET value = '" . $db->sql_escape(CLEANUP_ID) . "' WHERE name = 'cleanup_lock' AND value = '" . $db->sql_escape($config['cleanup_lock']) . "'"; |
|---|
| 34 |
if ( !($db->sql_query($sql)) ) { |
|---|
| 35 |
$this->write_errors ($sql, __LINE__, __FILE__); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
if ( $db->sql_affectedrows() != 1 ) { |
|---|
| 40 |
return; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
$db->sql_return_on_error(true); |
|---|
| 44 |
|
|---|
| 45 |
ignore_user_abort(1); |
|---|
| 46 |
if ( !ini_get('safe_mode') ) { |
|---|
| 47 |
@set_time_limit(0); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
$this->_run_cleanup(); |
|---|
| 51 |
|
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
function _run_cleanup () { |
|---|
| 55 |
global $root_path, $config; |
|---|
| 56 |
|
|---|
| 57 |
require_once ($root_path . 'include/class.cleanup_types.php'); |
|---|
| 58 |
|
|---|
| 59 |
$cleanup_types = new cleanup_types(); |
|---|
| 60 |
$class_methods = get_class_methods(get_class($cleanup_types)); |
|---|
| 61 |
|
|---|
| 62 |
foreach ( $class_methods AS $class_name ) { |
|---|
| 63 |
if ( isset($config['autoclean_interval' . $class_name]) && $config['autoclean_interval' . $class_name] && ( $config['autoclean_last_run' . $class_name] + $config['autoclean_interval' . $class_name] * 60 ) < time() ) { |
|---|
| 64 |
if ( DEFINED('DEBUG_EXTRA') ) { |
|---|
| 65 |
write_log('Cleanup operation ' . $class_name . ' started', LOG_VIEW_SYSOP); |
|---|
| 66 |
} |
|---|
| 67 |
if ( !( $return = $cleanup_types->$class_name() ) ) { |
|---|
| 68 |
write_log('Cleanup error. Operation ' . $class_name . ' dont exit propertly', LOG_VIEW_SYSOP); |
|---|
| 69 |
} |
|---|
| 70 |
if ( DEFINED('DEBUG_EXTRA') ) { |
|---|
| 71 |
write_log('Cleanup operation ' . $class_name . ' ended', LOG_VIEW_SYSOP); |
|---|
| 72 |
} |
|---|
| 73 |
set_config('autoclean_last_run' . $class_name, time(), true); |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
$this->_cleanup_end(); |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
function _cleanup_end () { |
|---|
| 81 |
global $db, $cleanup_types; |
|---|
| 82 |
|
|---|
| 83 |
$sql = 'UPDATE ' . CONFIG_TABLE . " SET value = '0' WHERE name = 'cleanup_lock' AND value = '" . $db->sql_escape(CLEANUP_ID) . "'"; |
|---|
| 84 |
$db->sql_query($sql); |
|---|
| 85 |
|
|---|
| 86 |
return; |
|---|
| 87 |
} |
|---|
| 88 |
} |
|---|
| 89 |
?> |
|---|