Skip to content

Commit 09d7fbf

Browse files
committed
schema file generation clean up
1 parent 820d6b1 commit 09d7fbf

4 files changed

Lines changed: 66 additions & 4 deletions

File tree

src/Fieldset.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,27 @@ public function restore(?string $path = null): Fieldset
613613
*/
614614
public function save(string $path = null): Fieldset
615615
{
616+
//if there are fields
617+
if (is_array($this->get('fields'))) {
618+
//clean up defaults
619+
foreach ($this->get('fields') as $i => $field) {
620+
//unset root
621+
$this->remove('fields', $i, 'root');
622+
//convert default
623+
if (isset($field['default'])) {
624+
if ($field['default'] === '') {
625+
$this->set('fields', $i, 'default', null);
626+
} else if (is_numeric($field['default'])) {
627+
if (strpos($field['default'], '.') === false) {
628+
$this->set('fields', $i, 'default', (int) $field['default']);
629+
} else {
630+
$this->set('fields', $i, 'default', (float) $field['default']);
631+
}
632+
}
633+
}
634+
}
635+
}
636+
616637
if (is_null($path) || !is_dir($path)) {
617638
$path = static::$path;
618639
}

src/Package/System/SystemPackage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function getInnerJoins(Schema $schema, array $data): array
228228
|| ($isRecursive && isset($data['span'][$primary1]));
229229

230230
$isJoin = (
231-
$many === 1 && (
231+
$many == 1 && (
232232
$data['join'] === 'all' || $data['join'] === 'forward')
233233
)
234234
|| (
@@ -279,7 +279,7 @@ public function getInnerJoins(Schema $schema, array $data): array
279279
$isSpan = isset($data['filter'][$primary1]);
280280

281281
$isJoin = (
282-
$many === 1 && (
282+
$many == 1 && (
283283
$data['join'] === 'all' || $data['join'] === 'reverse')
284284
)
285285
|| (

src/Package/System/events/schema.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
'fields',
4848
'relations',
4949
'suggestion',
50-
'disable',
50+
'disabled',
5151
'placeholder'
5252
];
5353

@@ -369,7 +369,7 @@
369369
'fields',
370370
'relations',
371371
'suggestion',
372-
'disable',
372+
'disabled',
373373
'placeholder'
374374
];
375375

src/Schema.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,47 @@ protected function getTypes(array $field): array
229229
return $types;
230230
}
231231

232+
/**
233+
* Saves the fieldset to file
234+
*
235+
* @return Fieldset
236+
*/
237+
public function save(string $path = null): Fieldset
238+
{
239+
//if there are fields
240+
if (is_array($this->get('fields'))) {
241+
//clean up indexes
242+
foreach ($this->get('fields') as $i => $field) {
243+
if (!isset($field['searchable'])) {
244+
$field['searchable'] = 0;
245+
}
246+
247+
if (!isset($field['filterable'])) {
248+
$field['filterable'] = 0;
249+
}
250+
251+
if (!isset($field['sortable'])) {
252+
$field['sortable'] = 0;
253+
}
254+
255+
$this->set('fields', $i, 'searchable', (int) $field['searchable']);
256+
$this->set('fields', $i, 'filterable', (int) $field['filterable']);
257+
$this->set('fields', $i, 'sortable', (int) $field['sortable']);
258+
}
259+
}
260+
261+
//if there are relations
262+
if (is_array($this->get('relations'))) {
263+
foreach ($this->get('relations') as $i => $relation) {
264+
if (isset($relation['many'])) {
265+
$this->set('relations', $i, 'many', (int) $relation['many']);
266+
}
267+
}
268+
}
269+
270+
return parent::save($path);
271+
}
272+
232273
/**
233274
* Returns fieldset classes that match the given filters
234275
*

0 commit comments

Comments
 (0)