Skip to content

Commit

Permalink
Fix: Migration to ensure compatibility with Symfony 5 for nested fiel…
Browse files Browse the repository at this point in the history
…ds (#433)
  • Loading branch information
patkul0 authored Feb 9, 2024
1 parent 7430ff5 commit 3b63b64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Upgrade Notes

## 4.5.2
- **[BUGFIX]**: Fix element type check in api channel [@patkul0](https://github.com/dachcom-digital/pimcore-formbuilder/pull/433)

## 4.5.1
- **[BUGFIX]**: Fix element type check in api channel [#423](https://github.com/dachcom-digital/pimcore-formbuilder/issues/423)

Expand Down
17 changes: 8 additions & 9 deletions src/FormBuilderBundle/Migrations/Version20211011171530.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public function up(Schema $schema): void

$configuration = $data['config'] ?? [];
$conditionalLogic = $data['conditional_logic'] ?? [];
$fields = $data['fields'] ?? [];

$fixedFields = $this->ensureSymfony5Compatibility($fields);
$fields = $data['fields'] ?? [];
$this->ensureSymfony5Compatibility($fields);

$this->addSql(sprintf('UPDATE formbuilder_forms SET `configuration` = "%s" WHERE `id` = %d', addslashes(serialize($configuration)), $formDefinitionId));
$this->addSql(sprintf('UPDATE formbuilder_forms SET `conditionalLogic` = "%s" WHERE `id` = %d', addslashes(serialize($conditionalLogic)), $formDefinitionId));
$this->addSql(sprintf('UPDATE formbuilder_forms SET `fields` = "%s" WHERE `id` = %d', addslashes(serialize($fixedFields)), $formDefinitionId));
$this->addSql(sprintf('UPDATE formbuilder_forms SET `fields` = "%s" WHERE `id` = %d', addslashes(serialize($fields)), $formDefinitionId));
}
}

Expand All @@ -70,10 +70,9 @@ public function down(Schema $schema): void
// disabled
}

private function ensureSymfony5Compatibility(array $fields): array
private function ensureSymfony5Compatibility(array &$fields): void
{
$fixedFields = [];
foreach ($fields as $field) {
foreach ($fields as &$field) {
if ($field['type'] === 'choice') {
$this->fixChoiceField($field);
}
Expand All @@ -82,10 +81,10 @@ private function ensureSymfony5Compatibility(array $fields): array
$this->fixConstraints($field);
}

$fixedFields[] = $field;
if (isset($field['fields']) && is_array($field['fields'])) {
$this->ensureSymfony5Compatibility($field['fields']);
}
}

return $fixedFields;
}

private function fixChoiceField(array &$field): void
Expand Down

0 comments on commit 3b63b64

Please sign in to comment.