diff options
-rw-r--r-- | phpBB/cron.php | 13 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 4 | ||||
-rw-r--r-- | phpBB/includes/functions_admin.php | 47 | ||||
-rw-r--r-- | phpBB/install/schemas/schema_data.sql | 2 |
4 files changed, 66 insertions, 0 deletions
diff --git a/phpBB/cron.php b/phpBB/cron.php index 848c263009..15564e1f5c 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -81,6 +81,19 @@ switch ($cron_type) } set_config('search_last_gc', time()); + case 'tidy_warnings': + include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx); + + if ($use_shutdown_function) + { + register_shutdown_function('tidy_warnings'); + } + else + { + tidy_warnings(); + } + break; + case 'tidy_database': include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4a5838effe..1949b5f6c4 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2171,6 +2171,10 @@ function page_footer() // Tidy the cache $cron_type = 'tidy_cache'; } + else if (time() - $config['warnings_last_gc'] > $config['warnings_gc']) + { + $cron_type = 'tidy_warnings'; + } else if (time() - (7 * 24 * 3600) > $config['database_last_gc']) { // Tidy some table rows every week diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 4ce8e4ddfa..ba830857ea 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2177,6 +2177,53 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port } /** +* Tidy Warnings +* Remove all warnings which have now expired from the database +* The duration of a warning can be defined by the administrator +* This only removes the warning and reduces the assosciated count, +* it does not remove the user note recording the contents of the warning +*/ +function tidy_warnings() +{ + global $db, $config; + + $expire_date = time() - ($config['warnings_expire_days'] * 86400); + $warning_list = $user_list = array(); + + $sql = 'SELECT * FROM ' . WARNINGS_TABLE . " + WHERE warning_time < $expire_date"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $warning_list[] = $row['warning_id']; + $user_list[$row['user_id']] = isset($user_list[$row['user_id']]) ? $user_list[$row['user_id']]++ : 0; + } + $db->sql_freeresult($result); + + if (sizeof($warning_list)) + { + $db->sql_transaction('begin'); + + $sql_where = ' IN (' . implode(', ', $warning_list) . ')'; + $sql = 'DELETE FROM ' . WARNINGS_TABLE . " + WHERE warning_id $sql_where"; + $db->sql_query($sql); + + foreach($user_list as $user_id => $value) + { + $sql = 'UPDATE ' . USERS_TABLE . " SET user_warnings = user_warnings - $value + WHERE user_id = $user_id"; + $db->sql_query($sql); + } + + $db->sql_transaction('commit'); + } + + set_config('warnings_last_gc', time()); +} + +/** * Tidy database * Removes all tracking rows older than 6 months, including mark_posted informations */ diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index a416e66e09..591a254f78 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -193,6 +193,8 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('topics_per_page', INSERT INTO phpbb_config (config_name, config_value) VALUES ('upload_icons_path', 'images/upload_icons'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('upload_path', 'files'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('version', '2.1.2'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('warnings_expire_days', '90'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('warnings_gc', '14400'); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('database_last_gc', '0', 1); |