2021-06-05 09:26:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2022-01-24 11:39:01 +00:00
|
|
|
use App\Models\Settings;
|
2023-01-25 21:32:59 +00:00
|
|
|
use App\Models\UsefulLink;
|
2023-01-05 17:01:42 +00:00
|
|
|
use Exception;
|
2021-06-05 09:26:32 +00:00
|
|
|
use Illuminate\Pagination\Paginator;
|
2022-01-24 11:39:01 +00:00
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2022-02-08 08:46:33 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2021-06-05 09:26:32 +00:00
|
|
|
use Illuminate\Support\Facades\Schema;
|
2021-07-28 16:22:12 +00:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2021-06-05 09:26:32 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2023-01-11 10:08:22 +00:00
|
|
|
use Qirolab\Theme\Theme;
|
2021-06-05 09:26:32 +00:00
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
|
|
|
Paginator::useBootstrap();
|
|
|
|
Schema::defaultStringLength(191);
|
2021-07-28 16:22:12 +00:00
|
|
|
|
|
|
|
Validator::extend('multiple_date_format', function ($attribute, $value, $parameters, $validator) {
|
|
|
|
$ok = true;
|
|
|
|
$result = [];
|
|
|
|
|
|
|
|
// iterate through all formats
|
|
|
|
foreach ($parameters as $parameter) {
|
|
|
|
//validate with laravels standard date format validation
|
|
|
|
$result[] = $validator->validateDateFormat($attribute, $value, [$parameter]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//if none of result array is true. it sets ok to false
|
2023-01-05 17:01:42 +00:00
|
|
|
if (! in_array(true, $result)) {
|
2021-07-28 16:22:12 +00:00
|
|
|
$ok = false;
|
2023-01-05 17:01:42 +00:00
|
|
|
$validator->setCustomMessages(['multiple_date_format' => 'The format must be one of '.implode(',', $parameters)]);
|
2021-07-28 16:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $ok;
|
|
|
|
});
|
2022-01-24 11:12:50 +00:00
|
|
|
|
2023-01-25 21:32:59 +00:00
|
|
|
|
|
|
|
if (Schema::hasColumn('useful_links', 'navbar')) {
|
|
|
|
$useful_links = UsefulLink::where("navbar", "true")->get();
|
|
|
|
view()->share('useful_links', $useful_links);
|
|
|
|
}
|
|
|
|
|
2022-01-24 11:12:50 +00:00
|
|
|
//only run if the installer has been executed
|
2022-02-08 08:37:29 +00:00
|
|
|
try {
|
2022-01-24 11:12:50 +00:00
|
|
|
$settings = Settings::all();
|
|
|
|
// Set all configs from database
|
|
|
|
foreach ($settings as $setting) {
|
|
|
|
config([$setting->key => $setting->value]);
|
|
|
|
}
|
|
|
|
|
2023-01-11 10:08:22 +00:00
|
|
|
if(!file_exists(base_path('themes')."/".config("SETTINGS::SYSTEM:THEME"))){
|
|
|
|
config(['SETTINGS::SYSTEM:THEME' => "default"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(config('theme.active') == null){
|
2023-01-11 14:31:46 +00:00
|
|
|
Theme::set(config("SETTINGS::SYSTEM:THEME","default"), "default");
|
2023-01-11 10:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 11:12:50 +00:00
|
|
|
// Set Mail Config
|
|
|
|
//only update config if mail settings have changed in DB
|
|
|
|
if (
|
|
|
|
config('mail.default') != config('SETTINGS:MAIL:MAILER') ||
|
|
|
|
config('mail.mailers.smtp.host') != config('SETTINGS:MAIL:HOST') ||
|
|
|
|
config('mail.mailers.smtp.port') != config('SETTINGS:MAIL:PORT') ||
|
|
|
|
config('mail.mailers.smtp.username') != config('SETTINGS:MAIL:USERNAME') ||
|
|
|
|
config('mail.mailers.smtp.password') != config('SETTINGS:MAIL:PASSWORD') ||
|
|
|
|
config('mail.mailers.smtp.encryption') != config('SETTINGS:MAIL:ENCRYPTION') ||
|
|
|
|
config('mail.from.address') != config('SETTINGS:MAIL:FROM_ADDRESS') ||
|
|
|
|
config('mail.from.name') != config('SETTINGS:MAIL:FROM_NAME')
|
|
|
|
) {
|
|
|
|
config(['mail.default' => config('SETTINGS::MAIL:MAILER')]);
|
|
|
|
config(['mail.mailers.smtp' => [
|
|
|
|
'transport' => 'smtp',
|
|
|
|
'host' => config('SETTINGS::MAIL:HOST'),
|
|
|
|
'port' => config('SETTINGS::MAIL:PORT'),
|
|
|
|
'encryption' => config('SETTINGS::MAIL:ENCRYPTION'),
|
|
|
|
'username' => config('SETTINGS::MAIL:USERNAME'),
|
|
|
|
'password' => config('SETTINGS::MAIL:PASSWORD'),
|
|
|
|
'timeout' => null,
|
|
|
|
'auth_mode' => null,
|
|
|
|
]]);
|
|
|
|
config(['mail.from' => ['address' => config('SETTINGS::MAIL:FROM_ADDRESS'), 'name' => config('SETTINGS::MAIL:FROM_NAME')]]);
|
|
|
|
|
|
|
|
Artisan::call('queue:restart');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Recaptcha API Config
|
2022-08-06 14:39:31 +00:00
|
|
|
// Load recaptcha package if recaptcha is enabled
|
2023-01-05 17:01:42 +00:00
|
|
|
if (config('SETTINGS::RECAPTCHA:ENABLED') == 'true') {
|
2022-08-06 14:39:31 +00:00
|
|
|
$this->app->register(\Biscolab\ReCaptcha\ReCaptchaServiceProvider::class);
|
|
|
|
}
|
|
|
|
|
2022-01-24 11:12:50 +00:00
|
|
|
//only update config if recaptcha settings have changed in DB
|
|
|
|
if (
|
|
|
|
config('recaptcha.api_site_key') != config('SETTINGS::RECAPTCHA:SITE_KEY') ||
|
|
|
|
config('recaptcha.api_secret_key') != config('SETTINGS::RECAPTCHA:SECRET_KEY')
|
|
|
|
) {
|
|
|
|
config(['recaptcha.api_site_key' => config('SETTINGS::RECAPTCHA:SITE_KEY')]);
|
|
|
|
config(['recaptcha.api_secret_key' => config('SETTINGS::RECAPTCHA:SECRET_KEY')]);
|
|
|
|
|
|
|
|
Artisan::call('config:clear');
|
|
|
|
Artisan::call('cache:clear');
|
|
|
|
}
|
|
|
|
|
2022-08-16 21:02:22 +00:00
|
|
|
try {
|
|
|
|
$stringfromfile = file(base_path().'/.git/HEAD');
|
|
|
|
|
|
|
|
$firstLine = $stringfromfile[0]; //get the string from the array
|
|
|
|
|
2023-01-05 17:01:42 +00:00
|
|
|
$explodedstring = explode('/', $firstLine, 3); //seperate out by the "/" in the string
|
2022-08-16 21:02:22 +00:00
|
|
|
|
|
|
|
$branchname = $explodedstring[2]; //get the one that is always the branch name
|
|
|
|
} catch (Exception $e) {
|
2023-01-05 17:01:42 +00:00
|
|
|
$branchname = 'unknown';
|
2022-08-16 21:02:22 +00:00
|
|
|
Log::error($e);
|
|
|
|
}
|
2022-08-18 13:32:35 +00:00
|
|
|
config(['BRANCHNAME' => $branchname]);
|
2022-08-16 21:02:22 +00:00
|
|
|
|
2022-01-24 11:12:50 +00:00
|
|
|
// Set Discord-API Config
|
|
|
|
config(['services.discord.client_id' => config('SETTINGS::DISCORD:CLIENT_ID')]);
|
|
|
|
config(['services.discord.client_secret' => config('SETTINGS::DISCORD:CLIENT_SECRET')]);
|
2022-02-08 08:37:29 +00:00
|
|
|
} catch (Exception $e) {
|
2023-01-05 17:01:42 +00:00
|
|
|
error_log('Settings Error: Could not load settings from database. The Installation probably is not done yet.');
|
2022-08-16 21:02:22 +00:00
|
|
|
error_log($e);
|
2023-01-05 17:01:42 +00:00
|
|
|
Log::error('Settings Error: Could not load settings from database. The Installation probably is not done yet.');
|
2022-08-16 21:02:22 +00:00
|
|
|
Log::error($e);
|
2022-01-24 11:12:50 +00:00
|
|
|
}
|
2021-06-05 09:26:32 +00:00
|
|
|
}
|
|
|
|
}
|