summaryrefslogtreecommitdiffstats
path: root/server_wizard
diff options
context:
space:
mode:
Diffstat (limited to 'server_wizard')
0 files changed, 0 insertions, 0 deletions
d='n89' href='#n89'>89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

namespace phpbb\config;

/**
* Configuration container class
*/
class db extends \phpbb\config\config
{
	/**
	* Cache instance
	* @var \phpbb\cache\driver\driver_interface
	*/
	protected $cache;

	/**
	* Database connection
	* @var \phpbb\db\driver\driver_interface
	*/
	protected $db;

	/**
	* Name of the database table used for configuration.
	* @var string
	*/
	protected $table;

	/**
	* Creates a configuration container with a default set of values
	*
	* @param \phpbb\db\driver\driver_interface    $db    Database connection
	* @param \phpbb\cache\driver\driver_interface $cache Cache instance
	* @param string                       $table Configuration table name
	*/
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, $table)
	{
		$this->db = $db;
		$this->cache = $cache;
		$this->table = $table;

		if (($config = $cache->get('config')) !== false)
		{
			$sql = 'SELECT config_name, config_value
				FROM ' . $this->table . '
				WHERE is_dynamic = 1';
			$result = $this->db->sql_query($sql);

			while ($row = $this->db->sql_fetchrow($result))
			{
				$config[$row['config_name']] = $row['config_value'];
			}
			$this->db->sql_freeresult($result);
		}
		else
		{
			$config = $cached_config = array();

			$sql = 'SELECT config_name, config_value, is_dynamic
				FROM ' . $this->table;
			$result = $this->db->sql_query($sql);

			while ($row = $this->db->sql_fetchrow($result))
			{
				if (!$row['is_dynamic'])
				{
					$cached_config[$row['config_name']] = $row['config_value'];
				}

				$config[$row['config_name']] = $row['config_value'];
			}
			$this->db->sql_freeresult($result);

			$cache->put('config', $cached_config);
		}

		parent::__construct($config);
	}

	/**
	* Removes a configuration option
	*
	* @param  String $key       The configuration option's name
	* @param  bool   $use_cache Whether this variable should be cached or if it
	*                           changes too frequently to be efficiently cached
	* @return null
	*/
	public function delete($key, $use_cache = true)
	{
		$sql = 'DELETE FROM ' . $this->table . "
			WHERE config_name = '" . $this->db->sql_escape($key) . "'";
		$this->db->sql_query($sql);

		unset($this->config[$key]);

		if ($use_cache)
		{
			$this->cache->destroy('config');
		}
	}

	/**
	* Sets a configuration option's value
	*
	* @param string $key       The configuration option's name
	* @param string $value     New configuration value
	* @param bool   $use_cache Whether this variable should be cached or if it
	*                          changes too frequently to be efficiently cached.
	*/
	public function set($key, $value, $use_cache = true)
	{
		$this->set_atomic($key, false, $value, $use_cache);
	}

	/**
	* Sets a configuration option's value only if the old_value matches the
	* current configuration value or the configuration value does not exist yet.
	*