Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/Config/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@
*/
'installedAlreadyAction' => '',

/*
|--------------------------------------------------------------------------
| Ignore Already Installed
|--------------------------------------------------------------------------
| This setting to ignore, if the installation were already perforemed.
| This is maybe helpfull in local enviroments for debugging.
| This is not recommended for productive usage. Default boolean false.
*/
'ignoreAlreadyInstalled' => 'false',

/*
|--------------------------------------------------------------------------
| List of Commands which should be executed in addition
|--------------------------------------------------------------------------
| Add your own Artisan commands to the following array.
| They will get executed in this order. They will run
| after database migration. The output will be shown at the finished page.
| The list is by default empty.
*/
'commands'=> [

],

/*
|--------------------------------------------------------------------------
| Updater Enabled
Expand All @@ -138,4 +161,25 @@
*/
'updaterEnabled' => 'true',

/*
|--------------------------------------------------------------------------
| Installer Enabled
|--------------------------------------------------------------------------
| Can the application run the '/install' route with the migrations.
| The default option is set to True if none is present.
| Boolean value. This is a check on top of "installedAlready".
|
*/
'installerEnabled' => 'true',

/*
|--------------------------------------------------------------------------
| Installed Log File
|--------------------------------------------------------------------------
| A file to indicate if the installation were already performed.
| Filename within the storage dir.
|
*/
'installedFile' => 'installed'

];
39 changes: 39 additions & 0 deletions src/Controllers/CommandController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace RachidLaasri\LaravelInstaller\Controllers;

use Illuminate\Routing\Controller;
use RachidLaasri\LaravelInstaller\Helpers\CommandManager;
use Illuminate\Http\Request;

class CommandController extends Controller
{
/**
* @var CommandManager
*/
private $commandManager;

/**
* @param CommandManager $commandManager
*/
public function __construct(CommandManager $commandManager)
{
$this->commandManager = $commandManager;
}

/**
* Execute the command.
*
* @return \Illuminate\View\View
*/
public function commands(Request $request)
{
$response = $this->commandManager->executeCommands();

$request->session()->put(['commandMessage' => $response]);
$request->session()->reflash();
$request->session()->save();

return redirect()->route('LaravelInstaller::final');
}
}
12 changes: 8 additions & 4 deletions src/Controllers/DatabaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace RachidLaasri\LaravelInstaller\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use RachidLaasri\LaravelInstaller\Helpers\DatabaseManager;

Expand All @@ -23,13 +24,16 @@ public function __construct(DatabaseManager $databaseManager)
/**
* Migrate and seed the database.
*
* @return \Illuminate\View\View
* @return \Illuminate\Http\RedirectResponse
*/
public function database()
public function database(Request $request)
{
$response = $this->databaseManager->migrateAndSeed();

return redirect()->route('LaravelInstaller::final')
->with(['message' => $response]);
$request->session()->put(['databaseMessage' => $response]);
$request->session()->save();
$request->session()->reflash();

return redirect()->route('LaravelInstaller::command');
}
}
68 changes: 68 additions & 0 deletions src/Helpers/CommandManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace RachidLaasri\LaravelInstaller\Helpers;

use Exception;
use Illuminate\Database\SQLiteConnection;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Symfony\Component\Console\Output\BufferedOutput;

class CommandManager
{
/**
* Migrate and seed the database.
*
* @return array
*/
public function executeCommands()
{
$outputLog = new BufferedOutput;
$commands = config('installer.commands');
$response = [];

if (is_array($commands) && count($commands) > 0){
foreach ($commands as $command) {
array_push($response, $this->execute($command, $outputLog));
}
}
return $response;
}

/**
* Run the command and add response.
*
* @param \Symfony\Component\Console\Output\BufferedOutput $outputLog
* @return array
*/
private function execute($command, BufferedOutput $outputLog)
{
try {
Artisan::call($command, [], $outputLog);
} catch (Exception $e) {
return $this->response($command, $e->getMessage(), 'error', $outputLog);
}

return $this->response($command, "Success", 'success', $outputLog);
}

/**
* Return a formatted error messages.
*
* @param string $message
* @param string $status
* @param \Symfony\Component\Console\Output\BufferedOutput $outputLog
* @return array
*/
private function response($command, $message, $status, BufferedOutput $outputLog)
{
return [
'command' => $command,
'status' => $status,
'message' => $message,
'outputLog' => $outputLog->fetch(),
];
}

}
2 changes: 1 addition & 1 deletion src/Helpers/FinalInstallManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static function response($message, BufferedOutput $outputLog)
return [
'status' => 'error',
'message' => $message,
'dbOutputLog' => $outputLog->fetch(),
'outputLog' => $outputLog->fetch(),
];
}
}
9 changes: 8 additions & 1 deletion src/Helpers/InstalledFileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class InstalledFileManager
*/
public function create()
{
$installedLogFile = storage_path('installed');
$installedLogFileName = config('installer.installedFileName', 'installed');
$installedLogFile = storage_path($installedLogFileName);

$dateStamp = date('Y/m/d h:i:sa');

Expand All @@ -37,4 +38,10 @@ public function update()
{
return $this->create();
}

public static function alreadyInstalled()
{
$installedLogFileName = config('installer.installedFileName', 'installed');
return file_exists(storage_path($installedLogFileName));
}
}
4 changes: 4 additions & 0 deletions src/Lang/de/installer_messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
'title' => 'Laravel Installer',
'next' => 'Nächster Schritt',
'finish' => 'Installieren',
'ignore' => 'Ignorieren & weiter',

/*
*
* Home page translations.
*
*/
'welcome' => [
'templateTitle' => 'Willkommen',
'title' => 'Willkommen zum Installer',
'message' => 'Willkommen zum Laravel Installationsassistent.',
'next' => 'Schrittweise konfigurieren',
'skipAndInstall' => 'Überspringen und sofort installieren'
],

/*
Expand Down
6 changes: 5 additions & 1 deletion src/Lang/en/installer_messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'next' => 'Next Step',
'back' => 'Previous',
'finish' => 'Install',
'ignore' => 'Ignore and Next Step',
'forms' => [
'errorTitle' => 'The Following errors occurred:',
],
Expand All @@ -24,7 +25,8 @@
'templateTitle' => 'Welcome',
'title' => 'Laravel Installer',
'message' => 'Easy Installation and Setup Wizard.',
'next' => 'Check Requirements',
'next' => 'Step-by-step Configuration',
'skipAndInstall' => 'Install immediately'
],

/*
Expand Down Expand Up @@ -189,9 +191,11 @@
'templateTitle' => 'Installation Finished',
'finished' => 'Application has been successfully installed.',
'migration' => 'Migration &amp; Seed Console Output:',
'command' => 'Command Console Output:',
'console' => 'Application Console Output:',
'log' => 'Installation Log Entry:',
'env' => 'Final .env File:',
'error' => 'ERROR',
'exit' => 'Click here to exit',
],

Expand Down
56 changes: 26 additions & 30 deletions src/Middleware/canInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Redirect;
use RachidLaasri\LaravelInstaller\Helpers\InstalledFileManager;

class canInstall
{
Expand All @@ -16,45 +17,40 @@ class canInstall
*/
public function handle($request, Closure $next)
{
if ($this->alreadyInstalled()) {
$installedRedirect = config('installer.installedAlreadyAction');
$installerEnabled = filter_var(config('installer.installerEnabled', true), FILTER_VALIDATE_BOOLEAN);
$ignoreAlreadyInstalled = filter_var(config('installer.ignoreAlreadyInstalled', false), FILTER_VALIDATE_BOOLEAN);

switch ($installedRedirect) {
if(!$ignoreAlreadyInstalled) {
if (InstalledFileManager::alreadyInstalled() || !$installerEnabled) {
$installedRedirect = config('installer.installedAlreadyAction');

case 'route':
$routeName = config('installer.installed.redirectOptions.route.name');
$data = config('installer.installed.redirectOptions.route.message');
switch ($installedRedirect) {

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

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

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

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

case '404':
case 'default':
default:
abort(404);
break;
}
}
}

return $next($request);
}

/**
* If application is already installed.
*
* @return bool
*/
public function alreadyInstalled()
{
return file_exists(storage_path('installed'));
}
}
5 changes: 5 additions & 0 deletions src/Routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
'uses' => 'DatabaseController@database',
]);

Route::get('command', [
'as' => 'command',
'uses' => 'CommandController@commands',
]);

Route::get('final', [
'as' => 'final',
'uses' => 'FinalController@finish',
Expand Down
26 changes: 23 additions & 3 deletions src/Views/finished.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,29 @@

@section('container')

@if(session('message')['dbOutputLog'])
<p><strong><small>{{ trans('installer_messages.final.migration') }}</small></strong></p>
<pre><code>{{ session('message')['dbOutputLog'] }}</code></pre>
@if(session('databaseMessage'))
@if( session('databaseMessage')['dbOutputLog'])
<p><strong><small>{{ trans('installer_messages.final.migration') }}</small></strong></p>
@if(session('databaseMessage')['status'] == 'error')
<strong><small>{{ trans('installer_messages.final.error') }}</small></strong>
<pre>{{ session('databaseMessage')['message'] }}</pre>
@else
<pre><code>{{ session('databaseMessage')['dbOutputLog'] }}</code></pre>
@endif
@endif
@endif

@if(session('commandMessage'))
<p><strong><small>{{ trans('installer_messages.final.command') }}</small></strong></p>
@foreach (session('commandMessage') as $message)
<p><strong><small>{{ $message['command'] }}</small></strong></p>
@if($message['status'] == 'error')
<strong><small>{{ trans('installer_messages.final.error') }}</small></strong>
<pre>{{ $message['message'] }}</pre>
@else
<pre><code>{{ $message['outputLog'] }}</code></pre>
@endif
@endif
@endif

<p><strong><small>{{ trans('installer_messages.final.console') }}</small></strong></p>
Expand Down
Loading