diff --git a/Initializer.php b/Initializer.php index 201c406..f79e6bd 100644 --- a/Initializer.php +++ b/Initializer.php @@ -31,7 +31,9 @@ $instance->defineEnvironment(); $instance->startInitialization(); if ($instance->askInitDb()) { - $instance->defineDb(); + do { + $instance->defineDb(); + } while (!$instance->databaseCheck()); $instance->migrate(); $instance->createUser(); $instance->congratulate(); @@ -73,6 +75,7 @@ * * --user - Whether to create user, default to yes, set no to skip creation * * --defaultuser - Whether to use default user creation * * --o - Webpage to open after intallaction process + * * --fun - Run HOLLYWOOD BABY!!! * * @see Initializer::getInstance() */ @@ -1041,8 +1044,44 @@ shell_exec("explorer '{$url}'"); } else { shell_exec("sensible-browser {$url}"); + $params = $this->getParams(); + if (isset( $params[ 'fun' ] )) { + echo shell_exec("hollywood"); + } } } } + + /** + * Check if database connection could be established + * + * @return bool + * @throws \Exception + */ + private function databaseCheck(): bool + { + $params = $this->getParams(); + if (isset( $params[ 'checkdb' ] )) { + $configPath = $this->environment[ 'setDbConnection' ]; + if (preg_match('/(.*)\/.*/', $configPath, $matches)) { + $path = $matches[ 1 ]; + } else { + $this->printError("Unknown error while trying to check connection"); + exit( 1 ); + } + $filename = "db{$this->db['dbtype']}.php"; + $fullpath = "{$path}/{$filename}"; + exec("php yii check/connection {$fullpath}", $output, $return); + if ($return > 0) { + if (isset( $params[ 'dbinit' ] )) { + throw new Exception("Couldn't connect to the database"); + } + echo $this->printError("Database unavailable. Please choose another database!"); + return false; + } + } + echo $this->formatMessage(" Database connection successful!", [ 'fg-green' ]) . "\n"; + return true; + } } \ No newline at end of file diff --git a/console/controllers/CheckController.php b/console/controllers/CheckController.php new file mode 100644 index 0000000..efd9c07 --- /dev/null +++ b/console/controllers/CheckController.php @@ -0,0 +1,26 @@ +open(); + } catch (Exception $exception) { + exit( 1 ); + } + exit( 0 ); + } + } \ No newline at end of file diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 7db21dd..70aada6 100644 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -4,7 +4,7 @@ /* @var $content string */ use artbox\core\components\SeoComponent; - use artbox\core\models\Settings; + use common\models\Settings; use artbox\core\models\User; use yii\helpers\Html; use yii\bootstrap\Nav; @@ -31,7 +31,7 @@ = Html::csrfMetaTags() ?> -