45
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\EditableField;
|
||||
use App\Models\Template;
|
||||
use App\Models\Tenant;
|
||||
use App\Signature\VariableMap;
|
||||
use Illuminate\Database\Seeder;
|
||||
use RuntimeException;
|
||||
|
||||
/** Données initiales : tenant CABM, champs modifiables (tous fermés), template par défaut. */
|
||||
class SignatureSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$tid = config('signature.default_tenant.entra_tenant_id');
|
||||
if (! $tid) {
|
||||
throw new RuntimeException('ENTRA_TENANT_ID absent du .env');
|
||||
}
|
||||
|
||||
$tenant = Tenant::firstOrCreate(
|
||||
['entra_tenant_id' => $tid],
|
||||
['name' => config('signature.default_tenant.name'), 'active' => true],
|
||||
);
|
||||
|
||||
// L'admin choisira dans le back-office les champs ouverts aux agents.
|
||||
foreach (['mobile', 'telephone', 'bureau', 'fonction'] as $field) {
|
||||
EditableField::firstOrCreate(
|
||||
['tenant_id' => $tenant->id, 'field' => $field],
|
||||
['label' => VariableMap::FIELDS[$field]['label'], 'enabled' => false],
|
||||
);
|
||||
}
|
||||
|
||||
if (! Template::where('tenant_id', $tenant->id)->exists()) {
|
||||
$template = Template::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'name' => 'Agents — défaut',
|
||||
'description' => 'Template par défaut, appliqué aux agents hors groupe signature_mail_*.',
|
||||
'draft_html_full' => file_get_contents(database_path('seeders/templates/agents-full.html')),
|
||||
'draft_html_short' => file_get_contents(database_path('seeders/templates/agents-short.html')),
|
||||
'is_default' => true,
|
||||
]);
|
||||
$template->publish();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user