* #355 Calculate distance button in add/edit Flight page * Styling * Move add/edit flight logic out of controller and into service layer * Styling * Formatting * Run styleci against modules dir * Styleci config * Style fixes in /modules
This commit is contained in:
@@ -15,15 +15,17 @@ use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
|
||||
/**
|
||||
* Class ConfigService
|
||||
* @package Modules\Installer\Services
|
||||
*/
|
||||
class ConfigService extends Service
|
||||
{
|
||||
/**
|
||||
* Create the .env file
|
||||
*
|
||||
* @param $attrs
|
||||
* @return boolean
|
||||
*
|
||||
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function createConfigFiles($attrs): bool
|
||||
{
|
||||
@@ -56,7 +58,9 @@ class ConfigService extends Service
|
||||
|
||||
/**
|
||||
* Update the environment file and update certain keys/values
|
||||
*
|
||||
* @param array $kvp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateKeysInEnv(array $kvp)
|
||||
@@ -64,25 +68,24 @@ class ConfigService extends Service
|
||||
$app = app();
|
||||
|
||||
$env_file = file_get_contents($app->environmentFilePath());
|
||||
foreach($kvp as $key => $value) {
|
||||
|
||||
foreach ($kvp as $key => $value) {
|
||||
$key = strtoupper($key);
|
||||
|
||||
# cast for any boolean values
|
||||
if(is_bool($value)) {
|
||||
// cast for any boolean values
|
||||
if (is_bool($value)) {
|
||||
$value = $value === true ? 'true' : 'false';
|
||||
}
|
||||
|
||||
# surround by quotes if there are any spaces in the value
|
||||
if(strpos($value, ' ') !== false) {
|
||||
// surround by quotes if there are any spaces in the value
|
||||
if (strpos($value, ' ') !== false) {
|
||||
$value = '"'.$value.'"';
|
||||
}
|
||||
|
||||
Log::info('Replacing "' . $key . '" with ' . $value);
|
||||
Log::info('Replacing "'.$key.'" with '.$value);
|
||||
|
||||
$env_file = preg_replace(
|
||||
'/^' . $key . '(.*)?/m',
|
||||
$key . '=' . $value,
|
||||
'/^'.$key.'(.*)?/m',
|
||||
$key.'='.$value,
|
||||
$env_file
|
||||
);
|
||||
}
|
||||
@@ -92,6 +95,7 @@ class ConfigService extends Service
|
||||
|
||||
/**
|
||||
* Generate a fresh new APP_KEY
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function createAppKey(): string
|
||||
@@ -102,26 +106,28 @@ class ConfigService extends Service
|
||||
/**
|
||||
* Change a few options within the PDO driver, depending on the version
|
||||
* of mysql/maria, etc used. ATM, only make a change for MariaDB
|
||||
*
|
||||
* @param $opts
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function determinePdoOptions($opts)
|
||||
{
|
||||
if($opts['DB_CONN'] !== 'mysql') {
|
||||
if ($opts['DB_CONN'] !== 'mysql') {
|
||||
return $opts;
|
||||
}
|
||||
|
||||
$dsn = "mysql:host=$opts[DB_HOST];port=$opts[DB_PORT];";
|
||||
Log::info('Connection string: ' . $dsn);
|
||||
Log::info('Connection string: '.$dsn);
|
||||
|
||||
$conn = new PDO($dsn, $opts['DB_USER'], $opts['DB_PASS']);
|
||||
$version = strtolower($conn->getAttribute(PDO::ATTR_SERVER_VERSION));
|
||||
Log::info('Detected DB Version: '.$version);
|
||||
|
||||
# If it's mariadb, enable the emulation for prepared statements
|
||||
# seems to be throwing a problem on 000webhost
|
||||
# https://github.com/nabeelio/phpvms/issues/132
|
||||
if(strpos($version, 'mariadb') !== false) {
|
||||
// If it's mariadb, enable the emulation for prepared statements
|
||||
// seems to be throwing a problem on 000webhost
|
||||
// https://github.com/nabeelio/phpvms/issues/132
|
||||
if (strpos($version, 'mariadb') !== false) {
|
||||
Log::info('Detected MariaDB, setting DB_EMULATE_PREPARES to true');
|
||||
$opts['DB_EMULATE_PREPARES'] = true;
|
||||
}
|
||||
@@ -131,7 +137,9 @@ class ConfigService extends Service
|
||||
|
||||
/**
|
||||
* Determine is APC is installed, if so, then use it as a cache driver
|
||||
*
|
||||
* @param $opts
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function configCacheDriver($opts)
|
||||
@@ -157,13 +165,15 @@ class ConfigService extends Service
|
||||
/**
|
||||
* Setup a queue driver that's not the default "sync"
|
||||
* driver, if a database is being used
|
||||
*
|
||||
* @param $opts
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function configQueueDriver($opts)
|
||||
{
|
||||
# If we're setting up a database, then also setup
|
||||
# the default queue driver to use the database
|
||||
// If we're setting up a database, then also setup
|
||||
// the default queue driver to use the database
|
||||
if ($opts['DB_CONN'] === 'mysql' || $opts['DB_CONN'] === 'postgres') {
|
||||
$opts['QUEUE_DRIVER'] = 'database';
|
||||
} else {
|
||||
@@ -189,7 +199,7 @@ class ConfigService extends Service
|
||||
}
|
||||
}
|
||||
|
||||
if(file_exists($config_file)) {
|
||||
if (file_exists($config_file)) {
|
||||
try {
|
||||
unlink($config_file);
|
||||
} catch (Exception $e) {
|
||||
@@ -200,7 +210,9 @@ class ConfigService extends Service
|
||||
|
||||
/**
|
||||
* Get the template file name and write it out
|
||||
*
|
||||
* @param $opts
|
||||
*
|
||||
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
||||
*/
|
||||
protected function writeConfigFiles($opts)
|
||||
@@ -209,23 +221,24 @@ class ConfigService extends Service
|
||||
|
||||
$env_file = App::environmentFilePath();
|
||||
|
||||
if(file_exists($env_file) && !is_writable($env_file)) {
|
||||
if (file_exists($env_file) && !is_writable($env_file)) {
|
||||
Log::error('Permissions on existing env.php is not writable');
|
||||
|
||||
throw new FileException('Can\'t write to the env.php file! Check the permissions');
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* First write out the env file
|
||||
*/
|
||||
try {
|
||||
$stub = new Stub('/env.stub', $opts);
|
||||
$stub->render();
|
||||
$stub->saveTo(App::environmentPath(), App::environmentFile());
|
||||
} catch(Exception $e) {
|
||||
throw new FileException('Couldn\'t write env.php. (' . $e . ')');
|
||||
} catch (Exception $e) {
|
||||
throw new FileException('Couldn\'t write env.php. ('.$e.')');
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Next write out the config file. If there's an error here,
|
||||
* then throw an exception but delete the env file first
|
||||
*/
|
||||
@@ -234,8 +247,9 @@ class ConfigService extends Service
|
||||
$stub->render();
|
||||
$stub->saveTo(App::environmentPath(), 'config.php');
|
||||
} catch (Exception $e) {
|
||||
unlink(App::environmentPath().'/'. App::environmentFile());
|
||||
throw new FileException('Couldn\'t write config.php. (' . $e . ')');
|
||||
unlink(App::environmentPath().'/'.App::environmentFile());
|
||||
|
||||
throw new FileException('Couldn\'t write config.php. ('.$e.')');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user