Rewrite installer without 3rd party installer lib.
This commit is contained in:
50
modules/Installer/Services/DatabaseService.php
Normal file
50
modules/Installer/Services/DatabaseService.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Installer\Services;
|
||||
|
||||
use Log;
|
||||
use PDO;
|
||||
|
||||
class DatabaseService {
|
||||
|
||||
/**
|
||||
* Check the PHP version that it meets the minimum requirement
|
||||
* @throws \PDOException
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkDbConnection($type, $host, $port, $name, $user, $pass)
|
||||
{
|
||||
Log::info('Testing Connection: '.$type.'::'.$user.':'.$pass.'@'.$host.':'.$port.';'.$name);
|
||||
|
||||
if($type === 'mysql') {
|
||||
$dsn = "mysql:host=$host;port=$port;dbname=$name";
|
||||
Log::info('Connection string: '. $dsn);
|
||||
try {
|
||||
$conn = new PDO($dsn, $user, $pass);
|
||||
} catch (\PDOException $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
// Needs testing
|
||||
elseif ($type === 'postgres') {
|
||||
$dsn = "pgsql:host=$host;port=$port;dbname=$name";
|
||||
try {
|
||||
$conn = new PDO($dsn, $user, $pass);
|
||||
} catch (\PDOException $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the database by running the migration commands
|
||||
*/
|
||||
public function setupDB()
|
||||
{
|
||||
\Artisan::call('database:create');
|
||||
\Artisan::call('migrate:refresh');
|
||||
}
|
||||
}
|
||||
52
modules/Installer/Services/EnvironmentService.php
Normal file
52
modules/Installer/Services/EnvironmentService.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Installer\Services;
|
||||
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Log;
|
||||
use PDO;
|
||||
|
||||
class EnvironmentService
|
||||
{
|
||||
|
||||
/**
|
||||
* Check the PHP version that it meets the minimum requirement
|
||||
* @return boolean
|
||||
*/
|
||||
public function createEnvFile($type, $host, $port, $name, $user, $pass)
|
||||
{
|
||||
$env_opts = [
|
||||
'db_conn' => $type,
|
||||
'db_host' => $host,
|
||||
'db_port' => $port,
|
||||
'db_name' => $name,
|
||||
'db_user' => $user,
|
||||
'db_pass' => $pass,
|
||||
];
|
||||
|
||||
$env_opts['app_key'] = base64_encode(Encrypter::generateKey(config('app.cipher')));
|
||||
|
||||
$this->writeEnvFile($env_opts);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the template file name and write it out
|
||||
*/
|
||||
protected function writeEnvFile($env_opts)
|
||||
{
|
||||
$app = app();
|
||||
$env_file = $app->environmentFilePath();
|
||||
|
||||
# TODO: Remove this post-testing
|
||||
$env_file .= '.generated';
|
||||
|
||||
$env_contents = view('installer::stubs/env', $env_opts);
|
||||
Log::info($env_contents);
|
||||
|
||||
$fp = fopen($env_file, 'w');
|
||||
fwrite($fp, $env_contents);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
}
|
||||
43
modules/Installer/Services/RequirementsService.php
Normal file
43
modules/Installer/Services/RequirementsService.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Installer\Services;
|
||||
|
||||
|
||||
class RequirementsService {
|
||||
|
||||
/**
|
||||
* Check the PHP version that it meets the minimum requirement
|
||||
* @return array
|
||||
*/
|
||||
public function checkPHPVersion(): array
|
||||
{
|
||||
$passed = false;
|
||||
if(version_compare(PHP_VERSION, config('installer.php.version')) >= 0) {
|
||||
$passed = true;
|
||||
}
|
||||
|
||||
return ['version' => PHP_VERSION, 'passed' => $passed];
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the minimal extensions required are loaded
|
||||
* @return array
|
||||
*/
|
||||
public function checkExtensions(): array
|
||||
{
|
||||
$extensions = [];
|
||||
foreach(config('installer.extensions') as $ext) {
|
||||
$pass = true;
|
||||
if(!extension_loaded($ext)) {
|
||||
$pass = false;
|
||||
}
|
||||
|
||||
$extensions[] = [
|
||||
'ext' => $ext,
|
||||
'passed' => $pass,
|
||||
];
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user