Skip to content
Snippets Groups Projects
Verified Commit 4ec07d68 authored by Dave Long's avatar Dave Long
Browse files

Issue #3365895 by danflanagan8, benjifisher, mikelutz: When sub_process...

Issue #3365895 by danflanagan8, benjifisher, mikelutz: When sub_process encounters a row skip, it should skip its internal row, and not bubble up to the outer row
parent 91a743c1
No related branches found
No related tags found
27 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3478Issue #3337882: Deleted menus are not removed from content type config,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #97434 passed
Pipeline: drupal

#97436

    ...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
    namespace Drupal\migrate\Plugin\migrate\process; namespace Drupal\migrate\Plugin\migrate\process;
    use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateException;
    use Drupal\migrate\MigrateSkipRowException;
    use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\ProcessPluginBase;
    use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\MigrateExecutableInterface;
    use Drupal\migrate\Row; use Drupal\migrate\Row;
    ...@@ -208,7 +209,12 @@ public function transform($value, MigrateExecutableInterface $migrate_executable ...@@ -208,7 +209,12 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    throw new MigrateException(sprintf("Input array should hold elements of type array, instead element was of type '%s'", gettype($new_value))); throw new MigrateException(sprintf("Input array should hold elements of type array, instead element was of type '%s'", gettype($new_value)));
    } }
    $new_row = new Row($new_value + $source); $new_row = new Row($new_value + $source);
    $migrate_executable->processRow($new_row, $this->configuration['process']); try {
    $migrate_executable->processRow($new_row, $this->configuration['process']);
    }
    catch (MigrateSkipRowException $e) {
    continue;
    }
    $destination = $new_row->getDestination(); $destination = $new_row->getDestination();
    if (array_key_exists('key', $this->configuration)) { if (array_key_exists('key', $this->configuration)) {
    $key = $this->transformKey($key, $migrate_executable, $new_row); $key = $this->transformKey($key, $migrate_executable, $new_row);
    ......
    <?php
    namespace Drupal\Tests\migrate\Kernel\process;
    use Drupal\KernelTests\KernelTestBase;
    use Drupal\migrate\MigrateExecutable;
    use Drupal\migrate\Plugin\MigrationInterface;
    /**
    * Tests process pipelines when a sub_process skips a row or process.
    *
    * @group migrate
    */
    class SubProcessWithSkipTest extends KernelTestBase {
    /**
    * {@inheritdoc}
    */
    protected static $modules = ['migrate'];
    /**
    * Provides the test migration definition.
    *
    * @return array
    */
    public function getDefinition() {
    return [
    'source' => [
    'plugin' => 'embedded_data',
    'data_rows' => [
    [
    'id' => 'skip_test',
    'my_array_of_arrays' => [
    [
    'key_1' => 'foo',
    'key_2' => 'bar',
    ],
    [
    'key_1' => NULL,
    'key_2' => 'baz',
    ],
    ],
    ],
    ],
    'ids' => [
    'id' => ['type' => 'string'],
    ],
    ],
    'process' => [
    'first' => [
    'plugin' => 'default_value',
    'default_value' => 'something outside of sub_process',
    ],
    'second' => [
    'plugin' => 'sub_process',
    'source' => 'my_array_of_arrays',
    'process' => [
    'prop_1' => [
    [
    'plugin' => 'skip_on_empty',
    'source' => 'key_1',
    ],
    // We put a process after skip_on_empty to better test skipping
    // a process.
    [
    'plugin' => 'get',
    'source' => 'key_2',
    ],
    ],
    'prop_2' => 'key_2',
    ],
    ],
    ],
    'destination' => [
    'plugin' => 'config',
    'config_name' => 'migrate_test.settings',
    ],
    ];
    }
    /**
    * Test use of skip_on_empty within sub_process.
    *
    * @dataProvider providerTestSubProcessSkip
    *
    * @param string $method
    * The method to use with skip_on_empty (row or process).
    * @param array $expected_data
    * The expected result of the migration.
    */
    public function testSubProcessSkip(string $method, array $expected_data): void {
    $definition = $this->getDefinition();
    $definition['process']['second']['process']['prop_1'][0]['method'] = $method;
    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
    $executable = new MigrateExecutable($migration);
    $result = $executable->import();
    // Migration needs to succeed before further assertions are made.
    $this->assertSame(MigrationInterface::RESULT_COMPLETED, $result);
    // Compare with expected data.
    $this->assertEquals($expected_data, \Drupal::config('migrate_test.settings')->get());
    }
    /**
    * Data provider for testNotFoundSubProcess().
    *
    * @return array
    */
    public function providerTestSubProcessSkip(): array {
    return [
    'skip row' => [
    'method' => 'row',
    'expected' => [
    'first' => 'something outside of sub_process',
    'second' => [
    [
    'prop_1' => 'bar',
    'prop_2' => 'bar',
    ],
    ],
    ],
    ],
    'skip process' => [
    'method' => 'process',
    'expected' => [
    'first' => 'something outside of sub_process',
    'second' => [
    [
    'prop_1' => 'bar',
    'prop_2' => 'bar',
    ],
    [
    'prop_2' => 'baz',
    ],
    ],
    ],
    ],
    ];
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment