diff --git a/phpBB/includes/config/config.php b/phpBB/includes/config/config.php index 64fef28cfa1..4ba05a98ece 100644 --- a/phpBB/includes/config/config.php +++ b/phpBB/includes/config/config.php @@ -103,6 +103,19 @@ public function count() return count($this->config); } + /** + * Removes a configuration option + * + * @param String $key The configuration option's name + * @param bool $cache Whether this variable should be cached or if it + * changes too frequently to be efficiently cached + * @return void + */ + public function delete($key, $cache = true) + { + unset($this->config[$key]); + } + /** * Sets a configuration option's value * diff --git a/phpBB/includes/config/db.php b/phpBB/includes/config/db.php index 74fb0504ce6..f98056e013d 100644 --- a/phpBB/includes/config/db.php +++ b/phpBB/includes/config/db.php @@ -90,6 +90,28 @@ public function __construct(dbal $db, phpbb_cache_driver_interface $cache, $tabl parent::__construct($config); } + /** + * Removes a configuration option + * + * @param String $key The configuration option's name + * @param bool $cache Whether this variable should be cached or if it + * changes too frequently to be efficiently cached + * @return void + */ + public function delete($key, $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 ($cache) + { + $this->cache->destroy('config'); + } + } + /** * Sets a configuration option's value * diff --git a/tests/config/config_test.php b/tests/config/config_test.php index 73a365c8476..9c91d9eb874 100644 --- a/tests/config/config_test.php +++ b/tests/config/config_test.php @@ -109,4 +109,12 @@ public function test_increment() $config->increment('foo', 1); $this->assertEquals(27, $config['foo']); } + + public function test_delete() + { + $config = new phpbb_config(array('foo' => 'bar')); + + $config->delete('foo'); + $this->assertFalse(isset($config['foo'])); + } } diff --git a/tests/config/db_test.php b/tests/config/db_test.php index e0d5252f191..5bd5296e5a2 100644 --- a/tests/config/db_test.php +++ b/tests/config/db_test.php @@ -125,4 +125,18 @@ public function test_increment_new() $this->config->increment('foobar', 3); $this->assertEquals(3, $this->config['foobar']);; } + + public function test_delete() + { + $this->assertTrue(isset($this->config['foo'])); + $this->config->delete('foo'); + $this->cache->checkVarUnset($this, 'foo'); + $this->assertFalse(isset($this->config['foo'])); + + // re-read config and populate cache + $cache2 = new phpbb_mock_cache; + $config2 = new phpbb_config_db($this->db, $cache2, 'phpbb_config'); + $cache2->checkVarUnset($this, 'foo'); + $this->assertFalse(isset($config2['foo'])); + } }