diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2009-03-19 17:01:59 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2009-03-19 17:01:59 +0000 |
commit | e461162847b1ac9287870de680e8dbd17e9f2fc1 (patch) | |
tree | e93351f9856ea56167c7c40a5c765318184df5d9 /phpBB/includes/functions.php | |
parent | bcabff8a1fe82452366b6f278782fd284effece4 (diff) | |
download | forums-e461162847b1ac9287870de680e8dbd17e9f2fc1.tar forums-e461162847b1ac9287870de680e8dbd17e9f2fc1.tar.gz forums-e461162847b1ac9287870de680e8dbd17e9f2fc1.tar.bz2 forums-e461162847b1ac9287870de680e8dbd17e9f2fc1.tar.xz forums-e461162847b1ac9287870de680e8dbd17e9f2fc1.zip |
Fix race condition for updating post/topic/etc. counter. (reported by BartVB)
please do not try such fixes at home - the correct solution would be to create a second config table with integer columns. ;)
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9398 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r-- | phpBB/includes/functions.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 248a478145..30d3e50be8 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -165,6 +165,37 @@ function set_config($config_name, $config_value, $is_dynamic = false) } /** +* Set dynamic config value with arithmetic operation. +*/ +function set_config_count($config_name, $increment, $is_dynamic = false) +{ + global $db, $cache; + + switch ($db->sql_layer) + { + case 'firebird': + $sql_update = 'CAST(CAST(config_value as integer) + ' . (int) $increment . ' as CHAR)'; + break; + + case 'postgres': + $sql_update = 'int4(config_value) + ' . (int) $increment; + break; + + // MySQL, SQlite, mssql, mssql_odbc, oracle + default: + $sql_update = 'config_value + ' . (int) $increment; + break; + } + + $db->sql_query('UPDATE ' . CONFIG_TABLE . ' SET config_value = ' . $sql_update . " WHERE config_name = '" . $db->sql_escape($config_name) . "'"); + + if (!$is_dynamic) + { + $cache->destroy('config'); + } +} + +/** * Generates an alphanumeric random string of given length */ function gen_rand_string($num_chars = 8) |