aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/config/config.php20
-rw-r--r--phpBB/includes/config/db.php32
-rw-r--r--tests/config/config_test.php9
-rw-r--r--tests/config/db_test.php7
4 files changed, 68 insertions, 0 deletions
diff --git a/phpBB/includes/config/config.php b/phpBB/includes/config/config.php
index 64fef28cfa..9596b1e15b 100644
--- a/phpBB/includes/config/config.php
+++ b/phpBB/includes/config/config.php
@@ -104,6 +104,26 @@ class phpbb_config implements ArrayAccess, IteratorAggregate, Countable
}
/**
+ * 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
*
* @param string $key The configuration option's name
diff --git a/phpBB/includes/config/db.php b/phpBB/includes/config/db.php
index 74fb0504ce..f0c9a5d591 100644
--- a/phpBB/includes/config/db.php
+++ b/phpBB/includes/config/db.php
@@ -91,6 +91,38 @@ class phpbb_config_db extends phpbb_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
*
* @param string $key The configuration option's name
diff --git a/tests/config/config_test.php b/tests/config/config_test.php
index 73a365c847..e4444eccda 100644
--- a/tests/config/config_test.php
+++ b/tests/config/config_test.php
@@ -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']));
+ }
}
diff --git a/tests/config/db_test.php b/tests/config/db_test.php
index e0d5252f19..d37b31dbbd 100644
--- a/tests/config/db_test.php
+++ b/tests/config/db_test.php
@@ -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']));
+ }
}