Skip to content

Comments

Migrate tamper#11

Open
MegaChriz wants to merge 7 commits into8.x-1.xfrom
migrate_tamper
Open

Migrate tamper#11
MegaChriz wants to merge 7 commits into8.x-1.xfrom
migrate_tamper

Conversation

@MegaChriz
Copy link
Collaborator

Problem/Motivation

This connects Tamper with Migrate process plugins. This way Tamper plugins can be applied in migrations. And it is useful while developing the process plugin UI. We can see how Tamper forms will appear in this UI.

I'm not sure however if this code should be part of Feeds Migrate, as the code doesn't depend on any other code in Feeds Migrate. It can work with Migrate on its own.

Proposed solution

The solution provides the following:

  • A process plugin called 'Tamper'. This depends on a derivative.
  • A derivative that generates a process plugin for every tamper plugin.
  • An adapter, that wraps a Migrate Row in tamperable item, so Tamper can operate on a Migrate Row.

I've tested the code with one Tamper plugin - Find replace regex - and found that that one works. There is however no test coverage yet, so I'm not sure if all plugins work correctly. Some Tamper plugins expect an array as input for example, other plugins throw exceptions to indicate an item should be skipped.

Example/QA

Example for applying the tamper plugin "Find replace regex":

  body/value:
    -
      plugin: single_value
      source: body
    -
      plugin: skip_on_empty
      method: process
    -
      plugin: extract
      source: body
      index:
        - 0
        - value
    -
      plugin: 'tamper:find_replace_regex'
      find: '/\<p\>(&nbsp;)?\s*\<\/p\>\s*/'
      replace: ''

@MegaChriz
Copy link
Collaborator Author

I think something went wrong with rebasing. The code is currently in one commit, not 7.

@Thangaraj-DialedIn
Copy link

Thangaraj-DialedIn commented Jun 17, 2020

Hi MegaChriz ,

  1. I'm installed the Fresh drupal-8.8.6 site.
  2. Tested the migrations with the following tamper plugins.
  • find_replace
  • math
  • country_to_code
  • find_replace_regex

All the tamper plugins are working well as expected.

Here is the example yml file I used,

id: migrate_tamper_test
label: 'Migrate Tamper Test'
source:
  plugin: embedded_data
  data_rows:
    -
      unique_id: 1
      creative_title: 'The versatility of Drupal fields'
      engaging_content: 'Fields are Drupal''s atomic data storage mechanism...'
    -
      unique_id: 2
      creative_title: 'What is a view in Drupal? How do they work?'
      engaging_content: 'In Drupal, a view is a listing of information. It can a list of nodes, users, comments, taxonomy terms, files, etc...'
  ids:
    unique_id:
      type: integer

process:
  title: creative_title
  body/value:
    plugin: 'tamper:find_replace_regex'
    find: '/\<p\>(&nbsp;)?\s*\<\/p\>\s*/'
    replace: ''
    source: engaging_content
destination:
  plugin: 'entity:node'
  default_bundle: page

Let me know your comments.

Thanks.

@MegaChriz
Copy link
Collaborator Author

Thanks for testing so far!

If you like, maybe you want to test the following plugins as well, because these are more complicated and thus more likely to not work correctly:

  • Explode
  • Implode
  • Rewrite
  • Required
  • Keyword Filter
  • Unique
  • Array Filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants