1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-22 16:51:56 +02:00

[ticket/10006] Add phpbb_config::delete

Add the missing `phpbb_config::delete` method to the config class

PHPBB3-10006
This commit is contained in:
Erik Frèrejean 2011-01-24 15:13:15 +01:00
parent 6dd0e40d02
commit 2f67ade05a
4 changed files with 68 additions and 0 deletions
phpBB/includes/config
tests/config

@ -103,6 +103,26 @@ class phpbb_config implements ArrayAccess, IteratorAggregate, Countable
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 bool True if the configuration entry was deleted successfully,
* otherwise false
*/
public function delete($key, $cache = true)
{
if (!isset($this->config[$key]))
{
return false;
}
unset($this->config[$key]);
return true;
}
/**
* Sets a configuration option's value
*

@ -90,6 +90,38 @@ class phpbb_config_db extends phpbb_config
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 bool True if the configuration entry was deleted successfully,
* otherwise false
*/
public function delete($key, $cache = true)
{
if (!isset($this->config[$key]))
{
return false;
}
$sql = 'DELETE FROM ' . $this->table . "
WHERE config_name = '" . $this->db->sql_escape($key) . "'";
$this->db->sql_query($sql);
if (!$this->db->sql_affectedrows())
{
return false;
}
unset($this->config[$key]);
if ($cache)
{
$this->cache->destroy('config');
}
}
/**
* Sets a configuration option's value
*

@ -109,4 +109,13 @@ class phpbb_config_test extends phpbb_test_case
$config->increment('foo', 1);
$this->assertEquals(27, $config['foo']);
}
public function test_delete()
{
$config = new phpbb_config(array('foo' => 'bar'));
$this->assertTrue(isset($config['foo']));
$config->delete('foo');
$this->assertFalse(isset($config['foo']));
}
}

@ -125,4 +125,11 @@ class phpbb_config_db_test extends phpbb_database_test_case
$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', false);
$this->assertFalse(isset($this->config['foo']));
}
}