Problem/Motivation

The "Find replace" tamper causes an import to fail when it doesn't apply to all items to all sources.

Steps to reproduce

Create a feed which ingests XML. Add a "Find replace" tamper rule to one of the mappings; the rule should not apply to all items in the source. For example, given the XML:

<?xml version="1.0"?>
<response>
  <item key="0">
    <guid>4896</guid>
    <title>A Test</title>
    <body><![CDATA[ <p>Hamburgers.</p> ]]></body>
  </item>
  <item key="1">
    <guid>2560</guid>
    <title>Another Test</title>
    <body><![CDATA[ <p>Nope.</p> ]]></body>
  </item>
</response>

...create Feed type which include a "Find replace" tamper to change "Hamburgers" to "Hotdogs".

Because the rule would not apply to the second item in the source, the entire import would fail - nothing would import.

Proposed resolution

Update Feeds Tamper such that when a rule does not apply, it is ignored.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

butterwise created an issue. See original summary.

butterwise’s picture

Issue summary: View changes
tclnj’s picture

Experiencing similar issue with JSON feed, though seems more related to the ability to handle array data in newer versions of the module.

ecj’s picture

here is the patch (avoiding g*t as being owned by m*soft.):

--- src/Plugin/Tamper/FindReplaceRegex.php.ORG	2022-10-10 11:46:53.575371122 +0200
+++ src/Plugin/Tamper/FindReplaceRegex.php	2022-10-10 11:47:06.175364547 +0200
@@ -90,8 +90,10 @@
    * {@inheritdoc}
    */
   public function tamper($data, TamperableItemInterface $item = NULL) {
+  	if (is_null($data))
+	  return NULL;
     if (!is_string($data)) {
-      throw new TamperException('Input should be a string.');
+      throw new TamperException('Input should be a string (is: '.gettype($data).').');
     }
     $find = $this->getSetting(self::SETTING_FIND);
     $replace = $this->getSetting(self::SETTING_REPLACE);

bob-e’s picture

@ecj How might I apply a patch that doesn't live on git?