feat(form-builder): schema drift detection + PUT auto_save_count
S2c D5 completion: schema_version_at_open column + drift semantics. - Migration 2026_04_22_100002 adds unsignedInteger schema_version_at_open. Recorded by FormSubmissionService::createDraft at the moment the portal first renders the form. - PublicFormSubmissionResource.schema_drift now compares schema_version_at_open vs schema_version_at_submit (or schema.version for active drafts) so organiser edits during an open draft surface as drift on subsequent PUT/submit responses. - PublicFormSubmissionController::update routes through FormSubmissionService::saveDraft so auto_save_count increments and the FormSubmissionDraftUpdated event fires per PUT. - bootstrap/app.php: FormRequest ValidationException on /api/v1/public/forms/* is now re-wrapped into the D6 envelope with code=VALIDATION_FAILED, so public endpoints emit one consistent error shape regardless of layer. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -69,21 +69,30 @@ final class PublicFormSubmissionResource extends JsonResource
|
||||
|
||||
private function computeSchemaDrift(): bool
|
||||
{
|
||||
if ($this->schema_version_at_submit === null) {
|
||||
// Draft phase: drift is "version advanced since the submission
|
||||
// was opened". We use schema.version vs the version the portal
|
||||
// saw via PublicFormSchemaResource at open time — which is
|
||||
// only derivable after submit. For drafts, schema_drift stays
|
||||
// false; the submit response is the authoritative check.
|
||||
// The draft was opened against version_at_open; at submit time the
|
||||
// schema's current version is frozen into version_at_submit. Drift
|
||||
// means the organiser edited the schema between the portal loading
|
||||
// the form and the user hitting submit.
|
||||
//
|
||||
// Drafts without a submit stamp keep the comparison live against
|
||||
// the current schema.version so an organiser edit during an open
|
||||
// draft also surfaces drift on subsequent PUT/GET calls.
|
||||
|
||||
$atOpen = $this->schema_version_at_open;
|
||||
if ($atOpen === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$schema = $this->schema;
|
||||
if ($schema === null) {
|
||||
return false;
|
||||
$other = $this->schema_version_at_submit;
|
||||
if ($other === null) {
|
||||
$schema = $this->schema;
|
||||
if ($schema === null) {
|
||||
return false;
|
||||
}
|
||||
$other = (int) $schema->version;
|
||||
}
|
||||
|
||||
return (int) $schema->version !== (int) $this->schema_version_at_submit;
|
||||
return (int) $atOpen !== (int) $other;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user