I use the explode plugin to create an array of taxonomy terms from the following string structure
"""aaa"",""b,b,b"",""c,c,c"""

I then use REGEX /"(.*)"/s and replace with $1 to remove the quotes

PROBLEM comes when the input list of terms is blank/empty

explode creates an array with an empty string element.

Unfurtunately this then creates a taxonomy entry with a blank term.

SOLUTION
here is the code change in explode.inc which works for me.

function feeds_tamper_explode_callback($result, $item_key, $element_key, &$field, $settings) {
  //dsm($field);
  $pos= strpos($field, $settings['real_separator']); // returns FALSE when separator NOT in field ... eg empty field
  if ( $pos !== FALSE ) {
    $field = explode($settings['real_separator'], $field);
  }
  //dsm($field);
}

Sorry I was not easily able to create a patch. I hope there is someone better equipped than I to do the next steps and get this change into the dev version.

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

twistor’s picture

Version: 7.x-1.0-beta2 » 7.x-1.x-dev
Assigned: Unassigned » twistor
Status: Active » Fixed

This got fixed at some point.

Status: Fixed » Closed (fixed)

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

Steven.Pescador’s picture

Status: Closed (fixed) » Needs review

Sorry to reopen this, but experienced this problem today using the latest dev version.

If my imported field is empty, explode is creating an array with an empty string element and in turn this is creating a blank taxonomy term.

I got it working myself using...

if (strpos($f, $settings['real_separator']) === FALSE) {
  if ($f != NULL){
    $out[] = $f;
  }
}

But this is probably an extremely dirty solution and may cause other errors. Just thought I'd throw this out here to see if I was missing something or more likely doing something wrong. Cheers.

TimelessDomain’s picture

Status: Needs review » Reviewed & tested by the community

#3 works - thanks. I was getting blank fields (taxonomy + any other exploded field) when exploding a csv parser, but now i don't. Yay!

plugins/explode.inc

- if (strpos($f, $settings['real_separator']) === FALSE) {
-       $out[] = $f;
-     }
+ if (strpos($f, $settings['real_separator']) === FALSE) {
+   if ($f != NULL){
+     $out[] = $f;
+   }
+ }
EvanDonovan’s picture

Status: Reviewed & tested by the community » Needs work

Can someone turn this into a patch so that it could get applied to the module? Also, are the posts from #3 on saying that this is still an issue on 7.x?

Also is this an issue on 6.x too?

5n00py’s picture

Status: Needs work » Needs review
FileSize
530 bytes

Modified solution from #3 packed to patch! Works fine for me.

reszli’s picture

#6 - thanks for this, it works!

5n00py’s picture

Why we have not any progress? Who can apply\review patch?

twistor’s picture

Status: Needs review » Needs work

I know I haven't committed this yet, here is my reasoning:

The empty value your're seeing is in the source data, so removing it automatically might not be wanted. For example, if you have a multi-columned field, like an address field. It has columns like, street, state, city, country, etc. In the source data, some of these entries might not be filled in. If we filter out empty values, then the columns won't align properly anymore.

My proposed solution is to create a new plugin, something like array_filter, which will remove empty values from the array.

5n00py’s picture

Ok.
But maybe we can add an option to existing explode plug-in?
Just something like "keep empty values"?

nchar’s picture

Status: Needs work » Needs review
FileSize
852 bytes

I created the array_filter plugin, that Chris suggested as the best solution. It works fine for me!

liquidcms’s picture

Status: Needs review » Reviewed & tested by the community

i have a multi user ref field which i was tampering with explode, trim. empty values in the csv were causing the error: "is not a valid user" due to the explode causing an empty array.

using the array_filter plugin from the patch in #11 fixed this. thanks.

5n00py’s picture

Status: Reviewed & tested by the community » Needs work

Review from coder module:

array_filter.inc

severity: normalreview: style_control_spacingLine 25: Control statements should have one space between the control keyword and opening parenthesis [style_control_spacing]

if(is_array($field)){

severity: normalreview: style_paren_spacingLine 25: use a space between the closing parenthesis and the open bracket [style_paren_spacing]

if(is_array($field)){

Also patch can't be applied as is to 7.x branch. because it require empty file.
So make another diff by running:
git diff origin/7.x-1.x

Header may look like this one:

diff --git a/plugins/array_filter.inc b/plugins/array_filter.inc
new file mode 100644
index 0000000..3932b38
--- /dev/null
+++ b/plugins/array_filter.inc

As functionality, I tested this plugin on clean installation and it works properly.
It do not change any explode code, its only new plugin.
So it can be applied after this little fixes.
Thank for the patch, waiting for fixing this little issues and commit.

twistor’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Assigned: twistor » Unassigned
Priority: Major » Normal
Status: Needs work » Patch (to be ported)

I went ahead and fixed the small things.

Thanks!

http://drupalcode.org/project/feeds_tamper.git/commit/1c491d6

phiscock’s picture

I've tried using the new plugin in the dev version, but it does not seem to be having any effect. I've tried applying it both before and after the explode plugin on text fields with multiple values.

Am I using it wrongly or is it not working for other people.

Paul

liquidcms’s picture

use after explode. and it works fine.

phiscock’s picture

Thanks. I was looking at previously wrongly imported data that was still there when I thought it didn't work.

5n00py’s picture

Status: Patch (to be ported) » Needs review
FileSize
881 bytes

Patch for 6.x branch attached.
Very same as 7.x version.
Included update from http://drupalcode.org/project/feeds_tamper.git/commit/372d17384195c02a9d...
(http://drupalcode.org/project/feeds_tamper.git/blobdiff/1c491d638e78a06b...)

Tests are not included.
I'm already test plugin on fresh d6 installation and it work properly.
Only one problem is a another feeds_tamper bug. (Now feeds tamper not support plugins without settings).
This problem appear in unique.inc plugin also.

5n00py’s picture

Tests patch. It needs review because I have not experience with tests.

5n00py’s picture

Prev 2 patches in one file.

twistor’s picture

Status: Needs review » Fixed

Thanks.

Status: Fixed » Closed (fixed)

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

The last submitted patch, 18: port_array_filter_to_6.x-1180726-18.patch, failed testing.

The last submitted patch, 19: port_array_filter_tests_to_6.x-1180726-19.patch, failed testing.

Status: Closed (fixed) » Needs work

The last submitted patch, 20: port_array_filter_w_tests-1180726-20.patch, failed testing.

twistor’s picture

Issue summary: View changes
Status: Needs work » Closed (fixed)

Status: Closed (fixed) » Needs review

Status: Needs review » Needs work

The last submitted patch, 20: port_array_filter_w_tests-1180726-20.patch, failed testing.

5n00py’s picture

Status: Needs work » Closed (fixed)

This patch already commited, so it can't be applied.
@msizec: If you have some problems with this patch you can reopen this issue or create new one, but you should provide some information.