None of our new users are getting latitude and longitude set. On our site, locations are associated with profile nodes. Location's hook_nodeapi looks for eid=nid, when it should be looking for eid=vid. At some point, our nid's and vid's in the node table got out of sync; the code coincidentally works for users whose profile nodes have nid=vid, but fails for users where they're different.

Attached is a patch that fixes the problem.

Comments

aaron’s picture

this was also reported at http://drupal.org/node/255020

bcn’s picture

I am also seeing this problem after a recent update of the locations module... I will test the patch and report back.

[UPDATE]
patch applies cleanly but does not seem to solve the issue for me. The problem I'm having is that when a location enabled node is being created the LAT/LONG does not get set for users that enter only a postal code. Once that user edits, and then saves the node, the lat/long geocoding sticks.

[UPDATE 2]
The problem I described above does not affect users with the ability to enter lat/long directly.

bcn’s picture

Status: Needs review » Reviewed & tested by the community

I believe there is a second issue at work here, therefore this patch does solve the problem it was intending to... I will open a new issue for the other problem I'm having.

ethanw’s picture

StatusFileSize
new3.64 KB

It looks like the logic of the `if ($node->nid)`...`if ($result =...` clauses fails to add location data for new nodes, which have an nid/vid but do not yet have an entry in the location table. For new nodes, then, the $node->nid test passes but the db_query on the location table fails, even with the vid adjustment above. When the db_query fails, the code flows past the node->nid positive block but skips the "else" for the $node->nid test, causing no location geocoding info to be added to the location, though State and City lookup is executed since it is outside the scope of this logic. A fix is to replace the code like this:

          if ($node->nid) {
            $result = db_query("SELECT * FROM {location} WHERE type = 'node' AND eid = %d", $node->nid);
            if ($location = db_fetch_object($result)) {
              if ($location->source != LOCATION_LATLON_USER_SUBMITTED) {

With something like this, adjusting closing parens as needed:

          if ($node->vid && $location = db_fetch_object(db_query("SELECT * FROM {location} WHERE type = 'node' AND eid = %d", $node->vid))) {
            if ($location->source != LOCATION_LATLON_USER_SUBMITTED) {

This is not yet thoroughly tested, but does work for new and existing node cases. Patch attached (created using subversion).

bcn’s picture

Patch from #4 applies cleanly and based on my tests seems to finally fix the issue(s) here. As described in #4, the earlier patch only went part of the way.

Thanks!

ethanw’s picture

StatusFileSize
new694 bytes

Just found one other small bug in this logic, with the above patch from #4, the second occurrence of

elseif ($data = location_get_postalcode_data($node->location)) {

Should be changed to

 elseif ($data = location_get_postalcode_data($node->locations[$index])) {

I don't know why it was working before given this issue, may have been some weight tweaking i'd done.

Patch attached, incremental from #4

drawk’s picture

(deleted - issue I was having was a configuration on my side)

bdragon’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

2.x is confirmed broken when working with revisions.

#6 issue is a dupe of #125745: On new node creation user location isn't looked up.

2.x is closed.