mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 21:58:17 +01:00
.env Auto Install (#7239)
* .env Auto Install * Autocommit PHP CS Fixer * .env Auto Install * .env Auto Install * Autocommit PHP CS Fixer * .env Auto Install --------- Co-authored-by: gevorgmansuryan <gevorgmansuryan@users.noreply.github.com>
This commit is contained in:
parent
366823d3b1
commit
21c2b0973d
@ -41,6 +41,7 @@ HumHub Changelog
|
||||
- Enh #7233: Mobile view: enlarge images in gallery preview of entries for the wall stream
|
||||
- Enh #7237: Changed PoweredBy URL
|
||||
- Enh #7238: Fixed PHP warning related to `.env`
|
||||
- Enh #7239: Added option `\humhub\modules\installer\Module::$enableAutoSetup` to enable/disable auto setup of humhub installation
|
||||
- Enh #7240: Fixed maximum file size setting in initialization
|
||||
|
||||
1.16.3 (Unreleased)
|
||||
|
@ -204,4 +204,9 @@ class DynamicConfig extends BaseObject
|
||||
{
|
||||
return Yii::getAlias(Yii::$app->params['dynamicConfigFile']);
|
||||
}
|
||||
|
||||
public static function exist()
|
||||
{
|
||||
return file_exists(self::getConfigFilePath());
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@
|
||||
namespace humhub\modules\installer;
|
||||
|
||||
use Exception;
|
||||
use humhub\libs\DynamicConfig;
|
||||
use Yii;
|
||||
use yii\console\Application;
|
||||
use yii\helpers\Url;
|
||||
@ -32,6 +31,11 @@ class Module extends \humhub\components\Module
|
||||
*/
|
||||
public $controllerNamespace = 'humhub\modules\installer\controllers';
|
||||
|
||||
/**
|
||||
* @var bool enable auto setup
|
||||
*/
|
||||
public bool $enableAutoSetup = false;
|
||||
|
||||
/**
|
||||
* Array of config steps
|
||||
*
|
||||
@ -126,7 +130,6 @@ class Module extends \humhub\components\Module
|
||||
|
||||
protected function initConfigSteps()
|
||||
{
|
||||
|
||||
/**
|
||||
* Step: Basic Configuration
|
||||
*/
|
||||
|
@ -553,7 +553,7 @@ class ConfigController extends Controller
|
||||
Yii::$app->settings->set('timeZone', Yii::$app->timeZone);
|
||||
|
||||
// Set to installed
|
||||
$this->module->setInstalled();
|
||||
Yii::$app->setInstalled();
|
||||
|
||||
try {
|
||||
Yii::$app->user->logout();
|
||||
|
@ -10,6 +10,7 @@ namespace humhub\modules\installer\controllers;
|
||||
|
||||
use humhub\components\access\ControllerAccess;
|
||||
use humhub\components\Controller;
|
||||
use humhub\libs\DynamicConfig;
|
||||
|
||||
/**
|
||||
* Index Controller shows a simple welcome page.
|
||||
@ -38,7 +39,7 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function actionGo()
|
||||
{
|
||||
if ($this->module->checkDBConnection()) {
|
||||
if (DynamicConfig::exist() && $this->module->checkDBConnection()) {
|
||||
return $this->redirect(['setup/finalize']);
|
||||
} else {
|
||||
return $this->redirect(['setup/prerequisites']);
|
||||
|
@ -48,6 +48,11 @@ class SetupController extends Controller
|
||||
{
|
||||
Yii::$app->cache->flush();
|
||||
|
||||
if ($this->module->enableAutoSetup) {
|
||||
return $this->redirect(['database']);
|
||||
|
||||
}
|
||||
|
||||
return $this->render('prerequisites', ['hasError' => PrerequisitesList::hasError()]);
|
||||
}
|
||||
|
||||
@ -80,31 +85,53 @@ class SetupController extends Controller
|
||||
$model->password = self::PASSWORD_PLACEHOLDER;
|
||||
}
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
||||
$connectionString = 'mysql:host=' . $model->hostname;
|
||||
if ($model->port !== '') {
|
||||
$connectionString .= ';port=' . $model->port;
|
||||
}
|
||||
if (!$model->create) {
|
||||
$connectionString .= ';dbname=' . $model->database;
|
||||
}
|
||||
if (($modelLoaded = $model->load(Yii::$app->request->post()) && $model->validate()) || $this->module->enableAutoSetup) {
|
||||
if ($modelLoaded) {
|
||||
$connectionString = 'mysql:host=' . $model->hostname;
|
||||
if ($model->port !== '') {
|
||||
$connectionString .= ';port=' . $model->port;
|
||||
}
|
||||
if (!$model->create) {
|
||||
$connectionString .= ';dbname=' . $model->database;
|
||||
}
|
||||
$username = $model->username;
|
||||
$password = $model->password;
|
||||
if ($password == self::PASSWORD_PLACEHOLDER) {
|
||||
$password = $config['components']['db']['password'];
|
||||
}
|
||||
} elseif ($this->module->enableAutoSetup) {
|
||||
$username = $model->username = Yii::$app->db->username;
|
||||
$password = Yii::$app->db->password;
|
||||
$connectionString = Yii::$app->db->dsn;
|
||||
$model->create = 1;
|
||||
|
||||
$password = $model->password;
|
||||
if ($password == self::PASSWORD_PLACEHOLDER) {
|
||||
$password = $config['components']['db']['password'];
|
||||
if (preg_match('/host=([^;]+)/', $connectionString ?: '', $matches)) {
|
||||
$model->hostname = $matches[1];
|
||||
}
|
||||
if (preg_match('/port=([^;]+)/', $connectionString ?: '', $matches)) {
|
||||
$model->port = $matches[1];
|
||||
}
|
||||
if (preg_match('/dbname=([^;]+)/', $connectionString ?: '', $matches)) {
|
||||
$model->database = $matches[1];
|
||||
}
|
||||
|
||||
$connectionString = preg_replace('/;dbname=[^;]*/', '', $connectionString);
|
||||
} else {
|
||||
$username = '';
|
||||
$password = '';
|
||||
$connectionString = '';
|
||||
}
|
||||
|
||||
// Create Test DB Connection
|
||||
$dbConfig = [
|
||||
'class' => 'yii\db\Connection',
|
||||
'dsn' => $connectionString,
|
||||
'username' => $model->username,
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'charset' => 'utf8',
|
||||
];
|
||||
|
||||
try {
|
||||
|
||||
/** @var yii\db\Connection $temporaryConnection */
|
||||
$temporaryConnection = Yii::createObject($dbConfig);
|
||||
|
||||
@ -153,6 +180,10 @@ class SetupController extends Controller
|
||||
*/
|
||||
public function actionCron()
|
||||
{
|
||||
if ($this->module->enableAutoSetup) {
|
||||
return $this->redirect(['finalize']);
|
||||
}
|
||||
|
||||
return $this->render('cron', []);
|
||||
}
|
||||
|
||||
@ -161,6 +192,10 @@ class SetupController extends Controller
|
||||
*/
|
||||
public function actionPrettyUrls()
|
||||
{
|
||||
if ($this->module->enableAutoSetup) {
|
||||
return $this->redirect(['finalize']);
|
||||
}
|
||||
|
||||
return $this->render('pretty-urls');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user