From c4934ea5e11a74d30b1e87b49140d5c35346a0ae Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Mon, 20 Jan 2020 22:00:13 +0100 Subject: [PATCH] Fix: Settings cli rewrite dynamic config when required --- .../humhub/commands/SettingsController.php | 19 +++++++++++++++++++ protected/humhub/libs/DynamicConfig.php | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/protected/humhub/commands/SettingsController.php b/protected/humhub/commands/SettingsController.php index 33255ada6e..7856c53ee1 100644 --- a/protected/humhub/commands/SettingsController.php +++ b/protected/humhub/commands/SettingsController.php @@ -10,6 +10,7 @@ namespace humhub\commands; use humhub\components\Module; use humhub\components\SettingsManager; +use humhub\libs\DynamicConfig; use humhub\models\Setting; use Yii; use yii\console\Controller; @@ -88,6 +89,8 @@ class SettingsController extends Controller $settingsManager = new SettingsManager(['moduleId' => $moduleId]); $settingsManager->set($name, $value); + $this->handleDynamicConfig($moduleId, $name); + $this->stdout("\n*** Successfully set setting\n\n", Console::FG_GREEN); $this->stdout("Name:\t\t" . $name . "\n"); $this->stdout("Module ID:\t" . $moduleId . "\n\n"); @@ -110,6 +113,7 @@ class SettingsController extends Controller $settingsManager = new SettingsManager(['moduleId' => $moduleId]); $settingsManager->delete($name); + $this->handleDynamicConfig($moduleId, $name); $this->stdout("\n*** Successfully deleted setting\n\n", Console::FG_GREEN); $this->stdout("Name:\t\t" . $name . "\n"); @@ -118,5 +122,20 @@ class SettingsController extends Controller return ExitCode::OK; } + /** + * Handles dynamic config rewrite if required + * + * @param $moduleId + * @param $name + */ + private function handleDynamicConfig($moduleId, $name) + { + if (DynamicConfig::needRewrite($moduleId, $name)) { + // Force reload + Yii::$app->settings->init(); + DynamicConfig::rewrite(); + } + } + } diff --git a/protected/humhub/libs/DynamicConfig.php b/protected/humhub/libs/DynamicConfig.php index 8875806f9c..ad954fd6b2 100644 --- a/protected/humhub/libs/DynamicConfig.php +++ b/protected/humhub/libs/DynamicConfig.php @@ -180,6 +180,21 @@ class DynamicConfig extends BaseObject self::save($config); } + /** + * Checks whether the config should be rewritten based on changed setting name + * + * @param $moduleId + * @param $name + * @return bool + */ + public static function needRewrite($moduleId, $name) + { + return (in_array($name, [ + 'name', 'defaultLanguage', 'timeZone', 'cache.class', 'mailer.transportType', + 'mailer.hostname', 'mailer.username', 'mailer.password', 'mailer.encryption', + 'mailer.port', 'horImageScrollOnMobile'])); + } + public static function getConfigFilePath() { return Yii::getAlias(Yii::$app->params['dynamicConfigFile']);