Skip to content

Commit 9d37dc2

Browse files
authored
fix: optionType deprecated values (#44)
* fix: optionType deprecated values * fix: unselected option in checkbox list
1 parent 41bcb89 commit 9d37dc2

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Support\Facades\DB;
7+
8+
return new class extends Migration
9+
{
10+
/**
11+
* Run the migrations.
12+
*/
13+
public function up(): void
14+
{
15+
// Get all fields with config containing optionType
16+
$fields = DB::table('fields')
17+
->whereNotNull('config')
18+
->where('config', 'like', '%optionType%')
19+
->get();
20+
21+
foreach ($fields as $field) {
22+
$config = json_decode($field->config, true);
23+
24+
if (isset($config['optionType']) && is_string($config['optionType'])) {
25+
// Convert string to array format
26+
$config['optionType'] = [$config['optionType']];
27+
28+
// Update the field with the corrected config
29+
DB::table('fields')
30+
->where('ulid', $field->ulid)
31+
->update(['config' => json_encode($config)]);
32+
}
33+
}
34+
}
35+
36+
/**
37+
* Reverse the migrations.
38+
*/
39+
public function down(): void
40+
{
41+
// Get all fields with config containing optionType arrays
42+
$fields = DB::table('fields')
43+
->whereNotNull('config')
44+
->where('config', 'like', '%optionType%')
45+
->get();
46+
47+
foreach ($fields as $field) {
48+
$config = json_decode($field->config, true);
49+
50+
if (isset($config['optionType']) && is_array($config['optionType']) && count($config['optionType']) === 1) {
51+
// Convert array back to string format
52+
$config['optionType'] = $config['optionType'][0];
53+
54+
// Update the field with the reverted config
55+
DB::table('fields')
56+
->where('ulid', $field->ulid)
57+
->update(['config' => json_encode($config)]);
58+
}
59+
}
60+
}
61+
};

src/FieldsServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ protected function getMigrations(): array
170170
'create_fields_table',
171171
'change_unique_column_in_fields',
172172
'add_group_column_to_fields_table',
173+
'fix_option_type_string_values_in_fields_table',
173174
];
174175
}
175176
}

0 commit comments

Comments
 (0)