diff --git a/src/Migrations/Version20230908101855.php b/src/Migrations/Version20230908101855.php index b1442f3e..c0264210 100644 --- a/src/Migrations/Version20230908101855.php +++ b/src/Migrations/Version20230908101855.php @@ -29,29 +29,52 @@ public function up(Schema $schema): void $conditionalLogic = array_map(static function ($logic) use ($workflowIdMap) { return [ - 'condition' => array_map(static function ($condition) use ($workflowIdMap) { - if ($condition['type'] !== 'outputWorkflow') { - return $condition; - } + 'condition' => array_filter( + array_map(static function ($condition) use ($workflowIdMap) { + if ($condition['type'] !== 'outputWorkflow') { + return $condition; + } - foreach ($condition['outputWorkflows'] as $index => $outputWorkflowId) { - $condition['outputWorkflows'][$index] = $workflowIdMap[$outputWorkflowId]; - } + $condition['outputWorkflows'][0] = 21; + $condition['outputWorkflows'][1] = 1; - return $condition; + foreach ($condition['outputWorkflows'] as $index => $outputWorkflowId) { - }, $logic['condition']), - 'action' => array_map(static function ($action) use ($workflowIdMap) { - if ($action['type'] !== 'switchOutputWorkflow') { - return $action; - } + if (!isset($workflowIdMap[$outputWorkflowId])) { + unset($condition['outputWorkflows'][$index]); + continue; + } - $action['workflowName'] = $workflowIdMap[$action['workflowId']]; - unset($action['workflowId']); + $condition['outputWorkflows'][$index] = $workflowIdMap[$outputWorkflowId]; + } - return $action; + if (count($condition['outputWorkflows']) === 0) { + return null; + } - }, $logic['action']) + $condition['outputWorkflows'] = array_values($condition['outputWorkflows']); + + return $condition; + + }, $logic['condition']) + ), + 'action' => array_filter( + array_map(static function ($action) use ($workflowIdMap) { + if ($action['type'] !== 'switchOutputWorkflow') { + return $action; + } + + if (!isset($workflowIdMap[$action['workflowId']])) { + return null; + } + + $action['workflowName'] = $workflowIdMap[$action['workflowId']]; + unset($action['workflowId']); + + return $action; + + }, $logic['action']) + ) ]; }, unserialize($form['conditionalLogic']));