Publication initiale de RelaisSMS : documentation et sources nettoyees

This commit is contained in:
2026-10-21 09:29:39 +02:00
commit ac186b03b1
158 changed files with 24818 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
*.sqlite*
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends Factory<User>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}
@@ -0,0 +1,49 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->bigInteger('expiration')->index();
});
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->bigInteger('expiration')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};
@@ -0,0 +1,59 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('jobs', function (Blueprint $table) {
$table->id();
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedSmallInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->string('connection');
$table->string('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
$table->index(['connection', 'queue', 'failed_at']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
Schema::dropIfExists('job_batches');
Schema::dropIfExists('failed_jobs');
}
};
@@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('app_settings', function (Blueprint $table) {
$table->id();
$table->string('key')->unique();
$table->text('value')->nullable();
$table->string('type')->default('string');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('app_settings');
}
};
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('contacts', function (Blueprint $table) {
$table->id();
$table->string('source')->default('local')->index();
$table->string('external_id')->nullable();
$table->string('first_name')->nullable();
$table->string('last_name');
$table->string('organization')->nullable();
$table->string('email')->nullable();
$table->text('notes')->nullable();
$table->boolean('sms_opt_out')->default(false)->index();
$table->boolean('is_favorite')->default(false)->index();
$table->timestamp('synced_at')->nullable();
$table->timestamps();
$table->softDeletes();
$table->unique(['source', 'external_id']);
$table->index(['last_name', 'first_name']);
});
}
public function down(): void
{
Schema::dropIfExists('contacts');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('contact_groups', function (Blueprint $table) {
$table->id();
$table->string('source')->default('local')->index();
$table->string('external_id')->nullable();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->boolean('is_favorite')->default(false)->index();
$table->timestamp('synced_at')->nullable();
$table->timestamps();
$table->softDeletes();
$table->unique(['source', 'external_id']);
});
}
public function down(): void
{
Schema::dropIfExists('contact_groups');
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('contact_phone_numbers', function (Blueprint $table) {
$table->id();
$table->foreignId('contact_id')->constrained()->cascadeOnDelete();
$table->string('label')->nullable();
$table->string('raw_number');
$table->string('normalized_number')->nullable()->index();
$table->string('country', 2)->nullable();
$table->boolean('is_valid')->default(false)->index();
$table->boolean('is_mobile')->default(false)->index();
$table->boolean('is_primary')->default(false);
$table->string('validation_error')->nullable();
$table->timestamps();
$table->index(['contact_id', 'is_primary']);
});
}
public function down(): void
{
Schema::dropIfExists('contact_phone_numbers');
}
};
@@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('contact_contact_group', function (Blueprint $table) {
$table->foreignId('contact_id')->constrained()->cascadeOnDelete();
$table->foreignId('contact_group_id')->constrained()->cascadeOnDelete();
$table->timestamps();
$table->primary(['contact_id', 'contact_group_id']);
});
}
public function down(): void
{
Schema::dropIfExists('contact_contact_group');
}
};
@@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('contacts', function (Blueprint $table) {
$table->string('remote_url')->nullable()->after('external_id');
$table->string('remote_etag')->nullable()->after('remote_url');
});
}
public function down(): void
{
Schema::table('contacts', function (Blueprint $table) {
$table->dropColumn(['remote_url', 'remote_etag']);
});
}
};
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('source_sync_runs', function (Blueprint $table) {
$table->id();
$table->string('source')->index();
$table->string('status')->index();
$table->timestamp('started_at')->nullable();
$table->timestamp('finished_at')->nullable();
$table->unsignedInteger('fetched_contacts')->default(0);
$table->unsignedInteger('synced_contacts')->default(0);
$table->unsignedInteger('deleted_contacts')->default(0);
$table->text('message')->nullable();
$table->text('error')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('source_sync_runs');
}
};
@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('sms_campaigns', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->string('provider')->default('ovh')->index();
$table->string('status')->default('draft')->index();
$table->text('message');
$table->unsignedInteger('recipients_count')->default(0);
$table->unsignedInteger('sent_count')->default(0);
$table->unsignedInteger('failed_count')->default(0);
$table->string('provider_service_name')->nullable();
$table->string('provider_tag')->nullable()->index();
$table->string('provider_job_id')->nullable();
$table->json('request_payload')->nullable();
$table->json('response_payload')->nullable();
$table->text('error_message')->nullable();
$table->timestamp('sent_at')->nullable();
$table->timestamps();
$table->index(['created_at', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('sms_campaigns');
}
};
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('sms_deliveries', function (Blueprint $table) {
$table->id();
$table->foreignId('sms_campaign_id')->constrained()->cascadeOnDelete();
$table->foreignId('contact_id')->nullable()->constrained()->nullOnDelete();
$table->foreignId('contact_phone_number_id')->nullable()->constrained()->nullOnDelete();
$table->string('contact_name');
$table->string('number')->index();
$table->string('status')->default('queued')->index();
$table->string('provider_message_id')->nullable();
$table->json('provider_response')->nullable();
$table->text('error_message')->nullable();
$table->timestamp('sent_at')->nullable();
$table->timestamps();
$table->index(['sms_campaign_id', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('sms_deliveries');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('sms_campaigns', function (Blueprint $table) {
$table->json('selected_contact_ids')->nullable()->after('recipients_count');
$table->json('selected_group_ids')->nullable()->after('selected_contact_ids');
$table->json('selected_group_names')->nullable()->after('selected_group_ids');
});
}
public function down(): void
{
Schema::table('sms_campaigns', function (Blueprint $table) {
$table->dropColumn([
'selected_contact_ids',
'selected_group_ids',
'selected_group_names',
]);
});
}
};
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('calendar_events', function (Blueprint $table) {
$table->id();
$table->string('source')->index();
$table->string('external_id');
$table->string('remote_url')->nullable();
$table->string('remote_etag')->nullable();
$table->string('summary')->nullable();
$table->text('description')->nullable();
$table->string('location')->nullable();
$table->timestamp('starts_at')->nullable()->index();
$table->timestamp('ends_at')->nullable();
$table->json('attendees')->nullable();
$table->timestamp('synced_at')->nullable();
$table->timestamp('deleted_at')->nullable()->index();
$table->timestamps();
$table->unique(['source', 'external_id']);
});
}
public function down(): void
{
Schema::dropIfExists('calendar_events');
}
};
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('calendar_reminders', function (Blueprint $table) {
$table->id();
$table->foreignId('calendar_event_id')->constrained()->cascadeOnDelete();
$table->foreignId('sms_campaign_id')->nullable()->constrained()->nullOnDelete();
$table->string('reminder_key');
$table->string('action')->default('DISPLAY')->index();
$table->integer('trigger_minutes')->nullable();
$table->timestamp('remind_at')->nullable()->index();
$table->string('status')->default('pending')->index();
$table->text('last_error')->nullable();
$table->timestamp('sent_at')->nullable();
$table->timestamps();
$table->unique(['calendar_event_id', 'reminder_key']);
$table->index(['status', 'remind_at']);
});
}
public function down(): void
{
Schema::dropIfExists('calendar_reminders');
}
};
@@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('sms_campaigns', function (Blueprint $table) {
$table->timestamp('scheduled_at')->nullable()->after('error_message')->index();
$table->timestamp('canceled_at')->nullable()->after('sent_at');
});
}
public function down(): void
{
Schema::table('sms_campaigns', function (Blueprint $table) {
$table->dropIndex(['scheduled_at']);
$table->dropColumn(['scheduled_at', 'canceled_at']);
});
}
};
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace Database\Seeders;
use App\Models\AppSetting;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use RuntimeException;
class DatabaseSeeder extends Seeder
{
use WithoutModelEvents;
/**
* Seed the application's database.
*/
public function run(): void
{
$email = (string) env('RELAIS_SMS_ADMIN_EMAIL', 'admin@relais-sms.test');
$password = (string) env('RELAIS_SMS_ADMIN_PASSWORD', 'relais-sms');
if (! app()->environment(['local', 'testing'])
&& ! User::query()->where('email', $email)->exists()
&& (trim($password) === '' || $password === 'relais-sms')) {
throw new RuntimeException('Definissez un mot de passe administrateur personnel dans RELAIS_SMS_ADMIN_PASSWORD avant de creer le compte hors developpement.');
}
$settings = collect(config('relais_sms.default_settings'))
->map(fn (mixed $value, string $key): array => [
'key' => $key,
'value' => is_bool($value) ? (string) (int) $value : (string) $value,
'type' => match (true) {
is_bool($value) => 'boolean',
is_int($value) => 'integer',
default => 'string',
},
])
->values()
->all();
AppSetting::upsert($settings, ['key'], ['value', 'type']);
User::query()->firstOrCreate([
'email' => $email,
], [
'name' => env('RELAIS_SMS_ADMIN_NAME', 'Administrateur RelaisSMS'),
'password' => Hash::make($password),
]);
}
}