diff options
author | Oleg Pudeyev <oleg@bsdpower.com> | 2012-11-02 16:05:53 -0400 |
---|---|---|
committer | Oleg Pudeyev <oleg@bsdpower.com> | 2012-11-02 16:05:53 -0400 |
commit | fd6ee50e06cb48c9e3a476bf23285875484ff5f7 (patch) | |
tree | 9a3af2e3d58546c0cc3f6040c4086766e5198c99 /phpBB | |
parent | 88b100d818940340e660c9f372526b1b5466bf3a (diff) | |
download | forums-fd6ee50e06cb48c9e3a476bf23285875484ff5f7.tar forums-fd6ee50e06cb48c9e3a476bf23285875484ff5f7.tar.gz forums-fd6ee50e06cb48c9e3a476bf23285875484ff5f7.tar.bz2 forums-fd6ee50e06cb48c9e3a476bf23285875484ff5f7.tar.xz forums-fd6ee50e06cb48c9e3a476bf23285875484ff5f7.zip |
[ticket/11162] Extract existing behavior into a function and add a test.
PHPBB3-11162
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/functions.php | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 65d8be32ad..8608c6ca4f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1297,6 +1297,28 @@ function tz_select($default = '', $truncate = false) return $tz_select; } +/** +* Updates rows in given table from a set of values to a new value. +* If this results in rows violating uniqueness constraints, the duplicate +* rows are eliminated. +* +* @param dbal $db Database object +* @param string $table Table on which to perform the update +* @param string $column Column whose values to change +* @param array $from_values An array of values that should be changed +* @param int $to_value The new value +* @return null +*/ +function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_values, $to_value) +{ + $db->sql_return_on_error(true); + $condition = $db->sql_in_set($column, $from_values); + $db->sql_query('UPDATE ' . $table . ' SET ' . $column . ' = ' . (int) $to_value. ' WHERE ' . $condition); + $db->sql_return_on_error(false); + + $db->sql_query('DELETE FROM ' . $table . ' WHERE ' . $condition); +} + // Functions handling topic/post tracking/marking /** @@ -3355,7 +3377,7 @@ function parse_cfg_file($filename, $lines = false) $parsed_items[$key] = $value; } - + if (isset($parsed_items['inherit_from']) && isset($parsed_items['name']) && $parsed_items['inherit_from'] == $parsed_items['name']) { unset($parsed_items['inherit_from']); |