mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 13:51:42 +01:00
Improve debug mode handling v2 (#7167)
* Improve Debug Mode Handling * Improve Debug Mode Handling * Improve Debug Mode Handling * Improve Debug Mode Handling * Improve Debug Mode Handling * Autocommit PHP CS Fixer * Improve Debug Mode Handling * Autocommit PHP CS Fixer * Improve Debug Mode Handling * Improve Debug Mode Handling * Improve Debug Mode Handling * Improve Debug Mode Handling * Autocommit PHP CS Fixer * Updated Composer.locK * Improve Debug Mode Handling * Improve Debug Mode Handling --------- Co-authored-by: gevorgmansuryan <gevorgmansuryan@users.noreply.github.com> Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com> Co-authored-by: Lucas Bartholemy <lucas@bartholemy.com>
This commit is contained in:
parent
ee6eb65425
commit
1f8a53f6bb
5
.env.example
Normal file
5
.env.example
Normal file
@ -0,0 +1,5 @@
|
||||
# Warning: This file may contain sensitive information. Make sure that this file is not
|
||||
# distributed via the web server and does not have file permissions that are too open.
|
||||
|
||||
HUMHUB_DEBUG=1
|
||||
HUMHUB_CONFIG.PARAMS.MODULE_AUTOLOAD_PATHS=
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@ assets/*
|
||||
!assets/.gitignore
|
||||
|
||||
protected/runtime/*
|
||||
.env
|
||||
!protected/runtime/.gitignore
|
||||
|
||||
node_modules
|
||||
|
@ -25,6 +25,7 @@ HumHub Changelog
|
||||
- Fix #7176: Fix of broken tests related to `Create Private Spaces` and `Create Public Spaces` Groups permissions
|
||||
- Enh #7198: Increase default Uplaod Max File Size to 64mb
|
||||
- Fix #7197: Increased version of `PHPOffice/PHPSpreadsheet` to v2.2+
|
||||
- Enh #7167: Disable DEBUG mode automatically after successful humhub installation. Add `.env` support
|
||||
- Enh #7202: Increased minimum PHP version to 8.1
|
||||
|
||||
1.16.2 (Unreleased)
|
||||
|
@ -70,6 +70,7 @@
|
||||
"symfony/sendgrid-mailer": "^5.4",
|
||||
"symfony/sendinblue-mailer": "^5.4",
|
||||
"twig/twig": "^3.4.1",
|
||||
"vlucas/phpdotenv": "^5.6",
|
||||
"web-token/jwt-checker": ">=1.0 <3.0",
|
||||
"web-token/jwt-signature": ">=1.0 <3.0",
|
||||
"web-token/jwt-signature-algorithm-ecdsa": ">=1.0 <3.0",
|
||||
|
1247
composer.lock
generated
1247
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -27,10 +27,14 @@ defined('YII_ENV_TEST') or define('YII_ENV_TEST', true);
|
||||
require(__DIR__ . '/protected/vendor/autoload.php');
|
||||
require(__DIR__ . '/protected/vendor/yiisoft/yii2/Yii.php');
|
||||
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__, '.env');
|
||||
$dotenv->safeLoad();
|
||||
|
||||
$config = yii\helpers\ArrayHelper::merge(
|
||||
// add more configurations here
|
||||
(is_readable(__DIR__ . '/protected/humhub/tests/codeception/config/dynamic.php')) ? require(__DIR__ . '/protected/humhub/tests/codeception/config/dynamic.php') : [],
|
||||
require(__DIR__ . '/protected/humhub/tests/codeception/config/acceptance.php')
|
||||
require(__DIR__ . '/protected/humhub/tests/codeception/config/acceptance.php'),
|
||||
humhub\helpers\EnvHelper::toConfig($_ENV),
|
||||
);
|
||||
|
||||
require_once './protected/vendor/codeception/codeception/autoload.php';
|
||||
|
29
index.php
29
index.php
@ -6,28 +6,33 @@
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
// comment out the following two lines when deployed to production
|
||||
use humhub\helpers\DatabaseHelper;
|
||||
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||
defined('YII_ENV') or define('YII_ENV', 'dev');
|
||||
|
||||
require(__DIR__ . '/protected/vendor/autoload.php');
|
||||
require(__DIR__ . '/protected/vendor/yiisoft/yii2/Yii.php');
|
||||
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__, '.env');
|
||||
$dotenv->safeLoad();
|
||||
|
||||
$dynamicConfig = (is_readable(__DIR__ . '/protected/config/dynamic.php')) ? require(__DIR__ . '/protected/config/dynamic.php') : [];
|
||||
$debug = !!($_ENV['HUMHUB_DEBUG'] ?? false) || !$dynamicConfig['params']['installed'];
|
||||
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', $debug);
|
||||
defined('YII_ENV') or define('YII_ENV', $debug ? 'dev' : 'prod');
|
||||
|
||||
|
||||
require(__DIR__ . '/protected/vendor/yiisoft/yii2/Yii.php');
|
||||
|
||||
$config = yii\helpers\ArrayHelper::merge(
|
||||
require(__DIR__ . '/protected/humhub/config/common.php'),
|
||||
require(__DIR__ . '/protected/humhub/config/web.php'),
|
||||
(is_readable(__DIR__ . '/protected/config/dynamic.php')) ? require(__DIR__ . '/protected/config/dynamic.php') : [],
|
||||
require(__DIR__ . '/protected/config/common.php'),
|
||||
require(__DIR__ . '/protected/config/web.php')
|
||||
require(__DIR__ . '/protected/config/web.php'),
|
||||
$dynamicConfig,
|
||||
humhub\helpers\EnvHelper::toConfig($_ENV),
|
||||
);
|
||||
|
||||
try {
|
||||
(new humhub\components\Application($config))->run();
|
||||
} catch (\Throwable $ex) {
|
||||
if (null === DatabaseHelper::handleConnectionErrors($ex)) {
|
||||
throw $ex;
|
||||
} catch (Throwable $e) {
|
||||
if (null === humhub\helpers\DatabaseHelper::handleConnectionErrors($e)) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
@ -8,14 +8,14 @@
|
||||
|
||||
namespace humhub\components;
|
||||
|
||||
use humhub\libs\BaseSettingsManager;
|
||||
use humhub\modules\content\components\ContentContainerActiveRecord;
|
||||
use humhub\modules\content\components\ContentContainerController;
|
||||
use humhub\modules\content\components\ContentContainerSettingsManager;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\user\models\User;
|
||||
use Throwable;
|
||||
use Yii;
|
||||
use humhub\libs\BaseSettingsManager;
|
||||
use humhub\modules\content\components\ContentContainerActiveRecord;
|
||||
use humhub\modules\content\components\ContentContainerSettingsManager;
|
||||
|
||||
/**
|
||||
* SettingsManager application component
|
||||
|
59
protected/humhub/helpers/EnvHelper.php
Normal file
59
protected/humhub/helpers/EnvHelper.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\helpers;
|
||||
|
||||
use yii\base\InvalidArgumentException;
|
||||
use yii\helpers\Inflector;
|
||||
use yii\helpers\Json;
|
||||
use yii\helpers\StringHelper;
|
||||
|
||||
class EnvHelper
|
||||
{
|
||||
private const FIXED_SETTING_PREFIX = 'HUMHUB_FIXED_SETTINGS.';
|
||||
private const MAIN_PREFIX = 'HUMHUB_CONFIG.';
|
||||
private const FIXED_SETTINGS_PATH = ['params', 'fixed-settings'];
|
||||
|
||||
public static function toConfig(?array $env = []): array
|
||||
{
|
||||
$config = [];
|
||||
|
||||
foreach ($env as $key => $value) {
|
||||
try {
|
||||
$value = Json::decode($value);
|
||||
} catch (InvalidArgumentException) {
|
||||
}
|
||||
|
||||
if (StringHelper::startsWith($key, self::FIXED_SETTING_PREFIX)) {
|
||||
ArrayHelper::setValue(
|
||||
$config,
|
||||
[
|
||||
...self::FIXED_SETTINGS_PATH,
|
||||
...self::keyToPath(str_replace(self::FIXED_SETTING_PREFIX, '', $key)),
|
||||
],
|
||||
$value,
|
||||
);
|
||||
}
|
||||
if (StringHelper::startsWith($key, self::MAIN_PREFIX)) {
|
||||
ArrayHelper::setValue(
|
||||
$config,
|
||||
[
|
||||
...self::keyToPath(str_replace(self::MAIN_PREFIX, '', $key)),
|
||||
],
|
||||
$value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
private static function keyToPath(string $key): array
|
||||
{
|
||||
return ArrayHelper::getColumn(
|
||||
explode('.', $key),
|
||||
function ($path) {
|
||||
return Inflector::variablize(strtolower($path));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
78
protected/humhub/modules/web/tests/codeception/unit/env/ConfigTest.php
vendored
Normal file
78
protected/humhub/modules/web/tests/codeception/unit/env/ConfigTest.php
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\unit\modules\web\env;
|
||||
|
||||
use humhub\helpers\EnvHelper;
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
|
||||
class ConfigTest extends HumHubDbTestCase
|
||||
{
|
||||
public function testDebugIgnored()
|
||||
{
|
||||
$ENV = [
|
||||
'HUMHUB_DEBUG' => 1,
|
||||
];
|
||||
|
||||
$this->assertEmpty(EnvHelper::toConfig($ENV));
|
||||
}
|
||||
|
||||
public function testFixedSettings()
|
||||
{
|
||||
$ENV = [
|
||||
'HUMHUB_FIXED_SETTINGS.BASE.MAILER.DSN' => 'smtp://...',
|
||||
'HUMHUB_FIXED_SETTINGS.BASE.MAILER.TRANSPORT_TYPE' => 'php',
|
||||
'HUMHUB_FIXED_SETTINGS.BASE.MAILER.SYSTEM_EMAIL_ADDRESS' => 'noreply@humhub.com',
|
||||
];
|
||||
|
||||
$config = [
|
||||
'params' => [
|
||||
'fixed-settings' => [
|
||||
'base' => [
|
||||
'mailer' => [
|
||||
'dsn' => 'smtp://...',
|
||||
'transportType' => 'php',
|
||||
'systemEmailAddress' => 'noreply@humhub.com',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($config, EnvHelper::toConfig($ENV));
|
||||
}
|
||||
|
||||
public function testArrayConfig()
|
||||
{
|
||||
$ENV = [
|
||||
'HUMHUB_CONFIG.PARAMS.MODULE_AUTOLOAD_PATHS' => ["/app/modules/humhub","/app/modules/humhub-contrib"],
|
||||
];
|
||||
|
||||
$config = [
|
||||
'params' => [
|
||||
'moduleAutoloadPaths' => [
|
||||
'/app/modules/humhub',
|
||||
'/app/modules/humhub-contrib',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($config, EnvHelper::toConfig($ENV));
|
||||
}
|
||||
|
||||
public function testJsonConfig()
|
||||
{
|
||||
$ENV = [
|
||||
'HUMHUB_CONFIG.COMPONENTS.DB' => '{"on afterOpen":["humhub\\\libs\\\Helpers","SqlMode"]}',
|
||||
];
|
||||
|
||||
$config = [
|
||||
'components' => [
|
||||
'db' => [
|
||||
'on afterOpen' => ['humhub\libs\Helpers', 'SqlMode'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($config, EnvHelper::toConfig($ENV));
|
||||
}
|
||||
}
|
@ -8,30 +8,37 @@
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
use humhub\helpers\DatabaseHelper;
|
||||
require(__DIR__ . '/vendor/autoload.php');
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../', '.env');
|
||||
$dotenv->safeLoad();
|
||||
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||
$dynamicConfig = (is_readable(__DIR__ . '/config/dynamic.php')) ? require(__DIR__ . '/config/dynamic.php') : [];
|
||||
$debug = !!($_ENV['HUMHUB_DEBUG'] ?? false) || !$dynamicConfig['params']['installed'];
|
||||
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', $debug);
|
||||
|
||||
// fcgi doesn't have STDIN and STDOUT defined by default
|
||||
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
|
||||
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
|
||||
|
||||
require(__DIR__ . '/vendor/autoload.php');
|
||||
|
||||
|
||||
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
|
||||
|
||||
$config = yii\helpers\ArrayHelper::merge(
|
||||
require(__DIR__ . '/humhub/config/common.php'),
|
||||
require(__DIR__ . '/humhub/config/console.php'),
|
||||
(is_readable(__DIR__ . '/config/dynamic.php')) ? require(__DIR__ . '/config/dynamic.php') : [],
|
||||
$dynamicConfig,
|
||||
require(__DIR__ . '/config/common.php'),
|
||||
require(__DIR__ . '/config/console.php')
|
||||
require(__DIR__ . '/config/console.php'),
|
||||
humhub\helpers\EnvHelper::toConfig($_ENV),
|
||||
);
|
||||
|
||||
try {
|
||||
$exitCode = (new humhub\components\console\Application($config))->run();
|
||||
exit($exitCode);
|
||||
} catch (\Throwable $ex) {
|
||||
if (null === DatabaseHelper::handleConnectionErrors($ex)) {
|
||||
throw $ex;
|
||||
} catch (\Throwable $e) {
|
||||
if (null === humhub\helpers\DatabaseHelper::handleConnectionErrors($e)) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user