Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"require": {
"php": "^8.2",
"pimcore/pimcore": "^11.0",
"pimcore/pimcore": "^12.0",
"symfony/form": "^6.4",
"symfony/intl": "^6.4",
"doctrine/orm": "^2.7 || ^3.0"
Expand Down
2 changes: 1 addition & 1 deletion config/doctrine/model/DoubleOptInSession.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<custom-id-generator class="Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator"/>
</id>
<field name="email" type="string" column="email" length="190" nullable="false"/>
<field name="additionalData" type="array" column="additional_data" nullable="true"/>
<field name="additionalData" type="json" column="additional_data" nullable="true"/>
<field name="dispatchLocation" type="text" column="dispatch_location" nullable="true"/>
<field name="applied" type="boolean" column="applied">
<options>
Expand Down
4 changes: 2 additions & 2 deletions config/doctrine/model/FormDefinition.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<field name="modificationDate" type="datetime" column="modificationDate" nullable="false"/>
<field name="createdBy" type="integer" column="createdBy"/>
<field name="modifiedBy" type="integer" column="modifiedBy"/>
<field name="configuration" type="object" column="configuration" nullable="true"/>
<field name="conditionalLogic" type="object" column="conditionalLogic" nullable="true"/>
<field name="configuration" type="json" column="configuration" nullable="true"/>
<field name="conditionalLogic" type="json" column="conditionalLogic" nullable="true"/>
<field name="fields" type="form_builder_fields" column="fields" nullable="true"/>
<one-to-many field="outputWorkflows" target-entity="FormBuilderBundle\Model\OutputWorkflow" mapped-by="formDefinition"
fetch="LAZY">
Expand Down
2 changes: 1 addition & 1 deletion config/doctrine/model/OutputWorkflow.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</id>
<field name="name" type="string" column="`name`" length="190" nullable="true"/>
<field name="funnelWorkflow" type="boolean" column="funnel_workflow" nullable="false"/>
<field name="successManagement" type="object" column="success_management" nullable="true"/>
<field name="successManagement" type="json" column="success_management" nullable="true"/>
<one-to-many field="channels" target-entity="FormBuilderBundle\Model\OutputWorkflowChannel" mapped-by="outputWorkflow"
orphan-removal="true" fetch="LAZY">
<cascade>
Expand Down
4 changes: 2 additions & 2 deletions config/doctrine/model/OutputWorkflowChannel.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</id>
<field name="type" type="string" column="type" length="190"/>
<field name="name" type="string" column="name" length="190"/>
<field name="configuration" type="object" column="configuration" nullable="true"/>
<field name="funnelActions" type="object" column="funnel_actions" nullable="true"/>
<field name="configuration" type="json" column="configuration" nullable="true"/>
<field name="funnelActions" type="json" column="funnel_actions" nullable="true"/>
<many-to-one field="outputWorkflow" target-entity="FormBuilderBundle\Model\OutputWorkflow" inversed-by="channels"
fetch="LAZY">
<join-columns>
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/SnippetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function buildView(FormView $view, FormInterface $form, array $options):
$view->vars = $vars;
}

private function getSnippetId(array $data): ?string
private function getSnippetId(array $data): ?int
{
$locale = $this->requestStack->getMainRequest()->getLocale();

Expand Down
83 changes: 83 additions & 0 deletions src/Migrations/Version20250911163105.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace FormBuilderBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class Version20250911163105 extends AbstractMigration implements ContainerAwareInterface
{
use ContainerAwareTrait;

public function getDescription(): string
{
return 'Migrate all formbuilder object type columns to json format';
}

public function up(Schema $schema): void
{
$connection = $this->connection;

$this->migrateTable($connection, 'formbuilder_forms', ['configuration', 'conditionalLogic'], 'id');
$this->migrateTable($connection, 'formbuilder_output_workflow', ['success_management'], 'id');
$this->migrateTable($connection, 'formbuilder_output_workflow_channel', ['configuration', 'funnel_actions'], 'id');
$this->migrateTable($connection, 'formbuilder_double_opt_in_session', ['additional_data'], 'token');

// Change column types to JSON
$this->addSql('ALTER TABLE formbuilder_forms MODIFY COLUMN configuration JSON');
$this->addSql('ALTER TABLE formbuilder_forms MODIFY COLUMN conditionalLogic JSON');
$this->addSql('ALTER TABLE formbuilder_output_workflow MODIFY COLUMN success_management JSON');
$this->addSql('ALTER TABLE formbuilder_output_workflow_channel MODIFY COLUMN configuration JSON');
$this->addSql('ALTER TABLE formbuilder_output_workflow_channel MODIFY COLUMN funnel_actions JSON');
$this->addSql('ALTER TABLE formbuilder_double_opt_in_session MODIFY COLUMN additional_data JSON');
}

private function migrateTable($connection, $tableName, $columns, $primaryKey = 'id'): void
{
$columnList = implode(', ', $columns);
$conditions = array_map(fn($col) => "$col IS NOT NULL", $columns);
$whereClause = implode(' OR ', $conditions);

$result = $connection->executeQuery("SELECT $primaryKey, $columnList FROM $tableName WHERE $whereClause");

while ($row = $result->fetchAssociative()) {
$updates = [];
$values = [];

foreach ($columns as $column) {
if (!empty($row[$column])) {
$unserialized = @unserialize($row[$column]);
if ($unserialized !== false) {
$updates[] = "$column = ?";
$values[] = json_encode($unserialized);
} elseif ($row[$column] === '[]') {
$updates[] = "$column = ?";
$values[] = '[]';
} elseif ($row[$column] === '{}') {
$updates[] = "$column = ?";
$values[] = '{}';
}
} else {
$updates[] = "$column = ?";
$values[] = null;
}
}

if (!empty($updates)) {
$values[] = $row[$primaryKey];
$connection->executeStatement(
"UPDATE $tableName SET " . implode(', ', $updates) . " WHERE $primaryKey = ?",
$values
);
}
}
}

public function down(Schema $schema): void
{
// This migration is not reversible because we are converting serialized data to JSON
$this->throwIrreversibleMigrationException();
}
}