Heimdall/app/Providers/AppServiceProvider.php

69 lines
2.1 KiB
PHP
Raw Normal View History

2018-01-26 14:35:01 +00:00
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Artisan;
2018-02-05 15:22:51 +00:00
use Schema;
2018-02-04 21:28:11 +00:00
use App\Setting;
2018-01-26 14:35:01 +00:00
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$alt_bg = '';
2018-02-06 22:02:50 +00:00
if(!is_file(base_path('.env'))) {
touch(base_path('.env'));
Artisan::call('key:generate');
}
if(!is_file(database_path('app.sqlite'))) {
2018-01-29 20:14:40 +00:00
// first time setup
2018-02-06 22:02:50 +00:00
touch(database_path('app.sqlite'));
2018-02-04 20:50:59 +00:00
Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true));
2018-02-02 15:16:55 +00:00
Artisan::call('storage:link');
//Cache
//Artisan::call('config:cache');
//Artisan::call('route:cache');
2018-01-29 20:14:40 +00:00
}
2018-02-06 22:02:50 +00:00
if(is_file(database_path('app.sqlite'))) {
2018-02-05 15:22:51 +00:00
if(Schema::hasTable('settings')) {
if($bg_image = Setting::fetch('background_image')) {
$alt_bg = ' style="background-image: url('.asset('storage/'.$bg_image).')"';
}
2018-02-05 15:02:18 +00:00
2018-02-05 15:22:51 +00:00
// check version to see if an upgrade is needed
$db_version = Setting::fetch('version');
$app_version = config('app.version');
if(version_compare($app_version, $db_version) == 1) { // app is higher than db, so need to run migrations etc
Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true));
}
2018-02-05 15:39:26 +00:00
} else {
Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true));
}
2018-02-07 13:37:40 +00:00
$lang = Setting::fetch('language');
\App::setLocale($lang);
2018-02-04 21:28:11 +00:00
}
view()->share('alt_bg', $alt_bg);
2018-01-26 14:35:01 +00:00
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
2018-02-04 20:50:59 +00:00
$this->app->singleton('settings', function () {
return new Setting();
});
2018-01-26 14:35:01 +00:00
}
}