miscellaneous updates

This commit is contained in:
2025-01-26 23:14:28 -06:00
parent 493413ec97
commit cff8101088
28 changed files with 734 additions and 474 deletions

View File

@ -6,6 +6,7 @@ use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Schema;
use Modules\Admin\App\Models\Setting;
class GlobalSettingsService
@ -34,29 +35,57 @@ class GlobalSettingsService
public function loadSystemConfig(): void
{
try {
$config = Cache::remember('global_system_config', $this->cacheTTL, function () {
$settings = Setting::global()
->where('key', 'LIKE', 'config.%')
->pluck('value', 'key')
->toArray();
if (!Schema::hasTable('migrations')) {
// Base de datos no inicializada: usar valores predeterminados
$config = $this->getDefaultSystemConfig();
} else {
// Cargar configuración desde la caché o base de datos
$config = Cache::remember('global_system_config', $this->cacheTTL, function () {
$settings = Setting::global()
->where('key', 'LIKE', 'config.%')
->pluck('value', 'key')
->toArray();
return [
'servicesFacebook' => $this->buildServiceConfig($settings, 'config.services.facebook.', 'services.facebook'),
'servicesGoogle' => $this->buildServiceConfig($settings, 'config.services.google.', 'services.google'),
'custom' => $this->buildVuexyCustomConfig($settings),
];
});
return [
'servicesFacebook' => $this->buildServiceConfig($settings, 'config.services.facebook.', 'services.facebook'),
'servicesGoogle' => $this->buildServiceConfig($settings, 'config.services.google.', 'services.google'),
'custom' => $this->buildVuexyCustomConfig($settings),
];
});
}
// Aplicar configuración al sistema
Config::set('services.facebook', $config['servicesFacebook']);
Config::set('services.google', $config['servicesGoogle']);
Config::set('custom', $config['custom']);
} catch (\Exception $e) {
echo __METHOD__;
echo "<br>" . $e->getMessage() . "<br><br>";
die('You must configure the database.');
// Manejo silencioso de errores para evitar interrupciones
Config::set('services.facebook', config('services.facebook', []));
Config::set('services.google', config('services.google', []));
Config::set('custom', config('custom', []));
}
}
/**
* Devuelve una configuración predeterminada si la base de datos no está inicializada.
*/
private function getDefaultSystemConfig(): array
{
return [
'servicesFacebook' => config('services.facebook', [
'client_id' => '',
'client_secret' => '',
'redirect' => '',
]),
'servicesGoogle' => config('services.google', [
'client_id' => '',
'client_secret' => '',
'redirect' => '',
]),
'custom' => config('custom', []),
];
}
/**
* Verifica si un bloque de configuraciones está presente.
*/