From a6d7f2c46ed846c1de9d337477aca1cb36f061b9 Mon Sep 17 00:00:00 2001 From: rsatr <108738888+rsatr@users.noreply.github.com> Date: Fri, 27 Jun 2025 14:12:30 +0200 Subject: [PATCH 01/11] Allow pimcore 12 in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9acb6b76..4a78a17a 100755 --- a/composer.json +++ b/composer.json @@ -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" From 8fcb8a7d250c312be090d255790d4cade750b793 Mon Sep 17 00:00:00 2001 From: "m.binerbay" Date: Thu, 11 Sep 2025 16:06:22 +0200 Subject: [PATCH 02/11] Try setting type="json" for configuration and configurationLogic fields --- config/doctrine/model/FormDefinition.orm.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/doctrine/model/FormDefinition.orm.xml b/config/doctrine/model/FormDefinition.orm.xml index 387884d3..87a99ffc 100644 --- a/config/doctrine/model/FormDefinition.orm.xml +++ b/config/doctrine/model/FormDefinition.orm.xml @@ -12,8 +12,8 @@ - - + + From 45a2d9b12d39b0c2e4b337dd4b037cdc50255ea0 Mon Sep 17 00:00:00 2001 From: "m.binerbay" Date: Thu, 11 Sep 2025 17:03:25 +0200 Subject: [PATCH 03/11] Try adding a migration to migrate column data in formbuilder_forms table --- src/Migrations/Version20250911163105.php | 61 ++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/Migrations/Version20250911163105.php diff --git a/src/Migrations/Version20250911163105.php b/src/Migrations/Version20250911163105.php new file mode 100644 index 00000000..6b86c78c --- /dev/null +++ b/src/Migrations/Version20250911163105.php @@ -0,0 +1,61 @@ +addSql(" + UPDATE formbuilder_forms + SET configuration = CASE + WHEN configuration IS NOT NULL AND configuration != '' + THEN JSON_QUOTE(configuration) + ELSE NULL + END, + conditionalLogic = CASE + WHEN conditionalLogic IS NOT NULL AND conditionalLogic != '' + THEN JSON_QUOTE(conditionalLogic) + ELSE NULL + END; + "); + + // Then change the column types + $table = $schema->getTable('formbuilder_forms'); + + if ($table->hasColumn('configuration')) { + $table->changeColumn('configuration', [ + 'type' => \Doctrine\DBAL\Types\Types::JSON, + 'notnull' => false, + 'comment' => null + ]); + } + + if ($table->hasColumn('conditionalLogic')) { + $table->changeColumn('conditionalLogic', [ + 'type' => \Doctrine\DBAL\Types\Types::JSON, + 'notnull' => false, + 'comment' => null + ]); + } + } + + public function down(Schema $schema): void + { + // This migration is not reversible as we're converting serialized data to JSON + $this->throwIrreversibleMigrationException(); + } +} From bb41e2b59a7e0d9f5338735f24ed90a0766ff411 Mon Sep 17 00:00:00 2001 From: "m.binerbay" Date: Thu, 11 Sep 2025 17:58:02 +0200 Subject: [PATCH 04/11] Update formbuilder_output_workflow and formbuilder_output_workflow_channel columns from object type to json type --- config/doctrine/model/OutputWorkflow.orm.xml | 2 +- config/doctrine/model/OutputWorkflowChannel.orm.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/doctrine/model/OutputWorkflow.orm.xml b/config/doctrine/model/OutputWorkflow.orm.xml index fb1cc614..6cabdab0 100644 --- a/config/doctrine/model/OutputWorkflow.orm.xml +++ b/config/doctrine/model/OutputWorkflow.orm.xml @@ -11,7 +11,7 @@ - + diff --git a/config/doctrine/model/OutputWorkflowChannel.orm.xml b/config/doctrine/model/OutputWorkflowChannel.orm.xml index 0df61746..5ad71956 100644 --- a/config/doctrine/model/OutputWorkflowChannel.orm.xml +++ b/config/doctrine/model/OutputWorkflowChannel.orm.xml @@ -11,8 +11,8 @@ - - + + From 5c13a94312eddf756654607dc278cbe629830c18 Mon Sep 17 00:00:00 2001 From: "m.binerbay" Date: Thu, 11 Sep 2025 17:58:18 +0200 Subject: [PATCH 05/11] Update migration to support migrating all tables --- src/Migrations/Version20250911163105.php | 87 +++++++++++++++--------- 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/src/Migrations/Version20250911163105.php b/src/Migrations/Version20250911163105.php index 6b86c78c..e631208f 100644 --- a/src/Migrations/Version20250911163105.php +++ b/src/Migrations/Version20250911163105.php @@ -13,43 +13,66 @@ class Version20250911163105 extends AbstractMigration implements ContainerAwareI public function getDescription(): string { - return 'Migrate formbuilder_forms.configuration and formbuilder_forms.conditionalLogic data from object to json format'; + return 'Migrate all formbuilder object type columns to json format'; } public function up(Schema $schema): void { - // First migrate the data - $this->addSql(" - UPDATE formbuilder_forms - SET configuration = CASE - WHEN configuration IS NOT NULL AND configuration != '' - THEN JSON_QUOTE(configuration) - ELSE NULL - END, - conditionalLogic = CASE - WHEN conditionalLogic IS NOT NULL AND conditionalLogic != '' - THEN JSON_QUOTE(conditionalLogic) - ELSE NULL - END; - "); - - // Then change the column types - $table = $schema->getTable('formbuilder_forms'); - - if ($table->hasColumn('configuration')) { - $table->changeColumn('configuration', [ - 'type' => \Doctrine\DBAL\Types\Types::JSON, - 'notnull' => false, - 'comment' => null - ]); - } + $connection = $this->connection; + + // 1. Migrate formbuilder_forms table + $this->migrateTable($connection, 'formbuilder_forms', ['configuration', 'conditionalLogic']); + + // 2. Migrate formbuilder_output_workflow table + $this->migrateTable($connection, 'formbuilder_output_workflow', ['success_management']); + + // 3. Migrate formbuilder_output_workflow_channel table + $this->migrateTable($connection, 'formbuilder_output_workflow_channel', ['configuration', 'funnel_actions']); + + // 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'); + } + + private function migrateTable($connection, $tableName, $columns): void + { + $columnList = implode(', ', $columns); + $conditions = array_map(fn($col) => "$col IS NOT NULL", $columns); + $whereClause = implode(' OR ', $conditions); + + $result = $connection->executeQuery("SELECT id, $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); + } else { + // If unserialization fails, store as JSON string + $updates[] = "$column = ?"; + $values[] = json_encode($row[$column]); + } + } else { + $updates[] = "$column = ?"; + $values[] = null; + } + } - if ($table->hasColumn('conditionalLogic')) { - $table->changeColumn('conditionalLogic', [ - 'type' => \Doctrine\DBAL\Types\Types::JSON, - 'notnull' => false, - 'comment' => null - ]); + if (!empty($updates)) { + $values[] = $row['id']; + $connection->executeStatement( + "UPDATE $tableName SET " . implode(', ', $updates) . ' WHERE id = ?', + $values + ); + } } } From dae90b8b1bbf8bcc7c6084842bdc6c23d43c6d99 Mon Sep 17 00:00:00 2001 From: "m.binerbay" Date: Fri, 12 Sep 2025 11:13:12 +0200 Subject: [PATCH 06/11] Update migration script to handle [] and {} values --- src/Migrations/Version20250911163105.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Migrations/Version20250911163105.php b/src/Migrations/Version20250911163105.php index e631208f..78e97dd5 100644 --- a/src/Migrations/Version20250911163105.php +++ b/src/Migrations/Version20250911163105.php @@ -53,14 +53,20 @@ private function migrateTable($connection, $tableName, $columns): void if (!empty($row[$column])) { $unserialized = @unserialize($row[$column]); if ($unserialized !== false) { + // Successfully unserialized (could be empty array, object, etc.) $updates[] = "$column = ?"; $values[] = json_encode($unserialized); - } else { - // If unserialization fails, store as JSON string + } elseif ($row[$column] === '[]') { + // Handle literal "[]" string as empty array $updates[] = "$column = ?"; - $values[] = json_encode($row[$column]); + $values[] = '[]'; + } elseif ($row[$column] === '{}') { + // Handle literal "{}" string as empty object + $updates[] = "$column = ?"; + $values[] = '{}'; } } else { + // Handle null and empty string cases $updates[] = "$column = ?"; $values[] = null; } From f6b80fa7dd301e3afffdc468939fee46e3dc119c Mon Sep 17 00:00:00 2001 From: "m.binerbay" Date: Fri, 12 Sep 2025 11:59:21 +0200 Subject: [PATCH 07/11] Change getSnippetId to int to because Document::getById requires an int param now --- src/Form/Type/SnippetType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/Type/SnippetType.php b/src/Form/Type/SnippetType.php index ad810e0e..3b642ca6 100644 --- a/src/Form/Type/SnippetType.php +++ b/src/Form/Type/SnippetType.php @@ -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(); From a227085451cf1e5165be6092bab20766575e61b9 Mon Sep 17 00:00:00 2001 From: "m.binerbay" Date: Fri, 12 Sep 2025 13:59:07 +0200 Subject: [PATCH 08/11] Remove comments --- src/Migrations/Version20250911163105.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Migrations/Version20250911163105.php b/src/Migrations/Version20250911163105.php index 78e97dd5..bb9e34b5 100644 --- a/src/Migrations/Version20250911163105.php +++ b/src/Migrations/Version20250911163105.php @@ -20,13 +20,8 @@ public function up(Schema $schema): void { $connection = $this->connection; - // 1. Migrate formbuilder_forms table $this->migrateTable($connection, 'formbuilder_forms', ['configuration', 'conditionalLogic']); - - // 2. Migrate formbuilder_output_workflow table $this->migrateTable($connection, 'formbuilder_output_workflow', ['success_management']); - - // 3. Migrate formbuilder_output_workflow_channel table $this->migrateTable($connection, 'formbuilder_output_workflow_channel', ['configuration', 'funnel_actions']); // Change column types to JSON @@ -53,20 +48,16 @@ private function migrateTable($connection, $tableName, $columns): void if (!empty($row[$column])) { $unserialized = @unserialize($row[$column]); if ($unserialized !== false) { - // Successfully unserialized (could be empty array, object, etc.) $updates[] = "$column = ?"; $values[] = json_encode($unserialized); } elseif ($row[$column] === '[]') { - // Handle literal "[]" string as empty array $updates[] = "$column = ?"; $values[] = '[]'; } elseif ($row[$column] === '{}') { - // Handle literal "{}" string as empty object $updates[] = "$column = ?"; $values[] = '{}'; } } else { - // Handle null and empty string cases $updates[] = "$column = ?"; $values[] = null; } @@ -84,7 +75,7 @@ private function migrateTable($connection, $tableName, $columns): void public function down(Schema $schema): void { - // This migration is not reversible as we're converting serialized data to JSON + // This migration is not reversible because we are converting serialized data to JSON $this->throwIrreversibleMigrationException(); } } From 7f314184055b2f6d54e246768832b51b72f30d07 Mon Sep 17 00:00:00 2001 From: "m.binerbay" Date: Wed, 17 Sep 2025 14:57:37 +0200 Subject: [PATCH 09/11] Switch type="array" to "json" --- config/doctrine/model/DoubleOptInSession.orm.xml | 2 +- src/Migrations/Version20250911163105.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config/doctrine/model/DoubleOptInSession.orm.xml b/config/doctrine/model/DoubleOptInSession.orm.xml index 102e535e..181c0447 100644 --- a/config/doctrine/model/DoubleOptInSession.orm.xml +++ b/config/doctrine/model/DoubleOptInSession.orm.xml @@ -11,7 +11,7 @@ - + diff --git a/src/Migrations/Version20250911163105.php b/src/Migrations/Version20250911163105.php index bb9e34b5..3db8a5c3 100644 --- a/src/Migrations/Version20250911163105.php +++ b/src/Migrations/Version20250911163105.php @@ -23,6 +23,7 @@ public function up(Schema $schema): void $this->migrateTable($connection, 'formbuilder_forms', ['configuration', 'conditionalLogic']); $this->migrateTable($connection, 'formbuilder_output_workflow', ['success_management']); $this->migrateTable($connection, 'formbuilder_output_workflow_channel', ['configuration', 'funnel_actions']); + $this->migrateTable($connection, 'formbuilder_double_opt_in_session', ['additionalData']); // Change column types to JSON $this->addSql('ALTER TABLE formbuilder_forms MODIFY COLUMN configuration JSON'); @@ -30,6 +31,7 @@ public function up(Schema $schema): void $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 additionalData JSON'); } private function migrateTable($connection, $tableName, $columns): void From 8a308daca7fcdee5c5f11ec189885001aa3900b0 Mon Sep 17 00:00:00 2001 From: "m.binerbay" Date: Wed, 17 Sep 2025 15:07:36 +0200 Subject: [PATCH 10/11] Fix column name formbuilder_double_opt_in_session.additional_data --- src/Migrations/Version20250911163105.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Migrations/Version20250911163105.php b/src/Migrations/Version20250911163105.php index 3db8a5c3..5979af42 100644 --- a/src/Migrations/Version20250911163105.php +++ b/src/Migrations/Version20250911163105.php @@ -23,7 +23,7 @@ public function up(Schema $schema): void $this->migrateTable($connection, 'formbuilder_forms', ['configuration', 'conditionalLogic']); $this->migrateTable($connection, 'formbuilder_output_workflow', ['success_management']); $this->migrateTable($connection, 'formbuilder_output_workflow_channel', ['configuration', 'funnel_actions']); - $this->migrateTable($connection, 'formbuilder_double_opt_in_session', ['additionalData']); + $this->migrateTable($connection, 'formbuilder_double_opt_in_session', ['additional_data']); // Change column types to JSON $this->addSql('ALTER TABLE formbuilder_forms MODIFY COLUMN configuration JSON'); From 833d4d8e57b2cf98b0c2cd2668b12125c0acea7e Mon Sep 17 00:00:00 2001 From: "m.binerbay" Date: Thu, 25 Sep 2025 13:54:22 +0200 Subject: [PATCH 11/11] Fix migration for formbuilder_double_opt_in_session --- src/Migrations/Version20250911163105.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Migrations/Version20250911163105.php b/src/Migrations/Version20250911163105.php index 5979af42..e63d3fab 100644 --- a/src/Migrations/Version20250911163105.php +++ b/src/Migrations/Version20250911163105.php @@ -20,10 +20,10 @@ public function up(Schema $schema): void { $connection = $this->connection; - $this->migrateTable($connection, 'formbuilder_forms', ['configuration', 'conditionalLogic']); - $this->migrateTable($connection, 'formbuilder_output_workflow', ['success_management']); - $this->migrateTable($connection, 'formbuilder_output_workflow_channel', ['configuration', 'funnel_actions']); - $this->migrateTable($connection, 'formbuilder_double_opt_in_session', ['additional_data']); + $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'); @@ -31,16 +31,16 @@ public function up(Schema $schema): void $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 additionalData JSON'); + $this->addSql('ALTER TABLE formbuilder_double_opt_in_session MODIFY COLUMN additional_data JSON'); } - private function migrateTable($connection, $tableName, $columns): void + 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 id, $columnList FROM $tableName WHERE $whereClause"); + $result = $connection->executeQuery("SELECT $primaryKey, $columnList FROM $tableName WHERE $whereClause"); while ($row = $result->fetchAssociative()) { $updates = []; @@ -66,9 +66,9 @@ private function migrateTable($connection, $tableName, $columns): void } if (!empty($updates)) { - $values[] = $row['id']; + $values[] = $row[$primaryKey]; $connection->executeStatement( - "UPDATE $tableName SET " . implode(', ', $updates) . ' WHERE id = ?', + "UPDATE $tableName SET " . implode(', ', $updates) . " WHERE $primaryKey = ?", $values ); }