* #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:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Modules\Installer\Http\Controllers;
|
||||
|
||||
use App\Facades\Utils;
|
||||
use App\Contracts\Controller;
|
||||
use App\Facades\Utils;
|
||||
use App\Models\User;
|
||||
use App\Repositories\AirlineRepository;
|
||||
use App\Services\AnalyticsService;
|
||||
@@ -23,29 +23,29 @@ use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
|
||||
/**
|
||||
* Class InstallerController
|
||||
* @package Modules\Installer\Http\Controllers
|
||||
*/
|
||||
class InstallerController extends Controller
|
||||
{
|
||||
private $airlineRepo,
|
||||
$analyticsSvc,
|
||||
$dbSvc,
|
||||
$envSvc,
|
||||
$migrationSvc,
|
||||
$reqSvc,
|
||||
$seederSvc,
|
||||
$userService;
|
||||
private $airlineRepo;
|
||||
private $analyticsSvc;
|
||||
private $dbSvc;
|
||||
private $envSvc;
|
||||
private $migrationSvc;
|
||||
private $reqSvc;
|
||||
private $seederSvc;
|
||||
private $userService;
|
||||
|
||||
/**
|
||||
* InstallerController constructor.
|
||||
* @param AirlineRepository $airlineRepo
|
||||
* @param AnalyticsService $analyticsSvc
|
||||
* @param DatabaseService $dbService
|
||||
* @param ConfigService $envService
|
||||
* @param MigrationService $migrationSvc
|
||||
*
|
||||
* @param AirlineRepository $airlineRepo
|
||||
* @param AnalyticsService $analyticsSvc
|
||||
* @param DatabaseService $dbService
|
||||
* @param ConfigService $envService
|
||||
* @param MigrationService $migrationSvc
|
||||
* @param RequirementsService $reqSvc
|
||||
* @param SeederService $seederSvc
|
||||
* @param UserService $userService
|
||||
* @param SeederService $seederSvc
|
||||
* @param UserService $userService
|
||||
*/
|
||||
public function __construct(
|
||||
AirlineRepository $airlineRepo,
|
||||
@@ -66,12 +66,13 @@ class InstallerController extends Controller
|
||||
$this->seederSvc = $seederSvc;
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if(config('app.key') !== 'base64:zdgcDqu9PM8uGWCtMxd74ZqdGJIrnw812oRMmwDF6KY=') {
|
||||
if (config('app.key') !== 'base64:zdgcDqu9PM8uGWCtMxd74ZqdGJIrnw812oRMmwDF6KY=') {
|
||||
return view('installer::errors/already-installed');
|
||||
}
|
||||
|
||||
@@ -95,31 +96,33 @@ class InstallerController extends Controller
|
||||
*/
|
||||
public function dbtest(Request $request)
|
||||
{
|
||||
$status = 'success'; # success|warn|danger
|
||||
$status = 'success'; // success|warn|danger
|
||||
$message = 'Database connection looks good!';
|
||||
|
||||
try {
|
||||
$this->testDb($request);
|
||||
} catch (\Exception $e) {
|
||||
$status = 'danger';
|
||||
$message = 'Failed! ' . $e->getMessage();
|
||||
$message = 'Failed! '.$e->getMessage();
|
||||
}
|
||||
|
||||
return view('installer::flash/dbtest', [
|
||||
'status' => $status,
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any of the items has been marked as failed
|
||||
*
|
||||
* @param array $arr
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function allPassed(array $arr): bool
|
||||
{
|
||||
foreach($arr as $item) {
|
||||
if($item['passed'] === false) {
|
||||
foreach ($arr as $item) {
|
||||
if ($item['passed'] === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -140,21 +143,21 @@ class InstallerController extends Controller
|
||||
$extensions = $this->reqSvc->checkExtensions();
|
||||
$directories = $this->reqSvc->checkPermissions();
|
||||
|
||||
# Only pass if all the items in the ext and dirs are passed
|
||||
// Only pass if all the items in the ext and dirs are passed
|
||||
$statuses = [
|
||||
$php_version['passed'] === true,
|
||||
$this->allPassed($extensions) === true,
|
||||
$this->allPassed($directories) === true
|
||||
$this->allPassed($directories) === true,
|
||||
];
|
||||
|
||||
# Make sure there are no false values
|
||||
// Make sure there are no false values
|
||||
$passed = !\in_array(false, $statuses, true);
|
||||
|
||||
return view('installer::install/steps/step1-requirements', [
|
||||
'php' => $php_version,
|
||||
'extensions' => $extensions,
|
||||
'php' => $php_version,
|
||||
'extensions' => $extensions,
|
||||
'directories' => $directories,
|
||||
'passed' => $passed,
|
||||
'passed' => $passed,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -175,7 +178,9 @@ class InstallerController extends Controller
|
||||
|
||||
/**
|
||||
* Step 2a. Create the .env
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function envsetup(Request $request)
|
||||
@@ -209,14 +214,14 @@ class InstallerController extends Controller
|
||||
'DB_PREFIX' => $request->post('db_prefix'),
|
||||
];
|
||||
|
||||
/**
|
||||
/*
|
||||
* Create the config files and then redirect so that the
|
||||
* framework can pickup all those configs, etc, before we
|
||||
* setup the database and stuff
|
||||
*/
|
||||
try {
|
||||
$this->envSvc->createConfigFiles($attrs);
|
||||
} catch(FileException $e) {
|
||||
} catch (FileException $e) {
|
||||
Log::error('Config files failed to write');
|
||||
Log::error($e->getMessage());
|
||||
|
||||
@@ -224,14 +229,16 @@ class InstallerController extends Controller
|
||||
return redirect(route('installer.step2'))->withInput();
|
||||
}
|
||||
|
||||
# Needs to redirect so it can load the new .env
|
||||
// Needs to redirect so it can load the new .env
|
||||
Log::info('Redirecting to database setup');
|
||||
return redirect(route('installer.dbsetup'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 2b. Setup the database
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function dbsetup(Request $request)
|
||||
@@ -242,8 +249,8 @@ class InstallerController extends Controller
|
||||
$console_out .= $this->dbSvc->setupDB();
|
||||
$console_out .= $this->migrationSvc->runAllMigrations();
|
||||
$this->seederSvc->syncAllSeeds();
|
||||
} catch(QueryException $e) {
|
||||
Log::error('Error on db setup: ' . $e->getMessage());
|
||||
} catch (QueryException $e) {
|
||||
Log::error('Error on db setup: '.$e->getMessage());
|
||||
|
||||
$this->envSvc->removeConfigFiles();
|
||||
flash()->error($e->getMessage());
|
||||
@@ -253,7 +260,7 @@ class InstallerController extends Controller
|
||||
$console_out = trim($console_out);
|
||||
|
||||
return view('installer::install/steps/step2a-db_output', [
|
||||
'console_output' => $console_out
|
||||
'console_output' => $console_out,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -269,11 +276,14 @@ class InstallerController extends Controller
|
||||
|
||||
/**
|
||||
* Step 3 submit
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function usersetup(Request $request)
|
||||
{
|
||||
@@ -283,7 +293,7 @@ class InstallerController extends Controller
|
||||
'airline_country' => 'required',
|
||||
'name' => 'required',
|
||||
'email' => 'required|email|unique:users,email',
|
||||
'password' => 'required|confirmed'
|
||||
'password' => 'required|confirmed',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
@@ -295,7 +305,6 @@ class InstallerController extends Controller
|
||||
/**
|
||||
* Create the first airline
|
||||
*/
|
||||
|
||||
$attrs = [
|
||||
'icao' => $request->get('airline_icao'),
|
||||
'name' => $request->get('airline_name'),
|
||||
@@ -309,20 +318,19 @@ class InstallerController extends Controller
|
||||
* Ensure the seed data at least has one airport
|
||||
* KAUS, for giggles, though.
|
||||
*/
|
||||
|
||||
$attrs = [
|
||||
'name' => $request->get('name'),
|
||||
'email' => $request->get('email'),
|
||||
'api_key' => Utils::generateApiKey(),
|
||||
'airline_id' => $airline->id,
|
||||
'password' => Hash::make($request->get('password'))
|
||||
'name' => $request->get('name'),
|
||||
'email' => $request->get('email'),
|
||||
'api_key' => Utils::generateApiKey(),
|
||||
'airline_id' => $airline->id,
|
||||
'password' => Hash::make($request->get('password')),
|
||||
];
|
||||
|
||||
$user = User::create($attrs);
|
||||
$user = $this->userService->createUser($user, ['admin']);
|
||||
Log::info('User registered: ', $user->toArray());
|
||||
|
||||
# Set the intial admin e-mail address
|
||||
// Set the intial admin e-mail address
|
||||
setting('general.admin_email', $user->email);
|
||||
|
||||
$this->analyticsSvc->sendInstall();
|
||||
@@ -332,7 +340,9 @@ class InstallerController extends Controller
|
||||
|
||||
/**
|
||||
* Final step
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function complete(Request $request)
|
||||
|
||||
@@ -9,10 +9,8 @@ use function count;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
|
||||
|
||||
/**
|
||||
* Class UpdaterController
|
||||
* @package Modules\Installer\Http\Controllers
|
||||
*/
|
||||
class UpdaterController extends Controller
|
||||
{
|
||||
@@ -21,6 +19,7 @@ class UpdaterController extends Controller
|
||||
|
||||
/**
|
||||
* UpdaterController constructor.
|
||||
*
|
||||
* @param MigrationService $migrationSvc
|
||||
* @param SeederService $seederSvc
|
||||
*/
|
||||
@@ -51,7 +50,7 @@ class UpdaterController extends Controller
|
||||
public function step1(Request $request)
|
||||
{
|
||||
$migrations = $this->migrationSvc->migrationsAvailable();
|
||||
if(count($migrations) > 0) {
|
||||
if (count($migrations) > 0) {
|
||||
Log::info('No migrations found');
|
||||
}
|
||||
|
||||
@@ -70,7 +69,7 @@ class UpdaterController extends Controller
|
||||
Log::info('Update: run_migrations', $request->post());
|
||||
|
||||
$migrations = $this->migrationSvc->migrationsAvailable();
|
||||
if(count($migrations) === 0) {
|
||||
if (count($migrations) === 0) {
|
||||
$this->seederSvc->syncAllSeeds();
|
||||
return view('installer::update/steps/step3-update-complete');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user