FEATURE #2503: add easier installer
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\CMS\ModuleManager\Providers;
|
namespace App\CMS\ModuleManager\Providers;
|
||||||
|
|
||||||
use App\CMS\Repositories\Module as ModuleRepository;
|
use App\CMS\Repositories\Module as ModuleRepository;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class ModuleManager extends ServiceProvider
|
class ModuleManager extends ServiceProvider
|
||||||
@@ -14,7 +15,11 @@ class ModuleManager extends ServiceProvider
|
|||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
// this service provider needs published config - config is merged right after this service provider
|
// this service provider needs published config - config is merged right after this service provider
|
||||||
$modules = app(ModuleRepository::class)->getOnlyModules();
|
try {
|
||||||
|
$modules = app(ModuleRepository::class)->getOnlyModules();
|
||||||
|
} catch (QueryException $e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// iterate over all modules and enable or disable them
|
// iterate over all modules and enable or disable them
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ class InitDatabaseSchema extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'db:init {schema.sql}';
|
protected $signature = 'db:init';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Command description';
|
protected $description = 'Init database structure';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
@@ -39,13 +39,16 @@ class InitDatabaseSchema extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
do {
|
||||||
|
$schema = $this->ask('Path to database schema file', 'database/schema.sql');
|
||||||
|
} while (!file_exists($schema));
|
||||||
|
|
||||||
$schema = $this->argument('schema.sql');
|
|
||||||
|
|
||||||
if (!file_exists($schema)) throw new NotFoundHttpException('File '.$schema.' does not exist.');
|
|
||||||
|
|
||||||
DB::unprepared(file_get_contents($schema));
|
DB::unprepared(file_get_contents($schema));
|
||||||
|
|
||||||
$this->line('Successfully imported');
|
$this->call('migrate');
|
||||||
|
$this->call('db:seed');
|
||||||
|
|
||||||
|
$this->line('Database successfully initialized.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Language;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
|
|
||||||
|
class InstallCMS extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'cms:install';
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Try to make installation of CMS as easy as possible';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
if (!file_exists(base_path('.env'))) {
|
||||||
|
$this->createEnv();
|
||||||
|
}
|
||||||
|
|
||||||
|
// install php dependencies
|
||||||
|
$parameters = env('APP_DEBUG') ? '' : '--no-dev';
|
||||||
|
exec('composer install ' . $parameters);
|
||||||
|
|
||||||
|
// init database
|
||||||
|
try {
|
||||||
|
// does exist something in laguages table? (Or event table itself?)
|
||||||
|
Language::all();
|
||||||
|
} catch (QueryException $e) {
|
||||||
|
// database is not initialized
|
||||||
|
$this->call('db:init');
|
||||||
|
}
|
||||||
|
|
||||||
|
// install npm dependencies
|
||||||
|
exec('npm install');
|
||||||
|
exec('bower install');
|
||||||
|
exec('gulp');
|
||||||
|
|
||||||
|
// change chmod of needed directories
|
||||||
|
$directories = ['bootstrap/cache', 'storage', 'public'];
|
||||||
|
foreach ($directories as $directory) {
|
||||||
|
$this->changeChmod($directory);
|
||||||
|
}
|
||||||
|
$this->line('Chmod changed');
|
||||||
|
|
||||||
|
$this->call('key:generate');
|
||||||
|
|
||||||
|
$this->line('Creating admin user...');
|
||||||
|
do {
|
||||||
|
$email = $this->ask('E-mail for admin user');
|
||||||
|
} while (empty($email));
|
||||||
|
|
||||||
|
$this->call('user:new', compact('email'));
|
||||||
|
|
||||||
|
$this->line('All done. CMS should be prepared.');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setEnvConstant($envConstant, $value)
|
||||||
|
{
|
||||||
|
$content = file_get_contents(base_path('.env'));
|
||||||
|
$content = preg_replace('/' . $envConstant . '=(.*)/i', $envConstant . '=' . $value, $content);
|
||||||
|
file_put_contents(base_path('.env'), $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createEnv()
|
||||||
|
{
|
||||||
|
\File::copy(base_path('.env.example'), base_path('.env'));
|
||||||
|
|
||||||
|
// set environment
|
||||||
|
do {
|
||||||
|
$env = $this->ask('Install environment: ', 'local');
|
||||||
|
} while (empty($env));
|
||||||
|
$this->setEnvConstant('APP_ENV', $env);
|
||||||
|
|
||||||
|
// set debugging
|
||||||
|
if ($env == 'local') {
|
||||||
|
$debug = 'true';
|
||||||
|
} else {
|
||||||
|
$debug = $this->confirm('Enable debugging?', true) ? 'true' : 'false';
|
||||||
|
}
|
||||||
|
$this->setEnvConstant('APP_DEBUG', $debug);
|
||||||
|
|
||||||
|
// setup database
|
||||||
|
$databaseFields = [
|
||||||
|
'DB_HOST' => 'Database server',
|
||||||
|
'DB_DATABASE' => 'Database name',
|
||||||
|
'DB_USERNAME' => 'Database user',
|
||||||
|
'DB_PASSWORD' => 'Password'
|
||||||
|
];
|
||||||
|
foreach ($databaseFields as $constant => $text) {
|
||||||
|
do {
|
||||||
|
$value = $this->ask($text);
|
||||||
|
} while (empty ($value));
|
||||||
|
|
||||||
|
$this->setEnvConstant($constant, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function changeChmod($directory)
|
||||||
|
{
|
||||||
|
@chmod($directory, 0777);
|
||||||
|
|
||||||
|
if (!is_dir($directory)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$subdirectories = \File::allFiles($directory);
|
||||||
|
|
||||||
|
foreach ($subdirectories as $subdirectory) {
|
||||||
|
$this->changeChmod($subdirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,13 +12,11 @@ class NewUser extends Command
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'user:new {email}';
|
protected $signature = 'user:new {email}';
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Creates new user';
|
protected $description = 'Creates new user';
|
||||||
@@ -28,13 +26,9 @@ class NewUser extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$email = $this->argument('email');
|
do {
|
||||||
|
$email = $this->argument('email');
|
||||||
// check if username is really email
|
} while (!filter_var($email, FILTER_VALIDATE_EMAIL));
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
||||||
$this->error($email . ' is not a valid e-mail!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ask for password
|
// ask for password
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
|
use App\Console\Commands\InstallCMS;
|
||||||
use App\Console\Commands\Modules\CreateNew;
|
use App\Console\Commands\Modules\CreateNew;
|
||||||
use App\Console\Commands\Modules\DisableModule;
|
use App\Console\Commands\Modules\DisableModule;
|
||||||
use App\Console\Commands\Modules\EnableModule;
|
use App\Console\Commands\Modules\EnableModule;
|
||||||
@@ -32,7 +33,8 @@ class Kernel extends ConsoleKernel
|
|||||||
Commands\SetTemplate::class,
|
Commands\SetTemplate::class,
|
||||||
Commands\AddLanguage::class,
|
Commands\AddLanguage::class,
|
||||||
PublishTemplateResources::class,
|
PublishTemplateResources::class,
|
||||||
TemplateInfo::class
|
TemplateInfo::class,
|
||||||
|
InstallCMS::class
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php namespace App\Providers;
|
<?php namespace App\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
@@ -8,8 +9,19 @@ class LaravelLocalizationServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$languages = DB::table('languages')
|
try {
|
||||||
->get();
|
$languages = DB::table('languages')
|
||||||
|
->get();
|
||||||
|
} catch (QueryException $e) {
|
||||||
|
$supportedLocales[config('app.locale')] = [
|
||||||
|
'native' => env('LOCALE_NATIVE_NAME', config('app.locale')),
|
||||||
|
'script' => env('LOCALE_SCRIPT', 'Latn'),
|
||||||
|
'name' => env('LOCALE_TRANSLATED_NAME', config('app.locale')),
|
||||||
|
'code' => config('app.locale'),
|
||||||
|
];
|
||||||
|
$this->setSupportedLocales($supportedLocales);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$supportedLocales = [];
|
$supportedLocales = [];
|
||||||
if (empty($languages)) {
|
if (empty($languages)) {
|
||||||
@@ -32,15 +44,20 @@ class LaravelLocalizationServiceProvider extends ServiceProvider
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
config([
|
$this->setSupportedLocales($supportedLocales);
|
||||||
'laravellocalization.supportedLocales' => $supportedLocales,
|
|
||||||
'laravellocalization.useAcceptLanguageHeader' => true,
|
|
||||||
'laravellocalization.hideDefaultLocaleInURL' => true
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
\App::setLocale(LaravelLocalization::getCurrentLocale());
|
\App::setLocale(LaravelLocalization::getCurrentLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function setSupportedLocales($supportedLocales)
|
||||||
|
{
|
||||||
|
config([
|
||||||
|
'laravellocalization.supportedLocales' => $supportedLocales,
|
||||||
|
'laravellocalization.useAcceptLanguageHeader' => true,
|
||||||
|
'laravellocalization.hideDefaultLocaleInURL' => true
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ use App\CMS\Contracts\Repositories\Template as TemplateContract;
|
|||||||
use App\CMS\Handlers\Registrators\TemplateRegistrator;
|
use App\CMS\Handlers\Registrators\TemplateRegistrator;
|
||||||
use App\CMS\Helpers\CurrentTemplate;
|
use App\CMS\Helpers\CurrentTemplate;
|
||||||
use App\CMS\Repositories\Module;
|
use App\CMS\Repositories\Module;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
@@ -13,7 +14,11 @@ class TemplateServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$template = CurrentTemplate::get();
|
try {
|
||||||
|
$template = CurrentTemplate::get();
|
||||||
|
} catch (QueryException $e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// ignore running from artisan
|
// ignore running from artisan
|
||||||
if (App::runningInConsole() || App::environment('testing') || !$template) {
|
if (App::runningInConsole() || App::environment('testing') || !$template) {
|
||||||
|
|||||||
Generated
+9746
-6015
File diff suppressed because it is too large
Load Diff
Regular → Executable
Reference in New Issue
Block a user