I have a Content Type with a Geofield. I have a feeds importer generating nodes from an XML feed. All the fields are importing fine, except for the Geofield. The importer worked fine before we updated to the new dev version of feeds: 7.x-2.0-alpha8+102-dev. I'm not really able to downgrade, though, due to other required functionality.
I thought this issue was related to https://www.drupal.org/node/2192421, but now I think it's similar but not the same. After a few hours of digging, I've tracked down why it's not saving, but I don't know the implications. Essentially, when feeds runs any processor, it runs module_invoke(feeds_presave). The only function that's calling for me is field_feeds_presave() in feeds/mappers/field.inc. That function calls _field_filter_items() from /modules/field/field.module, which then in turn calls geofield_field_is_empty($item,$field) in geofield.module.
The $item being passed in is a simple 2 item array:
(Array, 2 elements)
lat (String, 7 characters ) 33.6434
lon (String, 8 characters ) -80.1966
So, from my reading of geofield_field_is_empty(), it essentially doesn't see an $item['input_format'] defined so that code doesn't run, and it also doesn't see any $item['geom'], so it returns true and the geocoordinate values are removed.
So, I guess my question is, at which point in this process is it going wrong? If I manually run node_save() with the same exact field array values, it works. I'm guessing the standard node_save() doesn't have this intermediary check. So, should there be another step in geofield_set_target_simple() that does some processing and adds in that ['geom'] value? I've attached photos of my setup in case I'm just configuring the import incorrectly.
Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #46 | geofield-feeds_import_not_saving-2534822-46.patch | 837 bytes | m.stenta |
| #38 | geofield-feeds_import_not_saving-2534822-38.patch | 796 bytes | m.stenta |
| #17 | geofield-feeds_import_not_saving-2534822-17.patch | 907 bytes | pryrios |
| #12 | feeds_import_not_saving-2534822-12.patch | 531 bytes | joelpittet |
| #4 | geofield-feeds-simple-import-2534822-4.patch | 492 bytes | SeeWatson |
Comments
Comment #1
SeeWatson commentedComment #2
megachrizFeeds has recently become stricter in handling empty values and calls indeed
_field_filter_items()in order to avoid saving field data which the module considers to be empty. See for example these Feeds issues:#2344827: Importing empty email field: email field is anyway created in the DB
#2499251: Link module: empty fields are rendered
#1107522-195: Framework for expected behavior when importing empty/blank values + text field fix
To fix this issue, Geofield should either adjust the empty check in
geofield_field_is_empty()or make sure thatgeofield_set_target_simple()always sets$item['geom'].Comment #3
sistro commentedI've the same issue.
I solved using alpha9 version of module.
Comment #4
SeeWatson commentedSomething like this? It corrected the issue for me, but I don't know if this is the right approach.
Comment #5
Yorgg commentedThe patch worked for me. Thanks.
Comment #6
mitterer10 commentedI tried to apply this patch but it isn't working as I get errors like "patch unexpectedly ends in middle of line".
I'm using geofield 7.x-2.3 and feeds 7.x-2.0-beta1.
Might this be the problem?
Thanks!
Comment #7
tondeuse commentedWorks with 7.x-2.3+0-dev, applies fine, thanks,put an end to hours of questions.
Comment #8
SeeWatson commentedHi mitterer10, I don't think the versions would be an issue, as the current dev and stable Geocoder are identical. Maybe just try one of the other approaches here: https://www.drupal.org/patch/apply. I used the p1, I think.
Comment #9
FreeAndEasy commentedpatch works! please commit!
Comment #10
FreeAndEasy commentedComment #11
joelpittetThis doesn't account for multi value fields. Probably should loop through the fields instead of hard coding a 0
LANGUAGE_NONE should be used instead of 'und'.
And nit on coding standards: spaces need before and after parentisies in the if statement. aka if () { not if(){
Comment #12
joelpittetOk maybe this would be a bit more robust?
Comment #13
joelpittetAnd just to be make note, geofield_field_is_empty() is not getting input_format on the $item array so it just checks if 'geom' is empty and returns TRUE because it is not there.
So an alternative solution would just be maybe making that smarter? But I think this solution probably is the best so thank you @SeeWatson
Comment #14
SeeWatson commentedThanks for the review, @joelpittit. I went with und because that was what the rest of the module was using and I didn't want to break the convention. Are incremental formatting improvements the norm for things like this even if they break the existing module convention?
Comment #15
joelpittetI was tempted to fix the other uses of 'und' in that function but I held restraint, but we should all be using the language constant in all modules.
The formatting is from drupal's coding standards.
https://www.drupal.org/coding-standards#controlstruct
Comment #16
daemonchrist commentedPatch in #12 fixed this problem for me. Thanks!
Comment #17
pryrios commentedPatch in #12 only solves the issue for latitude/longitude widgets. I'm facing the same problem using bounding boxes so I have added some more code to that patch but I think we may be missing many cases here. Someone more savvy should really take a look at this mess and find the correct solution.
Comment #18
andrey_dver commentedHello.
I had the same problem.
My modules:
Geofield 7.x-2.3
Feeds 7.x-2.0-beta1
Feeds import had not saving lat and lon.
Patch #17 fixed this problem.
Thanks!
Comment #19
hypertext200Closing #2324927: Geofield Latitude/Longitude fields do not get imported with latest dev of Feeds as duplicate
Comment #20
hypertext200Patch #17 fixed the problem.
Comment #21
pingevt commentedI'm only using the long and lat fields at the moment but Patch #17 worked for me.
Comment #22
mouhammed commentedPatch #17 works.
Comment #23
madar commentedWith long and lat fields Patch #17 worked for me.
Comment #24
dillix commented#17 works fine.
+1 for commit this.
Comment #25
zolee commentedPatch #17 fixed the problem.
Comment #26
jeffschuler#17 worked for me for simple lat/lon import. Thanks!
Comment #27
madmanmax commented#17 worked for me as well. Now the lat/lon import is working.
Comment #28
redeight commented#17 fixed the issue for me as well.
Comment #29
geru commented#17 worked to fix lat / long not getting imported
Comment #30
denix commented#17 works great! Thanks
Comment #31
nattyweb commented#17 worked for me. Thank you.
Comment #32
kupide commentedPatch #17 worked for me too, thanks you.
Please commit !
Comment #33
darvanen+1 for commit =)
Comment #34
znerol commentedFeeds 7.x-2.0-beta2 is now ready for entity translation, hence the correct language code should be used instead of
LANGUAGE_NONE. See also the change record.Comment #35
megachrizSee also #2672788: Feeds integration: support mapping option "language".
Comment #36
m.stentaWhen using bounding box values, why is $field[LANGUAGE_NONE][$delta]['geom'] being set to $field[LANGUAGE_NONE][$delta]?
Comment #37
m.stentaThis issue is somewhat related because it provides a patch that alters the geofield_field_is_empty() function, specifically checking to see if ['geom'] is not set, and declaring the entire geofield empty if geom is empty.
#2672108: Don't save empty geometry WKT
EDIT: To be clear, they are two separate issues, and both need their own patch. I just wanted to point out that they deal with similar code. :-)
Comment #38
m.stentaAttached is a new patch that uses geofield_compute_values() for both lat/lon and bounding box imports - ensuring that all the geofield data is filled in before saving.
I have tested this with lat/lon import, but not with bounding box import. @Pryrios: would you mind testing this patch, since you are importing bounding boxes?
Comment #39
mikejuic3 commented@m.stenta
I have tested your patch and while I am not getting any errors it still doesn't seem to import.
I am building an importer for INSPIRE metadata so am quite busy on this at the moment. I will report back if I figure out what is going wrong.
Comment #40
m.stenta@mikejuic3 - What parts are you trying to import, specifically? Latitude + longitude? Bounding box? WKT?
My patch is tested with Lat/lon, but I haven't tested with bounding box (although it should work the same).
Comment #41
mikejuic3 commented@m.stenta The xml I am importing only contains bounding box coordinates. So I am importing bounding boxes. The feeds importer debugger shows that it is pulling in the BB coordinates but from there the import goes no further. I have tried both #38 and #17.
Cheers
Comment #42
mikejuic3 commentedA little more info, I think I have it more narrowed down:
$field[LANGUAGE_NONE][$delta] = geofield_compute_values($value, GEOFIELD_INPUT_BOUNDS);Seems to return an empty array. $value contains my bounding box but GEOFIELD_INPUT_BOUNDS is not taking the bait. Watch this space.
Comment #43
mikejuic3 commentedI have it importing from bounds after some modifications. geofield_set_target_simple now looks like this:
There were a couple of issues that needed to be sorted out and I am sure it can be done more cleanly than this.
Issues encountered:
I can roll this into a patch but would like some input as to doing it a bit more efficiently.
Cheers.
Comment #44
1mundus commentedDid anyone make Geofield CSV import work with Feeds 7.x-2.0-beta2? I have tried all of the patches listed here and none work. My configuration:
Feeds 7.x-2.0-beta2
Geofield 7.x-2.3
Mapping:
Lat -> Coordinates Latitude (field_coordinates:lat)
Lon -> Coordinates Longitude (field_coordinates:lon)
CSV file example:
Title|Language|Lat|Lon
Some title|en|20.00000|20.00000
All of the other fields get imported, but Geofield coordinates don't. I have also tried to make it work without the language set either in CSV or in the feed settings, but the result was the same.
Comment #45
darvanenYes @1mundus #17 worked fine for me with exactly those requirements.
Comment #46
m.stenta@mikejuic3 - Your logic makes sense, but I agree we should see if it is the most efficient. Your approach is essentially bypassing the bounding box entirely, by creating a polygon from the points, and then letting geofield_compute_values() fill in the rest.
So in essence, you're throwing out the second parameter of geofield_compute_values(), and therefore geofield_geometry_from_values() (the second parameter being $input_format in both). It works the same, but it feels to me like that piece of information (the input format) should be preserved.
So it sounds like the real issue here is: why is
geofield_compute_values($value, GEOFIELD_INPUT_BOUNDS);returning an empty array as you said in comment #42?Is it because $value needs to be formatted differently? Does it need to be a nested array within $value['geom']?
In other words, what if you use my patch from #38, but add the following line right above line 152:
$value = array('geom' => $value);Does that make sense? Attached is a new patch to demonstrate what I mean. Could you test to see if this works?
Comment #47
mikejuic3 commented@m.stenta
Apologies for taking so long to get back to you. I will test this out today or tomorrow and let you know. I can give a bit more detail then too.
Comment #48
ccjjmartin commentedI only tested patch #46 and I can verify it works. By it works, I mean that originally I was able to import nodes but not geofields. And now with the patch, I can import nodes and geofields.
Great work! Thanks for your contribution. [@m.stenta]
Comment #49
roadsideok commented#46 worked for me. Thank you all for the work on these patches!
EDIT: It worked for LAT/LONG geofields on newly imported terms, but does not seem to update existing terms.
Comment #50
kumkum29 commentedHello,
#17 works for me with new nodes & existing nodes. I don't use the #46 because this patch seems to create a problem with the existing contents (#49).
Have you planned to commit this patch in the next version of Geofield? (important bug).
Thanks.
Comment #51
kansaj commented#17 I'm not quite sure that #17 updates the nodes, I was not able to update long and lat.
Comment #52
m.stentakansaj: My patch in #46 above can handle lat/lon. Please test that one and let us know if it works for you.
Comment #53
kansaj commented#52 I confirm that it handles correctly new nodes, but old ones are not updated.
Comment #54
gaëlg@kansaj #46 worked for me, even for existing nodes, as soon as I temporarily checked "skip hash check" in the importer settings, for the first import after the patch had been applied.
Comment #55
m.stentaThanks @GaëlG, good point about the "skip hash check".
@kansaj, @kumkum29: can you please make sure that you have "skip hash check" unchecked when you are testing?
Feeds performs a hash on the data you are importing, and if it finds the same hash when you try to import the same data again, it will assume that nothing needs to be changed, so it won't update the nodes. For testing purposes you should have that hash check turned off, otherwise it will never make it to the code that we want to test.
Comment #56
kansaj commentedHi,
I could confirm the "skip hash check" worked as expected and updated the nodes.
Comment #57
m.stentaAwesome, thanks for confirming @kansaj!
I think this is patch ready to be committed! Thanks everyone for helping to review!
Comment #58
makbuk commented#17 works for me.
Thanks.
Comment #59
m.stenta@makbuk Thanks for the input - but the patch that we are currently reviewing is #46. Can you confirm that that one works for you as well?
Comment #60
e5sego commentedPatch #46 works for me
Note: During import of latitude/longitude data, the correspondending field widget has to be "Latitude / Longitude".
Comment #61
cimo75 commentedPatch #46 works for me importing lat and lon one by one.
Comment #62
marcopbazz commentedPatch #46 worked for me too. I used it for a leaflet widget field
Comment #63
ShedPhotons commentedPatch #46 worked for me - imports to POINT.
Comment #64
das-peter commentedAnother confirmation that the patch works.
Comment #65
ugintl commented#46 WORKED FOR ME
Comment #66
sealionking commentedNeed feeds support for D8.5
Could anyone familiar with these two module make a patch/ or patches?
I am constructing a site with info of a big bulk of locations and need to import those lat/lon data to their nodes and terms.
Sincerely wish you guys will offer support to solve this since I am not coder but only a builder.
Many thanks.
Comment #67
m.stenta@sealionking Please open a new feature request for the 8.x-1.x branch. This one is specifically about a bug that exists in the current 7.x-2.x codebase, which has a proposed patch ready for review/commit.
Comment #68
soyjaz commented#46 worked for me aswell - if that's anyhow relevant to point out. Thanks.
Comment #69
frogdog_tech commented#46 bingo
Comment #70
ConradFlashback commented#46 works
Comment #72
itamair commentedComment #74
scott.whittaker commentedIssue is closed but patch still required. Dev branch only?