Add helper to check if settings exists in DB

MAILPOET-5549
This commit is contained in:
John Oleksowicz
2023-10-19 13:41:08 -05:00
committed by Aschepikov
parent d81f303d45
commit 281c75c67c
2 changed files with 18 additions and 0 deletions

View File

@@ -124,6 +124,17 @@ class SettingsController {
unset($this->settings[$key]);
}
/**
* Returns true if a value is stored in the database for the given key
*
* @param string $key
*
* @return bool
*/
public function hasSavedValue(string $key): bool {
return $this->get($key, 'unset') !== 'unset';
}
private function ensureLoaded() {
if ($this->loaded) {
return;

View File

@@ -120,6 +120,13 @@ class SettingsControllerTest extends \MailPoetTest {
$this->assertEquals(true, true);
}
public function testItCanCheckIfSavedValueExists(): void {
$this->assertFalse($this->controller->hasSavedValue('test_key'));
$this->createOrUpdateSetting('test_key', 'some value');
$this->controller->resetCache(); // force reload from database
$this->assertTrue($this->controller->hasSavedValue('test_key'));
}
private function createOrUpdateSetting($name, $value) {
$tableName = $this->entityManager->getClassMetadata(SettingEntity::class)->getTableName();
$this->connection->executeStatement("