#355 Calculate distance button (#366)

* #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:
Nabeel S
2019-08-26 12:32:46 -04:00
committed by GitHub
parent 25999d55a3
commit bbec276da8
57 changed files with 9819 additions and 7522 deletions

View File

@@ -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.')');
}
}
}

View File

@@ -10,21 +10,24 @@ class DatabaseService extends Service
{
/**
* Check the PHP version that it meets the minimum requirement
*
* @param $driver
* @param $host
* @param $port
* @param $name
* @param $user
* @param $pass
* @return boolean
*
* @return bool
*/
public function checkDbConnection($driver, $host, $port, $name, $user, $pass)
{
Log::info('Testing Connection: '.$driver.'::'.$user.':<hidden>@'.$host.':'.$port.';'.$name);
if($driver === 'mysql') {
if ($driver === 'mysql') {
$dsn = "mysql:host=$host;port=$port;dbname=$name";
Log::info('Connection string: '. $dsn);
Log::info('Connection string: '.$dsn);
try {
$conn = new PDO($dsn, $user, $pass);
} catch (\PDOException $e) {
@@ -35,6 +38,7 @@ class DatabaseService extends Service
// TODO: Needs testing
elseif ($driver === 'postgres') {
$dsn = "pgsql:host=$host;port=$port;dbname=$name";
try {
$conn = new PDO($dsn, $user, $pass);
} catch (\PDOException $e) {
@@ -54,7 +58,7 @@ class DatabaseService extends Service
{
$output = '';
if(config('database.default') === 'sqlite') {
if (config('database.default') === 'sqlite') {
\Artisan::call('database:create');
$output .= \Artisan::output();
}

View File

@@ -2,20 +2,19 @@
namespace Modules\Installer\Services;
use App\Contracts\Service;
class RequirementsService extends Service
{
/**
* 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) {
if (version_compare(PHP_VERSION, config('installer.php.version')) >= 0) {
$passed = true;
}
@@ -24,19 +23,20 @@ class RequirementsService extends Service
/**
* Make sure the minimal extensions required are loaded
*
* @return array
*/
public function checkExtensions(): array
{
$extensions = [];
foreach(config('installer.extensions') as $ext) {
foreach (config('installer.extensions') as $ext) {
$pass = true;
if(!\extension_loaded($ext)) {
if (!\extension_loaded($ext)) {
$pass = false;
}
$extensions[] = [
'ext' => $ext,
'ext' => $ext,
'passed' => $pass,
];
}
@@ -47,6 +47,7 @@ class RequirementsService extends Service
/**
* Check the permissions for the directories specified
* Make sure they exist and are writable
*
* @return array
*/
public function checkPermissions(): array
@@ -54,21 +55,20 @@ class RequirementsService extends Service
clearstatcache();
$directories = [];
foreach (config('installer.permissions') as $dir)
{
foreach (config('installer.permissions') as $dir) {
$pass = true;
$path = base_path($dir);
if(!file_exists($path)) {
if (!file_exists($path)) {
$pass = false;
}
if(!is_writable($path)) {
if (!is_writable($path)) {
$pass = false;
}
$directories[] = [
'dir' => $dir,
'dir' => $dir,
'passed' => $pass,
];
}