Skip to content

Commit

Permalink
move migration into right context
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Oct 13, 2023
1 parent 478d571 commit 01d68d7
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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'])
Expand Down

0 comments on commit 01d68d7

Please sign in to comment.