From 01d68d7f74c1e1d9ffb348a8c672bcd8579629ee Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Fri, 13 Oct 2023 12:53:47 +0200 Subject: [PATCH] move migration into right context --- .../Migrations/Version20230908101855.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) rename src/{FormBuilderBundle => }/Migrations/Version20230908101855.php (86%) diff --git a/src/FormBuilderBundle/Migrations/Version20230908101855.php b/src/Migrations/Version20230908101855.php similarity index 86% rename from src/FormBuilderBundle/Migrations/Version20230908101855.php rename to src/Migrations/Version20230908101855.php index 639a3376..4c32e73c 100644 --- a/src/FormBuilderBundle/Migrations/Version20230908101855.php +++ b/src/Migrations/Version20230908101855.php @@ -18,23 +18,25 @@ public function up(Schema $schema): void { $workflowIdMapData = $this->connection->fetchAllAssociative('SELECT id, name FROM formbuilder_output_workflow'); - $workflowIdMap = array_reduce($workflowIdMapData, function ($carry, $data) { + $workflowIdMap = array_reduce($workflowIdMapData, static function ($carry, $data) { $carry[$data['id']] = $data['name']; return $carry; }, []); + $forms = $this->connection->fetchAllAssociative("SELECT id, conditionalLogic FROM formbuilder_forms WHERE conditionalLogic LIKE '%switchOutputWorkflow%'"); foreach ($forms as $form) { - $conditionalLogic = array_map(static function ($logic) use($workflowIdMap) { + $conditionalLogic = array_map(static function ($logic) use ($workflowIdMap) { return [ 'condition' => $logic['condition'], - 'action' => array_map(static function ($action) use($workflowIdMap){ + 'action' => array_map(static function ($action) use ($workflowIdMap) { if ($action['type'] !== 'switchOutputWorkflow') { return $action; } $action['workflowName'] = $workflowIdMap[$action['workflowId']]; unset($action['workflowId']); + return $action; }, $logic['action']) @@ -49,23 +51,25 @@ public function down(Schema $schema): void { $workflowIdMapData = $this->connection->fetchAllAssociative('SELECT id, name FROM formbuilder_output_workflow'); - $workflowIdMap = array_reduce($workflowIdMapData, function ($carry, $data) { + $workflowIdMap = array_reduce($workflowIdMapData, static function ($carry, $data) { $carry[$data['name']] = $data['id']; return $carry; }, []); + $forms = $this->connection->fetchAllAssociative("SELECT id, conditionalLogic FROM formbuilder_forms WHERE conditionalLogic LIKE '%switchOutputWorkflow%'"); foreach ($forms as $form) { - $conditionalLogic = array_map(static function ($logic) use($workflowIdMap) { + $conditionalLogic = array_map(static function ($logic) use ($workflowIdMap) { return [ 'condition' => $logic['condition'], - 'action' => array_map(static function ($action) use($workflowIdMap){ + 'action' => array_map(static function ($action) use ($workflowIdMap) { if ($action['type'] !== 'switchOutputWorkflow') { return $action; } $action['workflowId'] = $workflowIdMap[$action['workflowName']]; unset($action['workflowName']); + return $action; }, $logic['action'])