Ejemplo n.º 1
0
    /**
     * Increments an integer config value directly in the database.
     *
     * Using this method instead of setting the new value directly avoids race
     * conditions and unlike set_atomic it cannot fail.
     *
     * @param string $key       The configuration option's name
     * @param int    $increment Amount to increment by
     * @param bool   $use_cache Whether this variable should be cached or if it
     *                          changes too frequently to be efficiently cached.
     */
    function increment($key, $increment, $use_cache = true)
    {
        if (!isset($this->config[$key])) {
            $this->set($key, '0', $use_cache);
        }
        $sql_update = $this->db->cast_expr_to_string($this->db->cast_expr_to_bigint('config_value') . ' + ' . (int) $increment);
        $this->db->sql_query('UPDATE ' . $this->table . '
			SET config_value = ' . $sql_update . "\n\t\t\tWHERE config_name = '" . $this->db->sql_escape($key) . "'");
        if ($use_cache) {
            $this->cache->destroy('config');
        }
        $this->config[$key] += $increment;
    }