There is 4 references to split which needs replacing with preg_split - http://php.net/manual/en/function.split.php

geonames.module:67:      $object = array_combine($field_names, split("\t", $line));
geonames.module:90:    $lines = split("\n", $file->data);
geonames.module:93:        $a = split("\t", $line);
geonames.module:94:        $b = split("\.", $a[0]);

Comments

7wonders’s picture

explode is a better option than preg_split I think.

7wonders’s picture

Sadly I havent figured out creating patches yet but here is the required changes to get the latest d7 version working which includes adding the check for geonameid not equalling 0 and use of explode instead of split.

/**
 * Update the metadata tables (Countryinfo and Featurecodes)
 */
function geonames_metadata_update() {
  // Update the local list of Countries
  $failed = FALSE;
  $tablename = 'geonames_countryinfo';
  $file = drupal_http_request("http://download.geonames.org/export/dump/countryInfo.txt?app=drupal");
  if ($file->code == 200) {
    // Truncate the table, so we can do inserts
    db_truncate($tablename)->execute();

    // Use the Schema API to get a list of columns
    $schema = drupal_get_schema($tablename);
    $field_names = array_keys($schema['fields']);

    // Insert all records from the HTTP response
    $num = preg_match_all('/^[A-Z].*?$/ms', $file->data, $matches);
    foreach ($matches[0] as $line) {
      $object = array_combine($field_names, explode("\t", $line));
	        if ($object['geonameid'] != 0) {
      drupal_write_record($tablename, $object);
    }
}
    watchdog("geonames", "Successfully updated the $tablename table");
  }
  else {
    watchdog("geonames", "Failed to updated $tablename table", WATCHDOG_WARNING);
    $failed = TRUE;
  }

  // Feature code tables
  $tablename = 'geonames_featurecodes';
  $file = drupal_http_request("http://download.geonames.org/export/dump/featureCodes_en.txt?app=drupal");
  if ($file->code == 200) {
    // Truncate the table, so we can do inserts
    db_truncate($tablename)->execute();

    // Use the Schema API to get a list of columns
    $schema = drupal_get_schema($tablename);
    $field_names = array_keys($schema['fields']);

    // Insert all records from the HTTP response
    $lines = explode("\n", $file->data);
    foreach ($lines as $line) {
      if (trim($line) != '' && substr($line, 0, 1) != '#' && substr($line, 0, 4) != 'null') {
        $a = explode("\t", $line);
        $b = explode(".", $a[0]);
        $object = array_combine($field_names, array($b[0], $b[1], $a[1], $a[2]));
        drupal_write_record($tablename, $object);
      }
    }
    watchdog("geonames", "Successfully updated the $tablename table");
  }
  else {
    watchdog("geonames", "Failed to updated $tablename table", WATCHDOG_WARNING);
    $failed = TRUE;
  }

  if (!$failed) {
    variable_set('geonames_metadata_updated', REQUEST_TIME);
  }
}
lyricnz’s picture

Status: Active » Fixed

Replaced split() with explode() in D6 and D7 branches. Thanks.

Status: Fixed » Closed (fixed)

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