NULL values return 0 when imported via Feeds

Created on 2 July 2021, almost 3 years ago
Updated 19 January 2023, over 1 year ago

Problem/Motivation

When importing via Feeds, the importer will return 0 on null values and then store that in the Lat/Lon fields. This means that anything imported without a lat/lon will wind up at 0,0 on Geofield maps, and that the filter to leave out NULL values won't work, because a Lat/Lon of 0,0 is a valid latitude and longitude.

Steps to reproduce

Proposed resolution

The problem is the conversion to float in /src/Feeds/Target/Geofield.php, line 131. A condition should be added that leaves the value as NULL if it is not set.

protected function prepareValue($delta, array &$values) {
    // Here is been preparing values for Lat/Lon coordinates.
    foreach ($values as $column => $value) {
      if (in_array($column, ['lat', 'lon'])) {
        $separated_coordinates = explode(" ", $value);
        $values[$column] = [];

        foreach ($separated_coordinates as $coordinate) {
--->    $values[$column][] = (float) $coordinate;
        }
      }
    }

    // Latitude and Longitude should be a pair, if not throw EmptyFeedException.
    if (count($values['lat']) != count($values['lon'])) {
      throw new EmptyFeedException('Latitude and Longitude should be a pair. Change your file and import again.');
    }
  }

Remaining tasks

I've attached a patch that works on my installation. I'm not sure if it's the best solution, but it works.

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

1.32

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024