From b969dc796fe9a0116ef7481d009ef10c2ca7dc0a Mon Sep 17 00:00:00 2001
From: Thomas Steur <thomas.steur@gmail.com>
Date: Tue, 22 Oct 2013 05:14:27 +0000
Subject: [PATCH] refs #4126 fix settings were not saved

---
 core/Plugin/Settings.php                            | 3 ++-
 core/Settings/Manager.php                           | 4 ++--
 plugins/CoreAdminHome/Controller.php                | 9 ++++-----
 plugins/CoreAdminHome/javascripts/pluginSettings.js | 4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/core/Plugin/Settings.php b/core/Plugin/Settings.php
index 9fc7fa9f3b..691224d662 100644
--- a/core/Plugin/Settings.php
+++ b/core/Plugin/Settings.php
@@ -159,7 +159,8 @@ class Settings
         $setting = $this->getSetting($name);
 
         if (empty($setting)) {
-            throw new \Exception('This setting does not exist');
+            // TODO escape $name? or is it automatically escaped?
+            throw new \Exception(sprintf('The setting %s does not exist', $name));
         }
 
         if (!$setting['displayedForCurrentUser']) {
diff --git a/core/Settings/Manager.php b/core/Settings/Manager.php
index 045ae4e49b..a79c672a38 100644
--- a/core/Settings/Manager.php
+++ b/core/Settings/Manager.php
@@ -30,10 +30,10 @@ class Manager
     {
         if (empty(static::$settings)) {
 
-            $pluginSettings = array('Login' => 'Piwik\\Plugins\\Login\\Settings');
+            $pluginSettings = array();
             // TODO: document hook and think about better name
 
-            Piwik::postEvent('Plugin.addSettings', $pluginSettings);
+            Piwik::postEvent('Plugin.addSettings', array(&$pluginSettings));
 
             $settings = array();
             foreach ($pluginSettings as $pluginName => $pluginSetting) {
diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php
index ddc71608bf..f1e641a367 100644
--- a/plugins/CoreAdminHome/Controller.php
+++ b/plugins/CoreAdminHome/Controller.php
@@ -110,13 +110,12 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
         Piwik::checkUserIsNotAnonymous();
         Json::sendHeaderJSON();
 
-        $updateSettings = Common::getRequestVar('settings', null, 'json');
+        $changedPluginSettings = Common::getRequestVar('settings', null, 'array');
         $pluginSettings = SettingsManager::getAllPluginSettings();
 
         try {
 
-            foreach ($updateSettings as $pluginName => $serializedSetting) {
-                $unserializedSettings = UrlHelper::getArrayFromQueryString($serializedSetting);
+            foreach ($changedPluginSettings as $pluginName => $changedPluginSetting) {
 
                 if (!array_key_exists($pluginName, $pluginSettings)) {
                     // this plugin is not using settings, skip it
@@ -125,8 +124,8 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
 
                 $pluginSetting = $pluginSettings[$pluginName];
 
-                foreach ($unserializedSettings as $key => $value) {
-                    $pluginSetting->setSettingValue($key, $value);
+                foreach ($changedPluginSetting as $changedSetting) {
+                    $pluginSetting->setSettingValue($changedSetting['name'], $changedSetting['value']);
                 }
             }
 
diff --git a/plugins/CoreAdminHome/javascripts/pluginSettings.js b/plugins/CoreAdminHome/javascripts/pluginSettings.js
index 9a6048b280..14c63914b5 100644
--- a/plugins/CoreAdminHome/javascripts/pluginSettings.js
+++ b/plugins/CoreAdminHome/javascripts/pluginSettings.js
@@ -22,7 +22,7 @@ $(document).ready(function () {
             module: 'CoreAdminHome',
             action: 'setPluginSettings'
         }, 'GET');
-        ajaxHandler.addParams({settings: JSON.stringify(getSettings())}, 'POST');
+        ajaxHandler.addParams({settings: getSettings()}, 'POST');
         ajaxHandler.redirectOnSuccess();
         ajaxHandler.setLoadingElement(getLoadingElement());
         ajaxHandler.setErrorElement(getErrorElement());
@@ -39,7 +39,7 @@ $(document).ready(function () {
             $pluginSection = $(pluginSection);
 
             var pluginName = $pluginSection.attr('data-pluginname');
-            var serialized = $('input, textarea, select', $pluginSection ).serialize();
+            var serialized = $('input, textarea, select', $pluginSection ).serializeArray();
 
             values[pluginName] = serialized;
         });
-- 
GitLab