Problem/Motivation

When using the Rewrite plugin after an other plugin, the source value on the item remains unchanged. That's because Feeds Tamper currently writes the tampered value back to the item after all tampers have been applied.

Say for example you have the following value on a source field called "WORK_PHONE":

123/456-7890

And you want that to transform to:

(123)456-7890

If you apply a plugin first that replaces a slash with a close bracket and then apply the Rewrite plugin after that, in the end result what the first applied tamper had done is lost. You'll get "(123/456-7890" instead of "(123)456-7890".

Steps to reproduce

  1. Have a source item with the following values:
    • WORK_PHONE: 123/456-7890
  2. Configure the following tampers for the source "WORK_PHONE":
    • Find replace:
      • Text to find: /
      • Text to replace: )
    • Rewrite:
      • Replacement pattern: ([WORK_PHONE]
  3. Run the Feeds import

Expected result: (123)456-7890

Actual result: (123/456-7890

Proposed resolution

In FeedsSubscriber, write back the value to the item after each applied Tamper plugin (instead of doing this after the whole chain of Tamper plugins are applied).

Remaining tasks

  • Work out the source of the problem.
  • Fix the problem.
  • Review/Merge

User interface changes

None

API changes

None

Data model changes

None

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Issue fork tamper-3323381

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

DamienMcKenna created an issue. See original summary.

damienmckenna’s picture

I ended up changing the output format so that the extra tamper steps were not needed and I could ignore this bug.

megachriz’s picture

I think that the issue actually is in Feeds Tamper:

  1. Say you have a source item with the following data:
    [
      'phone' => '123/456-7890',
    ]
    
  2. On the source "phone", you apply the Tamper "find_replace", replacing / with )
  3. Also on the source "phone", you apply the Tamper "rewrite", with the following text: ([phone]

With Feeds, the result becomes:

[
  'phone' => '(123/456-7890',
]

That's because Feeds Tamper now writes the result back to the source at the end of the chain and not in between.

  • Branch 3323381-rewrite-tests_only changes ChainedTamperTest to mimic Feeds Tamper's current behavior.
  • Branch 3323381-rewrite-test-updated changes ChainedTamperTest to mimic what Feeds Tamper's behavior probably should be.
megachriz’s picture

Title: "Rewrite" plugin doesn't work right » Rewrite plugin: when using own source key in chain the initial value is used

  • megachriz committed f4a5e23b on 8.x-1.x
    Issue #3323381 by megachriz: Added test coverage for using the Rewrite...
megachriz’s picture

Project: Tamper » Feeds Tamper
Version: 8.x-1.x-dev » 8.x-2.x-dev

Moving this to Feeds Tamper now.

megachriz’s picture

Issue summary: View changes
Status: Active » Needs review

I've provided a fix and I've updated the issue summary to clarify what the problem is.

  • megachriz committed b29d73c1 on 8.x-2.x
    Issue #3323381 by megachriz: Write the data back to the item after each...
megachriz’s picture

Status: Needs review » Fixed

I merged the code!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.