Skip to content

Commit

Permalink
refs matomo-org#4126 fix settings were not saved
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur committed Oct 22, 2013
1 parent 313ccf7 commit b969dc7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion core/Plugin/Settings.php
Expand Up @@ -159,7 +159,8 @@ private function checkIsValidSetting($name)
$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']) {
Expand Down
4 changes: 2 additions & 2 deletions core/Settings/Manager.php
Expand Up @@ -30,10 +30,10 @@ public static function getAllPluginSettings()
{
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) {
Expand Down
9 changes: 4 additions & 5 deletions plugins/CoreAdminHome/Controller.php
Expand Up @@ -110,13 +110,12 @@ public function setPluginSettings()
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
Expand All @@ -125,8 +124,8 @@ public function setPluginSettings()

$pluginSetting = $pluginSettings[$pluginName];

foreach ($unserializedSettings as $key => $value) {
$pluginSetting->setSettingValue($key, $value);
foreach ($changedPluginSetting as $changedSetting) {
$pluginSetting->setSettingValue($changedSetting['name'], $changedSetting['value']);
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/CoreAdminHome/javascripts/pluginSettings.js
Expand Up @@ -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());
Expand All @@ -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;
});
Expand Down

0 comments on commit b969dc7

Please sign in to comment.