mirror of
https://github.com/typemill/typemill.git
synced 2025-08-16 11:04:46 +02:00
changed updateSettings
This commit is contained in:
@@ -68,21 +68,25 @@ class ControllerApiSystemExtensions extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$objectdata = [];
|
||||
# store updated settings here
|
||||
$settings = new Settings();
|
||||
|
||||
if($params['type'] == 'plugins')
|
||||
{
|
||||
$objectdata['plugins'][$params['name']] = $this->settings[$params['type']][$params['name']];
|
||||
$objectdata['plugins'][$params['name']]['active'] = $params['checked'];
|
||||
$pluginsettings = $this->settings['plugins'][$params['name']] ?? $params['name'];
|
||||
$pluginsettings['active'] = $params['checked'];
|
||||
$updatedSettings = $settings->updateSettings($pluginsettings, 'plugins', $params['name']);
|
||||
}
|
||||
elseif($params['type'] == 'themes')
|
||||
{
|
||||
$objectdata['theme'] = $params['name'];
|
||||
$themesettings = $this->settings['themes'][$params['name']] ?? $params['name'];
|
||||
$updatedSettings = $settings->updateSettings($themesettings, 'themes', $params['name']);
|
||||
if($updatedSettings)
|
||||
{
|
||||
$updatedSettings = $settings->updateSettings($params['name'], 'theme');
|
||||
}
|
||||
}
|
||||
|
||||
# store updated settings here
|
||||
$settings = new Settings();
|
||||
$updatedSettings = $settings->updateSettings($objectdata);
|
||||
|
||||
$response->getBody()->write(json_encode([
|
||||
'message' => Translations::translate('settings have been saved')
|
||||
]));
|
||||
|
@@ -42,11 +42,9 @@ class ControllerApiSystemPlugins extends Controller
|
||||
$validatedOutput['active'] = true;
|
||||
}
|
||||
|
||||
$plugindata['plugins'][$pluginname] = $validatedOutput;
|
||||
|
||||
# store updated settings here
|
||||
$settings = new Settings();
|
||||
$updatedSettings = $settings->updateSettings($plugindata);
|
||||
$updatedSettings = $settings->updateSettings($validatedOutput, 'plugins', $pluginname);
|
||||
|
||||
$response->getBody()->write(json_encode([
|
||||
'message' => Translations::translate('settings have been saved')
|
||||
|
@@ -37,12 +37,10 @@ class ControllerApiSystemThemes extends Controller
|
||||
|
||||
# delete themecss
|
||||
unset($validatedOutput['customcss']);
|
||||
|
||||
$themedata['themes'][$themename] = $validatedOutput;
|
||||
|
||||
# store updated settings here
|
||||
$settings = new Settings();
|
||||
$updatedSettings = $settings->updateSettings($themedata);
|
||||
$updatedSettings = $settings->updateSettings($validatedOutput, 'themes', $themename);
|
||||
|
||||
$response->getBody()->write(json_encode([
|
||||
'message' => Translations::translate('settings have been saved')
|
||||
|
@@ -119,32 +119,49 @@ class Settings
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateSettings(array $newSettings)
|
||||
public function updateSettings($newSettings, $key1 = false, $key2 = false)
|
||||
{
|
||||
$userSettings = $this->getUserSettings();
|
||||
|
||||
# only allow if usersettings already exists (setup has been done)
|
||||
if($userSettings)
|
||||
{
|
||||
# merge usersettings with new settings
|
||||
$settings = array_merge($userSettings, $newSettings);
|
||||
|
||||
# make sure that multidimensional arrays are merged correctly
|
||||
# for example: only one plugin data will be passed with new settings, with array merge all others will be deleted.
|
||||
foreach($newSettings as $key => $settingsItems)
|
||||
# hard overwrite
|
||||
if($key1 && $key2)
|
||||
{
|
||||
if(is_array($settingsItems) && isset($userSettings[$key]))
|
||||
$userSettings[$key1][$key2] = $newSettings;
|
||||
$settings = $userSettings;
|
||||
}
|
||||
# hard overwrite
|
||||
elseif($key1)
|
||||
{
|
||||
$userSettings[$key1] = $newSettings;
|
||||
$settings = $userSettings;
|
||||
}
|
||||
# only merge
|
||||
else
|
||||
{
|
||||
# merge usersettings with new settings
|
||||
$settings = array_merge($userSettings, $newSettings);
|
||||
|
||||
# make sure that multidimensional arrays are merged correctly
|
||||
# for example: only one plugin data will be passed with new settings, with array merge all others will be deleted.
|
||||
foreach($newSettings as $key => $settingsItems)
|
||||
{
|
||||
if($this->array_is_list($settingsItems))
|
||||
if(is_array($settingsItems) && isset($userSettings[$key]))
|
||||
{
|
||||
# for numeric/list arrays instead of associative arrays we only use new values
|
||||
$settings[$key] = $newSettings[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
$settings[$key] = array_merge($userSettings[$key], $newSettings[$key]);
|
||||
if($this->array_is_list($settingsItems))
|
||||
{
|
||||
# for numeric/list arrays instead of associative arrays we only use new values
|
||||
$settings[$key] = $newSettings[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
$settings[$key] = array_merge($userSettings[$key], $newSettings[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($this->storage->updateYaml('settingsFolder', '', 'settings.yaml', $settings))
|
||||
|
@@ -333,7 +333,7 @@ class Storage
|
||||
}
|
||||
|
||||
$writefile = fwrite($openfile, $data);
|
||||
if(!$writefile)
|
||||
if($writefile === false)
|
||||
{
|
||||
$this->error = Translations::translate('Could not write to the file') . ' ' . $filepath;
|
||||
|
||||
|
@@ -89,14 +89,14 @@ abstract class Plugin implements EventSubscriberInterface
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function storePluginData($filename, $pluginname = false)
|
||||
protected function storePluginData($filename, $data, $method = NULL)
|
||||
{
|
||||
$pluginname = $this->getPluginName($pluginname);
|
||||
|
||||
$storageClass = $this->container->get('settings')['storage'];
|
||||
$storage = new StorageWrapper($storageClass);
|
||||
|
||||
$result = $storage->writeFile('dataFolder', $pluginname, $filename);
|
||||
$result = $storage->writeFile('dataFolder', $pluginname, $filename, $data, $method = NULL);
|
||||
|
||||
if($result)
|
||||
{
|
||||
|
@@ -13,7 +13,7 @@ app.component('component-text', {
|
||||
:name="name"
|
||||
:placeholder="placeholder"
|
||||
:value="value"
|
||||
@input="update($event, name)">
|
||||
@input="update($event, name)"><slot></slot>
|
||||
<p v-if="errors[name]" class="text-xs text-red-500">{{ errors[name] }}</p>
|
||||
<p v-else class="text-xs">{{ $filters.translate(description) }}</p>
|
||||
</div>`,
|
||||
|
@@ -4,7 +4,7 @@ const app = Vue.createApp({
|
||||
<p v-if="version.system !== undefined"><a href="https://typemill.net" class="block p-2 text-center bg-rose-500 text-white">Please update typemill to version {{ version.system }}</a></p>
|
||||
<ul class="flex flex-wrap mt-4 mb-4">
|
||||
<li v-for="tab in tabs">
|
||||
<button class="px-2 py-2 border-b-2 border-stone-200 dark:border-stone-900 hover:border-stone-700 hover:dark:border-stone-200 transition duration-100" :class="(tab == currentTab) ? 'border-stone-700 dark:border-stone-200' : ''" @click.prevent="activateTab(tab)">{{ $filters.translate(tab) }}</button>
|
||||
<button class="px-2 py-2 border-b-2 border-stone-200 dark:border-stone-900 hover:border-stone-700 hover:dark:border-stone-200 hover:bg-stone-200 hover:dark:bg-stone-900 transition duration-100" :class="(tab == currentTab) ? 'border-stone-700 bg-stone-200 dark:bg-stone-900 dark:border-stone-200' : ''" @click.prevent="activateTab(tab)">{{ $filters.translate(tab) }}</button>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-for="(fieldDefinition, fieldname) in formDefinitions">
|
||||
|
@@ -1,4 +1,4 @@
|
||||
version: '2.0.2'
|
||||
version: '2.0.3'
|
||||
title: 'Typemill'
|
||||
author: 'Unknown'
|
||||
copyright: false
|
||||
|
@@ -117,10 +117,10 @@ $settings['license'] = $license->getLicenseScope($urlinfo);
|
||||
/****************************
|
||||
* LOAD & UPDATE PLUGINS *
|
||||
****************************/
|
||||
|
||||
$plugins = Plugins::loadPlugins();
|
||||
$routes = [];
|
||||
$middleware = [];
|
||||
$pluginSettings = [];
|
||||
|
||||
# if there are less plugins in the scan than in the settings, then a plugin has been removed
|
||||
if(isset($settings['plugins']) && (count($plugins) < count($settings['plugins'])) )
|
||||
@@ -133,11 +133,15 @@ foreach($plugins as $plugin)
|
||||
$pluginName = $plugin['name'];
|
||||
$className = $plugin['className'];
|
||||
|
||||
# if plugin is not in the settings already
|
||||
if(!isset($settings['plugins'][$pluginName]))
|
||||
# store existing plugin-settings to update settings later
|
||||
if(isset($settings['plugins'][$pluginName]))
|
||||
{
|
||||
$pluginSettings[$pluginName] = $settings['plugins'][$pluginName];
|
||||
}
|
||||
else
|
||||
{
|
||||
# it is a new plugin. Add it and set active to false
|
||||
$settings['plugins'][$pluginName] = ['active' => false];
|
||||
$pluginSettings[$pluginName] = ['active' => false];
|
||||
|
||||
# and set flag to refresh the settings
|
||||
$updateSettings = true;
|
||||
@@ -149,7 +153,12 @@ foreach($plugins as $plugin)
|
||||
{
|
||||
if(!$settings['license'] OR !isset($settings['license'][$PluginLicence]))
|
||||
{
|
||||
$settings['plugins'][$pluginName]['active'] = false;
|
||||
\Typemill\Static\Helper\addLogEntry('No License: ' . $pluginName);
|
||||
if($pluginSettings[$pluginName]['active'])
|
||||
{
|
||||
$pluginSettings[$pluginName]['active'] = false;
|
||||
$updateSettings = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,9 +176,7 @@ foreach($plugins as $plugin)
|
||||
if(isset($updateSettings))
|
||||
{
|
||||
# update stored settings file
|
||||
$newPluginSettings = ['plugins' => $settings['plugins']];
|
||||
$settingsModel->updateSettings($newPluginSettings);
|
||||
# Settings::updateSettings($settings);
|
||||
$settingsModel->updateSettings($pluginSettings, 'plugins');
|
||||
}
|
||||
|
||||
# add final settings to the container
|
||||
|
Reference in New Issue
Block a user