/** * Rewrites DynamicConfiguration based on Database Stored Settings */ public static function rewrite() { // Get Current Configuration $config = self::load(); // Add Application Name to Configuration $config['name'] = Setting::Get('name'); // Add Default language $defaultLanguage = Setting::Get('defaultLanguage'); if ($defaultLanguage !== null && $defaultLanguage != "") { $config['language'] = Setting::Get('defaultLanguage'); } else { $config['language'] = Yii::$app->language; } $timeZone = Setting::Get('timeZone'); if ($timeZone != "") { $config['timeZone'] = $timeZone; $config['components']['formatter']['defaultTimeZone'] = $timeZone; $config['components']['formatterApp']['defaultTimeZone'] = $timeZone; $config['components']['formatterApp']['timeZone'] = $timeZone; } // Add Caching $cacheClass = Setting::Get('type', 'cache'); if (in_array($cacheClass, ['yii\\caching\\DummyCache', 'yii\\caching\\ApcCache', 'yii\\caching\\FileCache'])) { $config['components']['cache'] = ['class' => $cacheClass, 'keyPrefix' => Yii::$app->id]; // Prefix APC Cache Keys //if ($cacheClass == 'yii\caching\ApcCache') { // $config['components']['cache'] = [ // 'keyPrefix' => Yii::$app->id // ]; //} } // Add User settings $config['components']['user'] = array(); if (Setting::Get('defaultUserIdleTimeoutSec', 'authentication_internal')) { $config['components']['user']['authTimeout'] = Setting::Get('defaultUserIdleTimeoutSec', 'authentication_internal'); } // Install Mail Component $mail = []; $mail['transport'] = array(); if (Setting::Get('transportType', 'mailing') == 'smtp') { $mail['transport']['class'] = 'Swift_SmtpTransport'; if (Setting::Get('hostname', 'mailing')) { $mail['transport']['host'] = Setting::Get('hostname', 'mailing'); } if (Setting::Get('username', 'mailing')) { $mail['transport']['username'] = Setting::Get('username', 'mailing'); } if (Setting::Get('password', 'mailing')) { $mail['transport']['password'] = Setting::Get('password', 'mailing'); } if (Setting::Get('encryption', 'mailing')) { $mail['transport']['encryption'] = Setting::Get('encryption', 'mailing'); } if (Setting::Get('port', 'mailing')) { $mail['transport']['port'] = Setting::Get('port', 'mailing'); } /* if (Setting::Get('allowSelfSignedCerts', 'mailing')) { $mail['transport']['ssl']['allow_self_signed'] = true; $mail['transport']['ssl']['verify_peer'] = false; } */ } elseif (Setting::Get('transportType', 'mailing') == 'php') { $mail['transport']['class'] = 'Swift_MailTransport'; } else { $mail['useFileTransport'] = true; } $config['components']['mailer'] = $mail; $config = ArrayHelper::merge($config, Theme::getThemeConfig(Setting::Get('theme'))); $config['params']['config_created_at'] = time(); foreach (Setting::find()->all() as $setting) { self::setSettingValue($config['params'], $setting); } self::save($config); }