mirror of
https://github.com/humhub/humhub.git
synced 2025-04-21 07:31:53 +02:00
Reduce dynamic.php content params (#7332)
* Reduce dynamic.php content - remove `mailer` from dynamic.php * Autocommit PHP CS Fixer * Reduce dynamic.php content - remove `mailer` from dynamic.php * Reduce dynamic.php content - remove `mailer` from dynamic.php * Reduce dynamic.php content - remove `cache` from dynamic.php * Reduce dynamic.php content * Reduce dynamic.php content params * Reduce dynamic.php content params * Reduce dynamic.php content params * Reduce dynamic.php content params * Reduce dynamic.php content * Reduce dynamic.php content * Autocommit PHP CS Fixer * Reduce dynamic.php content * Autocommit PHP CS Fixer * Reduce dynamic.php content * Reduce dynamic.php content * Reduce dynamic.php content * Reduce dynamic.php content * Reduce dynamic.php content * Reduce dynamic.php content * Reduce dynamic.php content * Autocommit PHP CS Fixer * Reduce dynamic.php content * Reduce dynamic.php content * Autocommit PHP CS Fixer * Reduce dynamic.php content * Reduce dynamic.php content * Reduce dynamic.php content --------- Co-authored-by: gevorgmansuryan <gevorgmansuryan@users.noreply.github.com>
This commit is contained in:
parent
1633770af3
commit
f56117fbbc
@ -4,6 +4,7 @@ HumHub Changelog
|
||||
1.18 (TBA)
|
||||
------------------------------
|
||||
- Enh #7328: `Mailer`, `User` and `Cache` configs removed from `dynamic.php`
|
||||
- Enh #7332: Optimized `DynamicConfig` to store and read database information only
|
||||
|
||||
1.17.0-beta.3 (Unreleased)
|
||||
---------------------------------
|
||||
|
@ -8,15 +8,12 @@
|
||||
|
||||
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;
|
||||
use yii\console\ExitCode;
|
||||
use yii\helpers\Console;
|
||||
use yii\console\widgets\Table;
|
||||
use yii\helpers\Console;
|
||||
|
||||
/**
|
||||
* SettingsController provides CLI access to database settings
|
||||
@ -88,8 +85,6 @@ 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");
|
||||
@ -112,7 +107,6 @@ 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");
|
||||
@ -120,20 +114,4 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ namespace humhub\components;
|
||||
use humhub\helpers\DatabaseHelper;
|
||||
use humhub\helpers\EnvHelper;
|
||||
use humhub\interfaces\MailerInterface;
|
||||
use humhub\libs\DynamicConfig;
|
||||
use humhub\libs\SelfTest;
|
||||
use humhub\libs\TimezoneHelper;
|
||||
use Yii;
|
||||
@ -117,9 +116,7 @@ trait ApplicationTrait
|
||||
*/
|
||||
public function setInstalled()
|
||||
{
|
||||
$config = DynamicConfig::load();
|
||||
$config['params']['installed'] = true;
|
||||
DynamicConfig::save($config);
|
||||
Yii::$app->settings->set('installed', true);
|
||||
}
|
||||
|
||||
|
||||
@ -146,19 +143,7 @@ trait ApplicationTrait
|
||||
return false;
|
||||
}
|
||||
|
||||
return Yii::$app->params['databaseInstalled'] = in_array('setting', $db->schema->getTableNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application database in installed state
|
||||
*
|
||||
* @since 1.16
|
||||
*/
|
||||
public function setDatabaseInstalled()
|
||||
{
|
||||
$config = DynamicConfig::load();
|
||||
$config['params']['databaseInstalled'] = true;
|
||||
DynamicConfig::save($config);
|
||||
return in_array('setting', $db->schema->getTableNames());
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@ class SettingsLoader implements BootstrapInterface
|
||||
$this->setMailerConfig($app);
|
||||
$this->setUserConfig($app);
|
||||
$this->setCacheConfig($app);
|
||||
$this->setParams($app);
|
||||
}
|
||||
|
||||
private function updateComponentDefinition($app, $component, $definition)
|
||||
@ -137,4 +138,11 @@ class SettingsLoader implements BootstrapInterface
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
protected function setParams($app)
|
||||
{
|
||||
$app->name = $app->settings->get('name');
|
||||
$app->params['installed'] = $app->settings->get('installed');
|
||||
$app->params['horImageScrollOnMobile'] = $app->settings->get('horImageScrollOnMobile');
|
||||
}
|
||||
}
|
||||
|
@ -19,17 +19,6 @@ use yii\helpers\ArrayHelper;
|
||||
*/
|
||||
class DynamicConfig extends BaseObject
|
||||
{
|
||||
/**
|
||||
* Add an array to the dynamic configuration
|
||||
*
|
||||
* @param array $new
|
||||
*/
|
||||
public static function merge($new)
|
||||
{
|
||||
$config = ArrayHelper::merge(self::load(), $new);
|
||||
self::save($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dynamic configuration
|
||||
*
|
||||
@ -52,7 +41,17 @@ class DynamicConfig extends BaseObject
|
||||
return [];
|
||||
}
|
||||
|
||||
return $config;
|
||||
$validConfig = [
|
||||
'components' => [
|
||||
'db' => ArrayHelper::getValue($config, 'components.db', []),
|
||||
],
|
||||
];
|
||||
|
||||
if ($validConfig != $config) {
|
||||
self::save($validConfig);
|
||||
}
|
||||
|
||||
return $validConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +63,7 @@ class DynamicConfig extends BaseObject
|
||||
{
|
||||
$content = '<' . '?php return ';
|
||||
$content .= var_export($config, true);
|
||||
$content .= '; ?' . '>';
|
||||
$content .= ';';
|
||||
|
||||
$configFile = self::getConfigFilePath();
|
||||
file_put_contents($configFile, $content);
|
||||
@ -80,50 +79,11 @@ class DynamicConfig extends BaseObject
|
||||
|
||||
/**
|
||||
* Rewrites DynamicConfiguration based on Database Stored Settings
|
||||
*
|
||||
* @deprecated since 1.8
|
||||
*/
|
||||
public static function rewrite()
|
||||
{
|
||||
// Get Current Configuration
|
||||
$config = self::load();
|
||||
|
||||
// Add Application Name to Configuration
|
||||
$config['name'] = Yii::$app->settings->get('name');
|
||||
|
||||
// Add Caching
|
||||
|
||||
|
||||
// Remove old theme/view stuff
|
||||
unset($config['components']['view']);
|
||||
|
||||
// Cleanups
|
||||
unset($config['components']['db']['charset']);
|
||||
unset($config['components']['formatterApp']);
|
||||
|
||||
// Remove old localisation options
|
||||
unset($config['timeZone']);
|
||||
unset($config['language']);
|
||||
unset($config['components']['formatter']['defaultTimeZone']);
|
||||
if (empty($config['components']['formatter'])) {
|
||||
unset($config['components']['formatter']);
|
||||
}
|
||||
|
||||
$config['params']['config_created_at'] = time();
|
||||
$config['params']['horImageScrollOnMobile'] = Yii::$app->settings->get('horImageScrollOnMobile');
|
||||
|
||||
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', 'horImageScrollOnMobile']));
|
||||
}
|
||||
|
||||
public static function getConfigFilePath()
|
||||
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use humhub\libs\DynamicConfig;
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m241211_193138_reduce_dynamic_config
|
||||
*/
|
||||
class m241211_193138_reduce_dynamic_config extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
if (Yii::$app->isInstalled()) {
|
||||
DynamicConfig::load();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
echo "m241211_193138_reduce_dynamic_config cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@
|
||||
|
||||
namespace humhub\modules\admin\models\forms;
|
||||
|
||||
use humhub\libs\DynamicConfig;
|
||||
use humhub\modules\topic\jobs\ConvertTopicsToGlobalJob;
|
||||
use humhub\modules\user\models\User;
|
||||
use humhub\modules\user\Module;
|
||||
@ -166,7 +165,6 @@ class AuthenticationSettingsForm extends Model
|
||||
]));
|
||||
}
|
||||
|
||||
DynamicConfig::rewrite();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,6 @@
|
||||
|
||||
namespace humhub\modules\admin\models\forms;
|
||||
|
||||
use DateTimeZone;
|
||||
use humhub\libs\DynamicConfig;
|
||||
use humhub\libs\TimezoneHelper;
|
||||
use humhub\modules\ui\icon\widgets\Icon;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
@ -114,8 +111,6 @@ class BasicSettingsForm extends Model
|
||||
Yii::$app->getModule('tour')->settings->set('enable', $this->tour);
|
||||
Yii::$app->getModule('friendship')->settings->set('enable', $this->enableFriendshipModule);
|
||||
|
||||
DynamicConfig::rewrite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace humhub\modules\admin\models\forms;
|
||||
|
||||
use humhub\libs\DynamicConfig;
|
||||
use humhub\modules\admin\events\FetchReloadableScriptsEvent;
|
||||
use humhub\modules\admin\Module;
|
||||
use Yii;
|
||||
@ -106,7 +105,6 @@ class CacheSettingsForm extends Model
|
||||
$settingsManager->set('cache.expireTime', $this->expireTime);
|
||||
$settingsManager->set('cache.reloadableScripts', $this->reloadableScripts);
|
||||
|
||||
DynamicConfig::rewrite();
|
||||
self::flushCache();
|
||||
|
||||
return true;
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
namespace humhub\modules\admin\models\forms;
|
||||
|
||||
use humhub\libs\DynamicConfig;
|
||||
use humhub\libs\LogoImage;
|
||||
use humhub\modules\file\validators\ImageSquareValidator;
|
||||
use humhub\modules\stream\actions\Stream;
|
||||
@ -168,8 +167,6 @@ class DesignSettingsForm extends Model
|
||||
SiteIcon::set($this->icon);
|
||||
}
|
||||
|
||||
DynamicConfig::rewrite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace humhub\modules\admin\models\forms;
|
||||
|
||||
use humhub\libs\DynamicConfig;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
|
||||
@ -141,8 +140,6 @@ class MailingSettingsForm extends Model
|
||||
$settingsManager->set('mailer.systemEmailName', $this->systemEmailName);
|
||||
$settingsManager->set('mailer.systemEmailReplyTo', $this->systemEmailReplyTo);
|
||||
|
||||
DynamicConfig::rewrite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -106,28 +106,6 @@ class Module extends \humhub\components\Module
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets application in installed state (disables installer)
|
||||
*
|
||||
* @deprecated since v1.16; use Yii::$app->setInstalled()
|
||||
* @see Yii::$app->setInstalled()
|
||||
*/
|
||||
public function setInstalled()
|
||||
{
|
||||
Yii::$app->setInstalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application database in installed state
|
||||
*
|
||||
* @deprecated since v1.16; use Yii::$app->setDatabaseInstalled()
|
||||
* @see Yii::$app->setDatabaseInstalled()
|
||||
*/
|
||||
public function setDatabaseInstalled()
|
||||
{
|
||||
Yii::$app->setDatabaseInstalled();
|
||||
}
|
||||
|
||||
protected function initConfigSteps()
|
||||
{
|
||||
/**
|
||||
|
@ -66,8 +66,6 @@ class InstallController extends Controller
|
||||
$config = DynamicConfig::load();
|
||||
|
||||
$config['components']['db'] = $dbConfig;
|
||||
$config['params']['installer']['db']['installer_hostname'] = $db_host;
|
||||
$config['params']['installer']['db']['installer_database'] = $db_name;
|
||||
|
||||
DynamicConfig::save($config);
|
||||
|
||||
@ -92,10 +90,6 @@ class InstallController extends Controller
|
||||
|
||||
MigrationService::create()->migrateUp();
|
||||
|
||||
DynamicConfig::rewrite();
|
||||
|
||||
Yii::$app->setDatabaseInstalled();
|
||||
|
||||
$this->stdout(" * Finishing\n", Console::FG_YELLOW);
|
||||
Yii::$app->setInstalled();
|
||||
|
||||
|
@ -12,7 +12,6 @@ use Exception;
|
||||
use humhub\compat\HForm;
|
||||
use humhub\components\access\ControllerAccess;
|
||||
use humhub\components\Controller;
|
||||
use humhub\libs\DynamicConfig;
|
||||
use humhub\libs\ProfileImage;
|
||||
use humhub\libs\UUID;
|
||||
use humhub\modules\comment\models\Comment;
|
||||
@ -549,8 +548,6 @@ class ConfigController extends Controller
|
||||
Yii::$app->settings->set('secret', UUID::v4());
|
||||
}
|
||||
|
||||
DynamicConfig::rewrite();
|
||||
|
||||
return $this->redirect(['finished']);
|
||||
}
|
||||
|
||||
|
@ -148,8 +148,6 @@ class SetupController extends Controller
|
||||
|
||||
// Write Config
|
||||
$config['components']['db'] = $dbConfig;
|
||||
$config['params']['installer']['db']['installer_hostname'] = $model->hostname;
|
||||
$config['params']['installer']['db']['installer_database'] = $model->database;
|
||||
|
||||
DynamicConfig::save($config);
|
||||
|
||||
@ -220,9 +218,5 @@ class SetupController extends Controller
|
||||
|
||||
// Migrate Up Database
|
||||
MigrationService::create()->migrateUp();
|
||||
|
||||
DynamicConfig::rewrite();
|
||||
|
||||
Yii::$app->setDatabaseInstalled();
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
namespace humhub\modules\installer\forms;
|
||||
|
||||
use humhub\libs\DynamicConfig;
|
||||
use humhub\libs\TimezoneHelper;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
@ -67,8 +66,6 @@ class LocalisationForm extends Model
|
||||
Yii::$app->settings->set('defaultLanguage', $this->language);
|
||||
Yii::$app->settings->set('serverTimeZone', $this->timeZone);
|
||||
|
||||
DynamicConfig::rewrite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
namespace humhub\modules\ui\commands;
|
||||
|
||||
use Exception;
|
||||
use humhub\libs\DynamicConfig;
|
||||
use humhub\modules\ui\view\bootstrap\ThemeLoader;
|
||||
use humhub\modules\ui\view\helpers\ThemeHelper;
|
||||
use Yii;
|
||||
@ -76,7 +75,6 @@ class ThemeController extends Controller
|
||||
}
|
||||
|
||||
$theme->activate();
|
||||
DynamicConfig::rewrite();
|
||||
(new ThemeLoader())->bootstrap(Yii::$app);
|
||||
|
||||
$this->stdout("\nSuccessfully switched to theme: \n", Console::BOLD);
|
||||
|
Loading…
x
Reference in New Issue
Block a user