2024-04-16 23:15:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
2024-04-17 10:53:59 +02:00
|
|
|
use Illuminate\Support\Collection;
|
2024-04-16 23:15:05 +02:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
return new class extends Migration
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function up()
|
|
|
|
{
|
|
|
|
foreach (DB::table('forms')->get() as $event) {
|
|
|
|
$config = json_decode($event->config);
|
|
|
|
$config->sections = array_map(function ($section) {
|
2024-04-17 10:53:59 +02:00
|
|
|
/** @var Collection<int, mixed> */
|
|
|
|
$fields = $section->fields;
|
|
|
|
$section->fields = collect($fields)->map(function ($field) {
|
2024-04-16 23:15:05 +02:00
|
|
|
if ($field->type === 'DropdownField' || $field->type === 'RadioField') {
|
|
|
|
$field->allowcustom = false;
|
|
|
|
}
|
|
|
|
return $field;
|
|
|
|
})->all();
|
|
|
|
|
|
|
|
return $section;
|
|
|
|
}, $config->sections);
|
|
|
|
DB::table('forms')->where('id', $event->id)->update(['config' => json_encode($config)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (DB::table('formtemplates')->get() as $event) {
|
|
|
|
$config = json_decode($event->config);
|
|
|
|
$config->sections = array_map(function ($section) {
|
2024-04-17 10:53:59 +02:00
|
|
|
/** @var Collection<int, mixed> */
|
|
|
|
$fields = $section->fields;
|
|
|
|
$section->fields = collect($fields)->map(function ($field) {
|
2024-04-16 23:15:05 +02:00
|
|
|
if ($field->type === 'DropdownField' || $field->type === 'RadioField') {
|
|
|
|
$field->allowcustom = false;
|
|
|
|
}
|
|
|
|
return $field;
|
|
|
|
})->all();
|
|
|
|
|
|
|
|
return $section;
|
|
|
|
}, $config->sections);
|
|
|
|
DB::table('formtemplates')->where('id', $event->id)->update(['config' => json_encode($config)]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function down()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
};
|