Loading src/Plugin/migrate/process/IfCondition.php +15 −9 Original line number Diff line number Diff line Loading @@ -168,18 +168,24 @@ class IfCondition extends ProcessPluginWithConditionBase { */ protected function doConditionalProcess($config_key, $value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $conditional_process[$destination_property] = $this->configuration[$config_key]; // If the source is not explicitly defined, in do_process or else_process, // we use the course from the if_condition plugin. // Clone the row so we can use ::processRow without affecting it. $dummy_row = clone($row); // Determine which notation for the process pipleine is being used. if (array_key_exists(0, $conditional_process[$destination_property])) { if (!isset($conditional_process[$destination_property][0]['source']) && isset($this->configuration['source'])) { $conditional_process[$destination_property][0]['source'] = $this->configuration['source']; // Numerical keys. Likely multiple process plugins in the pipeline. $first_process =& $conditional_process[$destination_property][0]; } else { $first_process =& $conditional_process[$destination_property]; } elseif (!isset($conditional_process[$destination_property]['source']) && isset($this->configuration['source'])) { $conditional_process[$destination_property]['source'] = $this->configuration['source']; // If the source is not set, we make a temp value on the dummy row. if (!isset($first_process['source'])) { $dummy_row->setDestinationProperty('_if_condition_temp', $value); $first_process['source'] = '@_if_condition_temp'; } $migrate_executable->processRow($row, $conditional_process); return $row->getDestinationProperty($destination_property); $migrate_executable->processRow($dummy_row, $conditional_process); return $dummy_row->getDestinationProperty($destination_property); } } tests/src/Kernel/IfConditionTest.php +30 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,34 @@ class IfConditionTest extends KernelTestBase { 'source' => '@dest_value_2', ], ], // This one tests when if_condition is in the middle of a pipeline. // In this case, source is not set anywhere within if_condition. 'dest_value_5' => [ [ 'plugin' => 'get', 'source' => 'my_source', ], [ 'plugin' => 'if_condition', 'condition' => 'not:empty', 'do_process' => [ 'plugin' => 'callback', 'callable' => 'strtoupper' ], ], [ 'plugin' => 'callback', 'callable' => 'strrev', ], [ 'plugin' => 'skip_on_condition', 'condition' => [ 'plugin' => 'equals', 'value' => strrev(strtoupper('this makes migrate fun')), ], 'method' => 'process', ], ], ], 'destination' => [ 'plugin' => 'config', Loading Loading @@ -167,6 +195,7 @@ class IfConditionTest extends KernelTestBase { 'dest_value_2' => 'hamburger', 'dest_value_3' => 'This is a test', 'dest_value_4' => 'hamburger', 'dest_value_5' => strrev(strtoupper('this is a test')), ], ], [ Loading @@ -183,6 +212,7 @@ class IfConditionTest extends KernelTestBase { 'dest_value_2' => 'HI, FRIEND.', 'dest_value_3' => 'THIS MAKES MIGRATE FUN', 'dest_value_4' => 'THIS MAKES MIGRATE FUN', // 'dest_value_5' should be skipped. ], ], ]; Loading Loading
src/Plugin/migrate/process/IfCondition.php +15 −9 Original line number Diff line number Diff line Loading @@ -168,18 +168,24 @@ class IfCondition extends ProcessPluginWithConditionBase { */ protected function doConditionalProcess($config_key, $value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $conditional_process[$destination_property] = $this->configuration[$config_key]; // If the source is not explicitly defined, in do_process or else_process, // we use the course from the if_condition plugin. // Clone the row so we can use ::processRow without affecting it. $dummy_row = clone($row); // Determine which notation for the process pipleine is being used. if (array_key_exists(0, $conditional_process[$destination_property])) { if (!isset($conditional_process[$destination_property][0]['source']) && isset($this->configuration['source'])) { $conditional_process[$destination_property][0]['source'] = $this->configuration['source']; // Numerical keys. Likely multiple process plugins in the pipeline. $first_process =& $conditional_process[$destination_property][0]; } else { $first_process =& $conditional_process[$destination_property]; } elseif (!isset($conditional_process[$destination_property]['source']) && isset($this->configuration['source'])) { $conditional_process[$destination_property]['source'] = $this->configuration['source']; // If the source is not set, we make a temp value on the dummy row. if (!isset($first_process['source'])) { $dummy_row->setDestinationProperty('_if_condition_temp', $value); $first_process['source'] = '@_if_condition_temp'; } $migrate_executable->processRow($row, $conditional_process); return $row->getDestinationProperty($destination_property); $migrate_executable->processRow($dummy_row, $conditional_process); return $dummy_row->getDestinationProperty($destination_property); } }
tests/src/Kernel/IfConditionTest.php +30 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,34 @@ class IfConditionTest extends KernelTestBase { 'source' => '@dest_value_2', ], ], // This one tests when if_condition is in the middle of a pipeline. // In this case, source is not set anywhere within if_condition. 'dest_value_5' => [ [ 'plugin' => 'get', 'source' => 'my_source', ], [ 'plugin' => 'if_condition', 'condition' => 'not:empty', 'do_process' => [ 'plugin' => 'callback', 'callable' => 'strtoupper' ], ], [ 'plugin' => 'callback', 'callable' => 'strrev', ], [ 'plugin' => 'skip_on_condition', 'condition' => [ 'plugin' => 'equals', 'value' => strrev(strtoupper('this makes migrate fun')), ], 'method' => 'process', ], ], ], 'destination' => [ 'plugin' => 'config', Loading Loading @@ -167,6 +195,7 @@ class IfConditionTest extends KernelTestBase { 'dest_value_2' => 'hamburger', 'dest_value_3' => 'This is a test', 'dest_value_4' => 'hamburger', 'dest_value_5' => strrev(strtoupper('this is a test')), ], ], [ Loading @@ -183,6 +212,7 @@ class IfConditionTest extends KernelTestBase { 'dest_value_2' => 'HI, FRIEND.', 'dest_value_3' => 'THIS MAKES MIGRATE FUN', 'dest_value_4' => 'THIS MAKES MIGRATE FUN', // 'dest_value_5' should be skipped. ], ], ]; Loading