Permalink
Browse files

Merge branch 'ticket/erikfrerejean/10006' into develop

  • Loading branch information...
2 parents dcfab4e + 27bbfde commit 8fe75aefbbb0304f1335441465e566b572168365 @p p committed Apr 19, 2011
Showing with 57 additions and 0 deletions.
  1. +13 −0 phpBB/includes/config/config.php
  2. +22 −0 phpBB/includes/config/db.php
  3. +8 −0 tests/config/config_test.php
  4. +14 −0 tests/config/db_test.php
@@ -104,6 +104,19 @@ public function count()
}
/**
+ * 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
*
* @param string $key The configuration option's name
@@ -91,6 +91,28 @@ public function __construct(dbal $db, phpbb_cache_driver_interface $cache, $tabl
}
/**
+ * 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
*
* @param string $key The configuration option's name
@@ -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']));
+ }
}
View
@@ -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.