From 98090f69df0a8f52c9d90d9bee2cac75261527a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Tue, 22 Mar 2016 15:54:47 +0100 Subject: [PATCH] FEATURE: add artisan commands for creating db structure --- app/Console/Commands/InitDatabaseSchema.php | 51 +++++++++++++++++++ app/Console/Commands/SetTheme.php | 55 +++++++++++++++++++++ app/Console/Kernel.php | 3 ++ 3 files changed, 109 insertions(+) create mode 100644 app/Console/Commands/InitDatabaseSchema.php create mode 100644 app/Console/Commands/SetTheme.php diff --git a/app/Console/Commands/InitDatabaseSchema.php b/app/Console/Commands/InitDatabaseSchema.php new file mode 100644 index 00000000..af8c11c0 --- /dev/null +++ b/app/Console/Commands/InitDatabaseSchema.php @@ -0,0 +1,51 @@ +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'); + } +} diff --git a/app/Console/Commands/SetTheme.php b/app/Console/Commands/SetTheme.php new file mode 100644 index 00000000..943602bf --- /dev/null +++ b/app/Console/Commands/SetTheme.php @@ -0,0 +1,55 @@ +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.'); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index f85bfe13..b018e95f 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -17,6 +17,9 @@ class Kernel extends ConsoleKernel Commands\ChangePassword::class, Commands\InstallModule::class, Commands\InstallAllModules::class, +// Commands\SetupDatabase::class, + Commands\InitDatabaseSchema::class, + Commands\SetTheme::class, ]; /**