FEATURE: add artisan commands for creating db structure
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
|
class InitDatabaseSchema extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'db:init {schema.sql}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Command description';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
$schema = $this->argument('schema.sql');
|
||||||
|
|
||||||
|
if (!file_exists($schema)) throw new NotFoundHttpException('File '.$schema.' does not exist.');
|
||||||
|
|
||||||
|
DB::unprepared(file_get_contents($schema));
|
||||||
|
|
||||||
|
$this->line('Successfully imported');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
|
class SetTheme extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'theme:set {theme_name}';
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Set theme for visitor area';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$theme = $this->argument('theme_name');
|
||||||
|
|
||||||
|
if (!is_dir(resource_path('views/visitor/' . $theme))) {
|
||||||
|
throw new NotFoundHttpException('Invalid theme ' . $theme . '!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$env = file_get_contents(base_path('.env'));
|
||||||
|
|
||||||
|
$env = preg_replace('/THEME=(.+)/i', 'THEME=' . $theme, $env);
|
||||||
|
|
||||||
|
if (!Str::contains($env, 'THEME')) {
|
||||||
|
$env = sprintf("%s\nTHEME=%s\n", $env, $theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents(base_path('.env'), $env);
|
||||||
|
|
||||||
|
$this->line('Theme successfully setup.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,9 @@ class Kernel extends ConsoleKernel
|
|||||||
Commands\ChangePassword::class,
|
Commands\ChangePassword::class,
|
||||||
Commands\InstallModule::class,
|
Commands\InstallModule::class,
|
||||||
Commands\InstallAllModules::class,
|
Commands\InstallAllModules::class,
|
||||||
|
// Commands\SetupDatabase::class,
|
||||||
|
Commands\InitDatabaseSchema::class,
|
||||||
|
Commands\SetTheme::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user