From 14b6714c93944b6af9ec01d978cfe7f387dc7e9a Mon Sep 17 00:00:00 2001 From: Graham Eames Date: Sat, 4 Mar 2006 17:34:04 +0000 Subject: Expire issued warnings after and admin configurable time TODO: Add config option for this value to the ACP git-svn-id: file:///svn/phpbb/trunk@5602 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_admin.php | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'phpBB/includes/functions_admin.php') 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 @@ -2176,6 +2176,53 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port return $file_info; } +/** +* 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 -- cgit v1.2.1