Skip to content

Commit

Permalink
Merge branch 'ticket/erikfrerejean/10006' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Apr 19, 2011
2 parents dcfab4e + 27bbfde commit 8fe75ae
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
13 changes: 13 additions & 0 deletions phpBB/includes/config/config.php
Expand Up @@ -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
*
Expand Down
22 changes: 22 additions & 0 deletions phpBB/includes/config/db.php
Expand Up @@ -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
*
Expand Down
8 changes: 8 additions & 0 deletions tests/config/config_test.php
Expand Up @@ -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']));
}
}
14 changes: 14 additions & 0 deletions tests/config/db_test.php
Expand Up @@ -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']));
}
}

0 comments on commit 8fe75ae

Please sign in to comment.