MySQL: JSON-Schlüsselreihenfolge darf keine Rolle spielen
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m40s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m23s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m53s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m47s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m2s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m5s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 2m50s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 2m41s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m6s

MySQL speichert Schlüssel in JSON-Spalten sortiert, MariaDB unverändert.
- Seiten: „Stand unverändert → kein Entwurf“ vergleicht jetzt unabhängig von der
  Schlüsselreihenfolge (auf MySQL entstand sonst bei jedem Speichern ein Entwurf)
- Formulare: Antworten in Ergebnisansicht und E-Mail in der Reihenfolge des Formulars
- Tests vergleichen assoziative Arrays ohne Reihenfolge; neue Tests dafür

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 11:22:46 +00:00
parent 21c706e5f5
commit 2b5fe55f8e
9 changed files with 92 additions and 6 deletions

View file

@ -120,7 +120,7 @@ class FormResults extends Page implements HasTable
$rows .= self::row('Person', e($submission->user ? $submission->user->name.' ('.$submission->user->email.')' : 'gelöschtes Konto'));
}
foreach ($submission->data as $key => $answer) {
foreach ($submission->orderedAnswers() as $key => $answer) {
if (($answer['type'] ?? null) === 'file') {
$value = collect($submission->files->where('field', $key))
->map(fn ($file) => '<a href="'.e($file->url()).'" style="color: rgb(var(--primary-600, 37 99 235)); text-decoration: underline">'.e($file->name).'</a>')

View file

@ -44,7 +44,7 @@ class FormSubmitted extends Mailable implements ShouldQueue
return new Content(view: 'forms::mail.submitted', with: [
'portalName' => app(Branding::class)->portalName(),
'answers' => $includeAnswers ? collect($this->submission->data)->map(fn ($answer, $key) => [
'answers' => $includeAnswers ? collect($this->submission->orderedAnswers())->map(fn ($answer, $key) => [
'label' => $answer['label'],
'value' => $this->submission->display($key),
])->values()->all() : null,

View file

@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
use Inhaus\Plugins\Forms\FormFields;
/**
* Ein ausgefülltes Formular. „data“ enthält je Feld Bezeichnung, Typ und Wert –
@ -50,6 +51,20 @@ class FormSubmission extends Model
return $this->hasMany(FormFile::class, 'submission_id');
}
/**
* Antworten in der Reihenfolge des Formulars; Felder, die es nur noch in
* dieser Einsendung gibt, am Ende. (MySQL speichert JSON-Schlüssel sortiert.)
*
* @return array<string, array{label: string, type: string, value: mixed}>
*/
public function orderedAnswers(): array
{
$data = (array) $this->data;
$order = array_keys(FormFields::inputs($this->form));
return array_replace(array_intersect_key(array_flip($order), $data), $data);
}
/**
* Wert als Text (Listen mit Komma, Ja/Nein, Dateinamen).
*/

View file

@ -97,7 +97,7 @@ class PageEditorController extends Controller
[$title, $content] = $this->validatedWorkingCopy($request);
// Stimmt der Stand mit dem veröffentlichten überein, gibt es keinen Entwurf.
$unchanged = $page->isPublished() && $title === $page->title && $content === $page->content;
$unchanged = $page->isPublished() && $title === $page->title && Content::same($content, $page->content);
$page->forceFill([
'draft_title' => $unchanged ? null : $title,