diff --git a/composer.json b/composer.json index 3b0de7f..0b8279a 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "24unix/bindapi", "description": "manage Bind9 DNS server via REST API", "version": "1.0.9", - "build_number": "364", + "build_number": "365", "authors": [ { "name": "Micha Espey", diff --git a/src/Repository/SettingsRepository.php b/src/Repository/SettingsRepository.php index 49afbda..795d2fa 100644 --- a/src/Repository/SettingsRepository.php +++ b/src/Repository/SettingsRepository.php @@ -40,13 +40,19 @@ readonly class SettingsRepository public function set(string $name, string $value): int { - - $sql = " - INSERT INTO " . DatabaseConnection::TABLE_SETTINGS . " (name, value) - VALUES (:name, :value) - ON DUPLICATE KEY UPDATE - value = :value + $currentSetting = $this->findByName($name); + if ($currentSetting !== false) { + $sql = " + UPDATE " . DatabaseConnection::TABLE_SETTINGS . " + SET value = :value + WHERE name = :name "; + } else { + $sql = " + INSERT INTO " . DatabaseConnection::TABLE_SETTINGS . " (name, value) + VALUES (:name, :value) + "; + } try { $statement = $this->databaseConnection->getConnection()->prepare(query: $sql);