Commit 2612f958fae9c77121776960c3c44fd23b7885b5

Authored by Yarik
1 parent 2c7856ad

Initializer completed

Initializer.php
... ... @@ -31,7 +31,9 @@
31 31 $instance->defineEnvironment();
32 32 $instance->startInitialization();
33 33 if ($instance->askInitDb()) {
34   - $instance->defineDb();
  34 + do {
  35 + $instance->defineDb();
  36 + } while (!$instance->databaseCheck());
35 37 $instance->migrate();
36 38 $instance->createUser();
37 39 $instance->congratulate();
... ... @@ -73,6 +75,7 @@
73 75 * * --user - Whether to create user, default to yes, set no to skip creation
74 76 * * --defaultuser - Whether to use default user creation
75 77 * * --o - Webpage to open after intallaction process
  78 + * * --fun - Run HOLLYWOOD BABY!!!
76 79 *
77 80 * @see Initializer::getInstance()
78 81 */
... ... @@ -1041,8 +1044,44 @@
1041 1044 shell_exec("explorer '{$url}'");
1042 1045 } else {
1043 1046 shell_exec("sensible-browser {$url}");
  1047 + $params = $this->getParams();
  1048 + if (isset( $params[ 'fun' ] )) {
  1049 + echo shell_exec("hollywood");
  1050 + }
1044 1051 }
1045 1052 }
1046 1053 }
  1054 +
  1055 + /**
  1056 + * Check if database connection could be established
  1057 + *
  1058 + * @return bool
  1059 + * @throws \Exception
  1060 + */
  1061 + private function databaseCheck(): bool
  1062 + {
  1063 + $params = $this->getParams();
  1064 + if (isset( $params[ 'checkdb' ] )) {
  1065 + $configPath = $this->environment[ 'setDbConnection' ];
  1066 + if (preg_match('/(.*)\/.*/', $configPath, $matches)) {
  1067 + $path = $matches[ 1 ];
  1068 + } else {
  1069 + $this->printError("Unknown error while trying to check connection");
  1070 + exit( 1 );
  1071 + }
  1072 + $filename = "db{$this->db['dbtype']}.php";
  1073 + $fullpath = "{$path}/{$filename}";
  1074 + exec("php yii check/connection {$fullpath}", $output, $return);
  1075 + if ($return > 0) {
  1076 + if (isset( $params[ 'dbinit' ] )) {
  1077 + throw new Exception("Couldn't connect to the database");
  1078 + }
  1079 + echo $this->printError("Database unavailable. Please choose another database!");
  1080 + return false;
  1081 + }
  1082 + }
  1083 + echo $this->formatMessage(" Database connection successful!", [ 'fg-green' ]) . "\n";
  1084 + return true;
  1085 + }
1047 1086 }
1048 1087  
1049 1088 \ No newline at end of file
... ...
console/controllers/CheckController.php 0 → 100644
  1 +<?php
  2 + namespace console\controllers;
  3 +
  4 + use yii\console\Controller;
  5 + use yii\db\Connection;
  6 + use yii\db\Exception;
  7 + use yii\helpers\ArrayHelper;
  8 +
  9 + /**
  10 + * Class CheckController
  11 + *
  12 + * @package console\controllers
  13 + */
  14 + class CheckController extends Controller
  15 + {
  16 + public function actionConnection($path)
  17 + {
  18 + $connection = \Yii::createObject(require( $path ));
  19 + try {
  20 + $connection->open();
  21 + } catch (Exception $exception) {
  22 + exit( 1 );
  23 + }
  24 + exit( 0 );
  25 + }
  26 + }
0 27 \ No newline at end of file
... ...
frontend/views/layouts/main.php
... ... @@ -4,7 +4,7 @@
4 4 /* @var $content string */
5 5  
6 6 use artbox\core\components\SeoComponent;
7   - use artbox\core\models\Settings;
  7 + use common\models\Settings;
8 8 use artbox\core\models\User;
9 9 use yii\helpers\Html;
10 10 use yii\bootstrap\Nav;
... ... @@ -31,7 +31,7 @@
31 31 <meta charset="<?= Yii::$app->charset ?>">
32 32 <meta name="viewport" content="width=device-width, initial-scale=1">
33 33 <?= Html::csrfMetaTags() ?>
34   - <title><?= Html::encode($seo->title) ?></title>
  34 + <title><?= Html::encode($seo->title) ?></title>
35 35 <?php $this->head() ?>
36 36 </head>
37 37 <body>
... ...
... ... @@ -14,5 +14,4 @@
14 14 if (!extension_loaded('openssl')) {
15 15 die( 'The OpenSSL PHP extension is required by Yii2.' );
16 16 }
17   -
18 17 Initializer::initialize();
... ...