Skip to content

Commit f3b9b4c

Browse files
author
igor-chepurnoi
committed
added removeAll method to Setting component
1 parent 7ffce37 commit f3b9b4c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

components/Settings.php

+10
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ public function remove($section, $key)
140140
return null;
141141
}
142142

143+
/**
144+
* Remove all settings
145+
*
146+
* @return int
147+
*/
148+
public function removeAll()
149+
{
150+
return $this->model->removeAllSettings();
151+
}
152+
143153
/**
144154
* Activates a setting
145155
*

models/SettingModel.php

+10
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ public function removeSetting($section, $key)
190190
return false;
191191
}
192192

193+
/**
194+
* Remove all settings
195+
*
196+
* @return int
197+
*/
198+
public function removeAllSettings()
199+
{
200+
return static::deleteAll();
201+
}
202+
193203
/**
194204
* Activates a setting
195205
*

tests/SettingsTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public function testRemoveSetting()
3030
$this->assertNull(Yii::$app->settings->get('admin', 'email'), 'Unable to remove the setting!');
3131
}
3232

33+
public function testRemoveAllSettings()
34+
{
35+
Yii::$app->settings->set('admin', 'email', 'admin@mail.com');
36+
Yii::$app->settings->set('admin', 'password', '123123');
37+
38+
$this->assertEquals(2, Yii::$app->settings->removeAll());
39+
$this->assertFalse(Yii::$app->settings->has('admin', 'email'));
40+
$this->assertFalse(Yii::$app->settings->has('admin', 'password'));
41+
}
42+
3343
public function testSetSettingWithType()
3444
{
3545
Yii::$app->settings->set('cron', 'activeEmailCommand', 'false', SettingType::BOOLEAN_TYPE);

0 commit comments

Comments
 (0)