Lets call it settings.name instead

This commit is contained in:
slawkens 2023-05-16 14:17:21 +02:00
parent 481ba5a30f
commit 7aff4557a6
4 changed files with 12 additions and 10 deletions

View File

@ -42,11 +42,13 @@ if (!is_array($settingsFile)) {
return; return;
} }
$settingsKeyName = ($plugin == 'core' ? $plugin : $settingsFile['key']);
if (isset($_POST['save'])) { if (isset($_POST['save'])) {
$db->query('DELETE FROM `' . TABLE_PREFIX . 'settings` WHERE `plugin_name` = ' . $db->quote($plugin) . ';'); $db->query('DELETE FROM `' . TABLE_PREFIX . 'settings` WHERE `name` = ' . $db->quote($settingsKeyName) . ';');
foreach ($_POST['settings'] as $key => $value) { foreach ($_POST['settings'] as $key => $value) {
try { try {
$db->insert(TABLE_PREFIX . 'settings', ['plugin_name' => $plugin, 'key' => $key, 'value' => $value]); $db->insert(TABLE_PREFIX . 'settings', ['name' => $settingsKeyName, 'key' => $key, 'value' => $value]);
} catch (PDOException $error) { } catch (PDOException $error) {
warning('Error while saving setting (' . $plugin . ' - ' . $key . '): ' . $error->getMessage()); warning('Error while saving setting (' . $plugin . ' - ' . $key . '): ' . $error->getMessage());
} }
@ -62,7 +64,7 @@ if (isset($_POST['save'])) {
$title = ($plugin == 'core' ? 'Settings' : 'Plugin Settings - ' . $plugin); $title = ($plugin == 'core' ? 'Settings' : 'Plugin Settings - ' . $plugin);
$settings = Settings::display($plugin, $settingsFile['settings']); $settings = Settings::display($settingsKeyName, $settingsFile['settings']);
$twig->display('admin.settings.html.twig', [ $twig->display('admin.settings.html.twig', [
'settings' => $settings, 'settings' => $settings,

View File

@ -306,7 +306,7 @@ INSERT INTO `myaac_gallery` (`id`, `ordering`, `comment`, `image`, `thumb`, `aut
CREATE TABLE `myaac_settings` CREATE TABLE `myaac_settings`
( (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`plugin_name` VARCHAR(255) NOT NULL DEFAULT '', `name` VARCHAR(255) NOT NULL DEFAULT '',
`key` VARCHAR(255) NOT NULL DEFAULT '', `key` VARCHAR(255) NOT NULL DEFAULT '',
`value` TEXT NOT NULL, `value` TEXT NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),

View File

@ -44,7 +44,7 @@ class Settings implements ArrayAccess
if($settings->rowCount() > 0) { if($settings->rowCount() > 0) {
foreach ($settings->fetchAll(PDO::FETCH_ASSOC) as $setting) { foreach ($settings->fetchAll(PDO::FETCH_ASSOC) as $setting) {
$this->settings[$setting['plugin_name']][$setting['key']] = $setting['value']; $this->settings[$setting['name']][$setting['key']] = $setting['value'];
} }
} }
@ -56,7 +56,7 @@ class Settings implements ArrayAccess
public function updateInDatabase($pluginName, $key, $value) public function updateInDatabase($pluginName, $key, $value)
{ {
global $db; global $db;
$db->update(TABLE_PREFIX . 'settings', ['value' => $value], ['plugin_name' => $pluginName, 'key' => $key]); $db->update(TABLE_PREFIX . 'settings', ['value' => $value], ['name' => $pluginName, 'key' => $key]);
} }
public function deleteFromDatabase($pluginName, $key = null) public function deleteFromDatabase($pluginName, $key = null)
@ -64,10 +64,10 @@ class Settings implements ArrayAccess
global $db; global $db;
if (!isset($key)) { if (!isset($key)) {
$db->delete(TABLE_PREFIX . 'settings', ['plugin_name' => $pluginName], -1); $db->delete(TABLE_PREFIX . 'settings', ['name' => $pluginName], -1);
} }
else { else {
$db->delete(TABLE_PREFIX . 'settings', ['plugin_name' => $pluginName, 'key' => $key]); $db->delete(TABLE_PREFIX . 'settings', ['name' => $pluginName, 'key' => $key]);
} }
} }
@ -75,7 +75,7 @@ class Settings implements ArrayAccess
{ {
global $db; global $db;
$query = 'SELECT `key`, `value` FROM `' . TABLE_PREFIX . 'settings` WHERE `plugin_name` = ' . $db->quote($plugin) . ';'; $query = 'SELECT `key`, `value` FROM `' . TABLE_PREFIX . 'settings` WHERE `name` = ' . $db->quote($plugin) . ';';
$query = $db->query($query); $query = $db->query($query);
$settingsDb = []; $settingsDb = [];

View File

@ -5,7 +5,7 @@ if(!$db->hasTable(TABLE_PREFIX . 'settings')) {
$db->exec("CREATE TABLE `" . TABLE_PREFIX . "settings` $db->exec("CREATE TABLE `" . TABLE_PREFIX . "settings`
( (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`plugin_name` VARCHAR(255) NOT NULL DEFAULT '', `name` VARCHAR(255) NOT NULL DEFAULT '',
`key` VARCHAR(255) NOT NULL DEFAULT '', `key` VARCHAR(255) NOT NULL DEFAULT '',
`value` TEXT NOT NULL, `value` TEXT NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),