Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #90 from jeremykenedy/master
Browse files Browse the repository at this point in the history
Add already installed config options.
  • Loading branch information
rashidlaasri authored Jul 17, 2017
2 parents f2d410e + f10a15a commit a16c357
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 15 deletions.
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ The current features are :

* [Laravel 5.1, 5.2, 5.3, 5.4 or newer](https://laravel.com/docs/installation)


## Installation

1. From your projects root folder in terminal run:
Expand Down
47 changes: 47 additions & 0 deletions src/Config/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,51 @@
],
],
],

/*
|--------------------------------------------------------------------------
| Installed Middlware Options
|--------------------------------------------------------------------------
| Different available status switch configuration for the
| canInstall middleware located in `canInstall.php`.
|
*/
'installed' => [
'redirectOptions' => [
'route' => [
'name' => 'welcome',
'data' => [],
],
'abort' => [
'type' => '404',
],
'dump' => [
'data' => 'Dumping a not found message.',
]
],
],

/*
|--------------------------------------------------------------------------
| Selected Installed Middlware Option
|--------------------------------------------------------------------------
| The selected option fo what happens when an installer intance has been
| Default output is to `/resources/views/error/404.blade.php` if none.
| The available middleware options include:
| route, abort, dump, 404, default, ''
|
*/
'installedAlreadyAction' => '',

/*
|--------------------------------------------------------------------------
| Updater Enabled
|--------------------------------------------------------------------------
| Can the application run the '/update' route with the migrations.
| The default option is set to False if none is present.
| Boolean value
|
*/
'updaterEnabled' => 'true',

];
33 changes: 29 additions & 4 deletions src/Middleware/canInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use DB;
use Redirect;

class canInstall
{
Expand All @@ -13,15 +14,39 @@ class canInstall
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
* @param Redirector $redirect
* @return \Illuminate\Http\RedirectResponse
*/
public function handle($request, Closure $next)
{

// Possible Feature: Make this some configurable option for easier customization and controversial desire to change it.
if($this->alreadyInstalled()) {
abort(404);
}

$installedRedirect = config('installer.installedAlreadyAction');

switch ($installedRedirect) {

case 'route':
$routeName = config('installer.installed.redirectOptions.route.name');
$data = config('installer.installed.redirectOptions.route.message');
return redirect()->route($routeName)->with(['data' => $data]);
break;

case 'abort':
abort(config('installer.installed.redirectOptions.abort.type'));
break;

case 'dump':
$dump = config('installer.installed.redirectOptions.dump.data');
dd($dump);
break;

case '404':
case 'default':
default:
abort(404);
break;
}
}
return $next($request);
}

Expand Down
26 changes: 18 additions & 8 deletions src/Middleware/canUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,26 @@ class canUpdate
*/
public function handle($request, Closure $next)
{
$canInstall = new canInstall;
$updateEnabled = filter_var(config('installer.updaterEnabled'), FILTER_VALIDATE_BOOLEAN);
switch ($updateEnabled) {
case true:
$canInstall = new canInstall;

// if the application has not been installed,
// redirect to the installer
if (!$canInstall->alreadyInstalled()) {
return redirect()->route('LaravelInstaller::welcome');
}
// if the application has not been installed,
// redirect to the installer
if (!$canInstall->alreadyInstalled()) {
return redirect()->route('LaravelInstaller::welcome');
}

if($this->alreadyUpdated()) {
abort(404);
}
break;

if($this->alreadyUpdated()) {
abort(404);
case false:
default:
abort(404);
break;
}

return $next($request);
Expand Down
4 changes: 2 additions & 2 deletions src/Views/environment-wizard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<label for="environment">
{{ trans('installer_messages.environment.wizard.form.app_environment_label') }}
</label>
<select name="environment" id="environment" onchange='CheckColors(this.value);'>
<select name="environment" id="environment" onchange='checkEnvironment(this.value);'>
<option value="local" selected>{{ trans('installer_messages.environment.wizard.form.app_environment_label_local') }}</option>
<option value="development">{{ trans('installer_messages.environment.wizard.form.app_environment_label_developement') }}</option>
<option value="qa">{{ trans('installer_messages.environment.wizard.form.app_environment_label_qa') }}</option>
Expand Down Expand Up @@ -505,7 +505,7 @@

@section('scripts')
<script type="text/javascript">
function CheckColors(val) {
function checkEnvironment(val) {
var element=document.getElementById('environment_text_input');
if(val=='other') {
element.style.display='block';
Expand Down

0 comments on commit a16c357

Please sign in to comment.