S2c D9. Implements ARCH §31.1 — identity matching triggered on FormSubmissionSubmitted for event_registration schemas. - Migration 2026_04_22_100000: add form_submissions.identity_match_status (nullable string(20), pending|matched|none) + index (form_schema_id, identity_match_status). - Migration 2026_04_22_100001: replace the composite index on (form_schema_id, idempotency_key) with a UNIQUE constraint so the DB itself is the race-safe backstop behind the application-level idempotency replay. - Listener TriggerPersonIdentityMatchOnFormSubmit: runs only when form_schema.purpose === event_registration. For person-subject submissions it calls PersonIdentityService::detectMatches and writes matched/pending/none; for public (subject=null) it records 'pending' so the portal can message the submitter that matching will complete when the organiser attaches a person. Failures log at error level and never rethrow — sibling listeners on the same event (§31.10 TAG_PICKER sync) still run. - AppServiceProvider wires the listener alongside SyncTagPickerSelectionsOnSubmit. - FormSubmission.$fillable gains identity_match_status. Rationale for a dedicated column (over JSON on submission.metadata): the matrix is a hard-typed 3-state enum that the public API surfaces directly, and we want to index it to show organiser dashboards "how many submissions are pending identity-confirmation". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
108 lines
2.9 KiB
PHP
108 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models\FormBuilder;
|
|
|
|
use App\Enums\FormBuilder\FormSubmissionReviewStatus;
|
|
use App\Enums\FormBuilder\FormSubmissionStatus;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* No direct activity-log hooks on this model: lifecycle events fire from the
|
|
* FormSubmissionService (arriving in S2) per ARCH §17.1.
|
|
*/
|
|
final class FormSubmission extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'form_schema_id',
|
|
'subject_type',
|
|
'subject_id',
|
|
'submitted_by_user_id',
|
|
'public_submitter_name',
|
|
'public_submitter_email',
|
|
'public_submitter_ip',
|
|
'public_submitter_ip_anonymised_at',
|
|
'status',
|
|
'review_status',
|
|
'reviewed_by_user_id',
|
|
'reviewed_at',
|
|
'review_notes',
|
|
'submitted_at',
|
|
'schema_version_at_submit',
|
|
'schema_snapshot',
|
|
'submission_duration_seconds',
|
|
'auto_save_count',
|
|
'anonymised_at',
|
|
'is_test',
|
|
'submitted_in_locale',
|
|
'opened_at',
|
|
'first_interacted_at',
|
|
'idempotency_key',
|
|
'identity_match_status',
|
|
];
|
|
|
|
/** @var array<string, string> */
|
|
protected $casts = [
|
|
'status' => FormSubmissionStatus::class,
|
|
'review_status' => FormSubmissionReviewStatus::class,
|
|
'schema_snapshot' => 'array',
|
|
'is_test' => 'bool',
|
|
'submitted_at' => 'datetime',
|
|
'reviewed_at' => 'datetime',
|
|
'anonymised_at' => 'datetime',
|
|
'opened_at' => 'datetime',
|
|
'first_interacted_at' => 'datetime',
|
|
'public_submitter_ip_anonymised_at' => 'datetime',
|
|
'schema_version_at_submit' => 'int',
|
|
'submission_duration_seconds' => 'int',
|
|
'auto_save_count' => 'int',
|
|
];
|
|
|
|
public function schema(): BelongsTo
|
|
{
|
|
return $this->belongsTo(FormSchema::class, 'form_schema_id');
|
|
}
|
|
|
|
public function subject(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
public function submittedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'submitted_by_user_id');
|
|
}
|
|
|
|
public function reviewedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'reviewed_by_user_id');
|
|
}
|
|
|
|
public function values(): HasMany
|
|
{
|
|
return $this->hasMany(FormValue::class);
|
|
}
|
|
|
|
public function sectionStatuses(): HasMany
|
|
{
|
|
return $this->hasMany(FormSubmissionSectionStatus::class);
|
|
}
|
|
|
|
public function delegations(): HasMany
|
|
{
|
|
return $this->hasMany(FormSubmissionDelegation::class);
|
|
}
|
|
}
|