- Server di posta in Impostazioni (password cifrata, email di prova): se compilato prende il posto del .env; non si esporta e l'import XML non lo cancella. MAIL_SCHEME=tls nel .env.example non era valido per Laravel 11. - Proclamatori con email e telefono facoltativi, cifrati, nell'XML e cancellati dall'anonimizzazione; il numero apre WhatsApp. - Dopo l'assegnazione un riquadro in evidenza con il link del PDF, "Invia su WhatsApp" con il messaggio pronto e la scelta "inviato / non ancora", che resta finché non si sceglie. - Conferma dell'email obbligatoria per tutti gli utenti, anche esistenti: email in italiano, link valido senza login, nuova conferma a ogni cambio di indirizzo, "Reinvia conferma" in Utenti. Senza conferma restano raggiungibili profilo, cambio password e, per l'admin, il server di posta; comando utenti:conferma-email per l'emergenza. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
3.2 KiB
PHP
120 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Setting extends Model
|
|
{
|
|
protected static ?self $cachedInstance = null;
|
|
|
|
protected $fillable = [
|
|
'congregazione_nome',
|
|
'public_base_url',
|
|
'logo_path',
|
|
'giorni_giacenza_da_assegnare',
|
|
'giorni_giacenza_prioritari',
|
|
'giorni_per_smarrito',
|
|
'home_limit_list',
|
|
'assignment_link_ttl_hours',
|
|
'pdf_viewer_show_download',
|
|
'audit_retention_days',
|
|
'setup_completed',
|
|
'mail_host',
|
|
'mail_port',
|
|
'mail_cifratura',
|
|
'mail_username',
|
|
'mail_password',
|
|
'mail_from_address',
|
|
'mail_from_name',
|
|
];
|
|
|
|
/**
|
|
* Il server di posta: configurazione di questa installazione, non dati.
|
|
* Non si esporta e un import non la tocca (vedi XmlExchange).
|
|
*/
|
|
public const CAMPI_POSTA = [
|
|
'mail_host',
|
|
'mail_port',
|
|
'mail_cifratura',
|
|
'mail_username',
|
|
'mail_password',
|
|
'mail_from_address',
|
|
'mail_from_name',
|
|
];
|
|
|
|
protected $hidden = ['mail_password'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'setup_completed' => 'boolean',
|
|
'pdf_viewer_show_download' => 'boolean',
|
|
'giorni_giacenza_da_assegnare' => 'integer',
|
|
'giorni_giacenza_prioritari' => 'integer',
|
|
'giorni_per_smarrito' => 'integer',
|
|
'home_limit_list' => 'integer',
|
|
'assignment_link_ttl_hours' => 'integer',
|
|
'audit_retention_days' => 'integer',
|
|
'mail_port' => 'integer',
|
|
'mail_password' => 'encrypted',
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::saved(function (): void {
|
|
static::$cachedInstance = null;
|
|
});
|
|
|
|
static::deleted(function (): void {
|
|
static::$cachedInstance = null;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Drop the memoized instance.
|
|
*
|
|
* Mass operations (Setting::query()->delete(), truncate, raw SQL) do not
|
|
* fire model events, so the `saved`/`deleted` hooks above can't catch
|
|
* them and the cache would keep serving a row that no longer exists.
|
|
* Call this explicitly after any such operation.
|
|
*/
|
|
public static function flushCache(): void
|
|
{
|
|
static::$cachedInstance = null;
|
|
}
|
|
|
|
/**
|
|
* Get the singleton settings instance (first row).
|
|
*/
|
|
public static function instance(): static
|
|
{
|
|
if (static::$cachedInstance instanceof static) {
|
|
return static::$cachedInstance;
|
|
}
|
|
|
|
static::$cachedInstance = static::firstOrCreate([], [
|
|
'giorni_giacenza_da_assegnare' => 120,
|
|
'giorni_giacenza_prioritari' => 180,
|
|
'giorni_per_smarrito' => 120,
|
|
'home_limit_list' => 10,
|
|
'assignment_link_ttl_hours' => 1,
|
|
'audit_retention_days' => 730,
|
|
]);
|
|
|
|
return static::$cachedInstance;
|
|
}
|
|
|
|
public static function isSetupComplete(): bool
|
|
{
|
|
$setting = static::first();
|
|
return $setting && $setting->setup_completed;
|
|
}
|
|
|
|
public static function getValue(string $key, mixed $default = null): mixed
|
|
{
|
|
return static::instance()->{$key} ?? $default;
|
|
}
|
|
}
|