Skip to content

Commit

Permalink
GUI installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
suraj-webkul committed Aug 16, 2024
1 parent 49e5291 commit abbcbf6
Show file tree
Hide file tree
Showing 127 changed files with 18,045 additions and 279 deletions.
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Kernel extends HttpKernel
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Webkul\Installer\Http\Middleware\CanInstall::class,
];

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/Webkul/Installer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/npm-debug.log
/package-lock.json
26 changes: 26 additions & 0 deletions packages/Webkul/Installer/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "bagisto/laravel-installer",
"license": "MIT",
"description": "Installer package",
"authors": [
{
"name": "Bagisto",
"email": "[email protected]"
}
],
"require": {},
"autoload": {
"psr-4": {
"Webkul\\Installer\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Webkul\\Installer\\Providers\\InstallerServiceProvider"
],
"aliases": {}
}
},
"minimum-stability": "dev"
}
24 changes: 24 additions & 0 deletions packages/Webkul/Installer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"autoprefixer": "^10.4.16",
"axios": "^1.6.4",
"laravel-vite-plugin": "^0.7.2",
"postcss": "^8.4.23",
"tailwindcss": "^3.3.2",
"vite": "^4.0.0",
"vue": "^3.4.19"
},
"dependencies": {
"@vee-validate/i18n": "^4.9.1",
"@vee-validate/rules": "^4.9.1",
"@vitejs/plugin-vue": "^4.2.3",
"mitt": "^3.0.0",
"vee-validate": "^4.9.1",
"vue-flatpickr": "^2.3.0"
}
}
6 changes: 6 additions & 0 deletions packages/Webkul/Installer/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
Empty file modified packages/Webkul/Installer/src/Data/countries.json
100755 → 100644
Empty file.
Empty file modified packages/Webkul/Installer/src/Data/states.json
100755 → 100644
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
110 changes: 110 additions & 0 deletions packages/Webkul/Installer/src/Helpers/DatabaseManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace Webkul\Installer\Helpers;

use Exception;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Webkul\Installer\Database\Seeders\DatabaseSeeder as KrayinDatabaseSeeder;
use Webkul\Installer\Database\Seeders\ProductTableSeeder;

class DatabaseManager
{
/**
* Check Database Connection.
*/
public function isInstalled()
{
if (! file_exists(base_path('.env'))) {
return false;
}

try {
DB::connection()->getPDO();

$isConnected = (bool) DB::connection()->getDatabaseName();

if (! $isConnected) {
return false;
}

$hasUserTable = Schema::hasTable('users');

if (! $hasUserTable) {
return false;
}

$userCount = DB::table('users')->count();

if (! $userCount) {
return false;
}

return true;
} catch (Exception $e) {
return false;
}
}

/**
* Drop all the tables and migrate in the database
*
* @return void|string
*/
public function migration()
{
try {
Artisan::call('migrate:fresh');

return response()->json([
'success' => true,
'message' => 'Tables is migrated successfully.',
]);
} catch (Exception $e) {
return response()->json([
'error' => $e->getMessage(),
], 500);
}
}

/**
* Seed the database.
*
* @return void|string
*/
public function seeder($data)
{
$data['parameter'] = [
'locale' => $data['parameter']['default_locales'],
'currency' => $data['parameter']['allowed_locales'],
];

try {
app(KrayinDatabaseSeeder::class)->run($data['parameter']);

$this->storageLink();
} catch (Exception $e) {
return $e->getMessage();
}
}

/**
* Storage Link.
*/
private function storageLink()
{
Artisan::call('storage:link');
}

/**
* Generate New Application Key
*/
public function generateKey()
{
try {
Artisan::call('key:generate');
} catch (Exception $e) {
}
}
}
93 changes: 93 additions & 0 deletions packages/Webkul/Installer/src/Helpers/EnvironmentManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Webkul\Installer\Helpers;

use Exception;

class EnvironmentManager
{
/**
* Create a helper instance.
*
* @return void
*/
public function __construct(protected DatabaseManager $databaseManager) {}

/**
* Generate ENV File and Installation.
*
* @param [object] $request
*/
public function generateEnv($request)
{
$envExamplePath = base_path('.env.example');

$envPath = base_path('.env');

if (! file_exists($envPath)) {
if (file_exists($envExamplePath)) {
copy($envExamplePath, $envPath);
} else {
touch($envPath);
}
}

try {
$response = $this->setEnvConfiguration($request->all());

$this->databaseManager->generateKey();

return $response;
} catch (Exception $e) {
return $e;
}
}

/**
* Set the ENV file configuration.
*
* @return string
*/
public function setEnvConfiguration($request)
{
$envDBParams = [];

/**
* Update params with form-data.
*/
if (isset($request['db_hostname'])) {
$envDBParams['DB_HOST'] = $request['db_hostname'];
$envDBParams['DB_DATABASE'] = $request['db_name'];
$envDBParams['DB_PREFIX'] = $request['db_prefix'] ?? '';
$envDBParams['DB_USERNAME'] = $request['db_username'];
$envDBParams['DB_PASSWORD'] = $request['db_password'];
$envDBParams['DB_CONNECTION'] = $request['db_connection'];
$envDBParams['DB_PORT'] = (int) $request['db_port'];
}

if (isset($request['app_name'])) {
$envDBParams['APP_NAME'] = $request['app_name'] ?? null;
$envDBParams['APP_URL'] = $request['app_url'];
$envDBParams['APP_LOCALE'] = $request['app_locale'];
$envDBParams['APP_TIMEZONE'] = $request['app_timezone'];
}

$data = file_get_contents(base_path('.env'));

foreach ($envDBParams as $key => $value) {
if (preg_match('/\s/', $value)) {
$value = '"'.$value.'"';
}

$data = preg_replace("/$key=(.*)/", "$key=$value", $data);
}

try {
file_put_contents(base_path('.env'), $data);
} catch (Exception $e) {
return false;
}

return true;
}
}
96 changes: 96 additions & 0 deletions packages/Webkul/Installer/src/Helpers/ServerRequirements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace Webkul\Installer\Helpers;

class ServerRequirements
{
/**
* Minimum PHP Version Supported (Override is in installer.php config file).
*
* @var string
*/
private $minPhpVersion = '8.1.0';

/**
* Check for the server requirements.
*/
public function validate(): array
{
// Server Requirements
$requirements = [
'php' => [
'calendar',
'ctype',
'curl',
'dom',
'fileinfo',
'filter',
'gd',
'hash',
'intl',
'json',
'mbstring',
'openssl',
'pcre',
'pdo',
'session',
'tokenizer',
'xml',
],
];

$results = [];

foreach ($requirements as $type => $requirement) {
foreach ($requirement as $item) {
$results['requirements'][$type][$item] = true;

if (! extension_loaded($item)) {
$results['requirements'][$type][$item] = false;

$results['errors'] = true;
}
}
}

return $results;
}

/**
* Check PHP version requirement.
*
* @return array
*/
public function checkPHPversion(?string $minPhpVersion = null)
{
$minVersionPhp = $minPhpVersion ?? $this->minPhpVersion;

$currentPhpVersion = $this->getPhpVersionInfo();

$supported = version_compare($currentPhpVersion['version'], $minVersionPhp) >= 0;

return [
'full' => $currentPhpVersion['full'],
'current' => $currentPhpVersion['version'],
'minimum' => $minVersionPhp,
'supported' => $supported,
];
}

/**
* Get current Php version information.
*
* @return array
*/
private static function getPhpVersionInfo()
{
$currentVersionFull = PHP_VERSION;

preg_match("#^\d+(\.\d+)*#", $currentVersionFull, $filtered);

return [
'full' => $currentVersionFull,
'version' => $filtered[0] ?? $currentVersionFull,
];
}
}
12 changes: 12 additions & 0 deletions packages/Webkul/Installer/src/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Webkul\Installer\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
use DispatchesJobs, ValidatesRequests;
}
Loading

0 comments on commit abbcbf6

Please sign in to comment.