I setup a new Drupal site and installed the latest .dev versions of CCK, Location and GMap. I created a new content type 'Country', and gave it the location fields 'Country' and 'Coordinate Chooser' (both the overall location field and the individual fields within location were set to 'required').

I then attempted to create a node of type 'country' - I left the country field as the default (USA) and added a marker to the GMap (for the coordinates). I saved, but nothing appeared on the node page. Editing the node sees both country and coordinate fields empty. Nothing has been saved.

This only seems to happen when you leave the country as the default value. On another of my test sites, I had the default country as Australia, and trying to create an Australia node produced the same results. Changing to a different country seems to work though...
Also worth noting is the fact that setting the default country in both the Location configuration settings and per content type is buggy - it often doesn't work properly, or works every now-and-then, but not reliably.

Be good to get this confirmed and fixed.

CommentFileSizeAuthor
#17 424784.patch1.33 KBbdragon
#8 location-424784-8.patch514 bytesAnonymous (not verified)
#7 location_issue_code.png24.71 KBAnonymous (not verified)
#7 location_issue_result.png35.05 KBAnonymous (not verified)
#4 location_cck.patch669 bytessocki
#3 location_instances.jpg51.14 KBsocki
#3 node_locations_query.jpg66.63 KBsocki
#3 node_save_query.jpg56 KBsocki

Comments

lolmaus’s picture

I confirm the bug.

No errors arise, but when you change coords in a node, the coord changes WILL NOT be saved (as if you clicked Back instead of Save).

If you change the country field in addition to the coords, the changes WILL be saved.

lolmaus’s picture

This is not a matter of default country. It requires the country field to be changed, no matter whether you do that from default to custom, from custom to default or from custom to custom.

socki’s picture

StatusFileSize
new56 KB
new66.63 KB
new51.14 KB

I believe I might be having the same problem.

After doing a bit of digging, I think there might be an issue with how some of the data is being saved. It may also be a misconfiguration on my part. In either case, would you be able to point me in the right direction?

Please see the following screenshots:

node_locations_query.jpg - This is the query that is executed when you attempt to go to the "node locations" page. The first INNER JOIN makes the data in the location_instances table required.

SELECT n.nid, n.type, n.title, l.latitude, l.longitude , m.marker
    FROM node n
    INNER JOIN location_instance i
      ON n.vid = i.vid
    INNER JOIN location l
      ON l.lid = i.lid
    LEFT JOIN gmap_taxonomy_node m ON n.vid = m.vid
    WHERE
      n.status = 1
    AND
      (l.latitude != 0 OR l.longitude != 0)

location_instances.jpg - this is what is being stored in my location_instances table. As you can see, the NID and VID columns are all zero. This seems bad.

                                nid 	vid 	uid 	genid 	               lid
  	Edit   Delete   	0  	0  	0  	cck:field_location:2  	2
	Edit 	Delete 	0 	0 	0 	cck:field_location:13 	3
	Edit 	Delete 	0 	0 	0 	cck:field_location:15 	4

node_save_query.jpg - When I create a new node, saving the location data as part of it, these queries get executed. In here, the data is deleted, and when it gets recreated, it only sets the two columns... and NOT the NID or VID columns.

DELETE FROM location_instance WHERE genid = 'cck:field_location:15'
INSERT INTO location_instance (genid, lid) VALUES ('cck:field_location:15', 4)

Please let me know if you may need any additional information, or if you may know what I might be doing incorrectly.

Thanks.

socki’s picture

Status: Active » Needs review
StatusFileSize
new669 bytes

I think i may have a potential fix for the issue I mentioned above.

It seems that the problem is that when location_save_locations is called from within location_cck_field the following is executed:

    case 'insert':
    case 'update':
      // Store instances of locations by field name and vid.
      $genid = 'cck:'. $field['field_name'] .':'. $node->vid;
      location_save_locations($items, array('genid' => $genid));
      // CCK automatically picks up the new lids and stores them in its own tables.
      break;

The patch I've attached will update this to be:

    case 'insert':
    case 'update':
      // Store instances of locations by field name and vid.
      $genid = 'cck:'. $field['field_name'] .':'. $node->vid;
      location_save_locations($items, array('genid' => $genid, 'nid' => $node->nid, 'vid' => $node->vid, 'uid' => $node->uid));
      // CCK automatically picks up the new lids and stores them in its own tables.
      break;

Note: The difference being the addition of the nid, vid and uid columns being passed into location_save_locations.

Since I'm new to using this module, I'm not entirely positive that this will have no negative impact, but with my implementation, it does appear to work just fine.

One thing that this may alter is if revisioning is enabled on the site. With the new parameters being passed in, an instance will be inserted for each revision. The reason for this is the existence of the vid in the table. The delete statement within location_save_locations deletes only exact matches of all the columns passed in.

Hope this helps.

yesct’s picture

Issue tags: +location defaults

thanks for posting a patch!

tagging.

I think there are some duplicates of this issue reported in the queue... but I dont have the time to find them. Maybe someone else could look, maybe search for "country default" or "country default save"

http://drupal.org/project/issues/search/location?text=default+country+sa...

Anonymous’s picture

Status: Needs review » Needs work

Patch doesn't work for me... When creating a country and leaving the country name as the default value (Australia), it still doesn't save properly - editing the country shows the name set to 'Please select'...

Anonymous’s picture

StatusFileSize
new35.05 KB
new24.71 KB

I think I found where the problem lies...

I added the code in the first screenshot to location.module in the 'location_calc_difference' function (one of the functions that's run when deciding if any changes have been made - it should return TRUE for changes made). The code I added shows what happens to the location being checked before and after it's run through the 'location_strip' function. The result is shown in the second screenshot.

What it seems is happening, is that my coordinates are being stripped and hence when the location data is being checked, no changes are found and so nothing is saved to the database.

I'd submit a patch to fix this, but am not sure exactly what to fix (the problem lies in the 'location_strip' function somewhere). Any help would be much appreciated!

Anonymous’s picture

StatusFileSize
new514 bytes

I've made the following, very rudimentary patch that simply comments out the two strip() functions from the location_calc_difference() function in location.module.

Brief testing shows data is now being saved properly on my test site, but I don't know what effects, if any, this'll have on other parts of the code...

Hopefully this'll be a step in the right direction to getting this fixed...

yesct’s picture

Status: Needs work » Needs review
criz’s picture

I can confirm this critical bug!
Patch from #8 is working, thx, but I don't think that this is an appropriate solution?

Anonymous’s picture

Patch from #8 is working, thx, but I don't think that this is an appropriate solution?

It's not. My site was going live and staff were going to start creating content with location data, so I needed it to work and came up with that patch.
As I said in #7 above, the problem (as far as I know) lies in the location_strip() function. I just stopped that function being run.

yesct’s picture

Title: Location data not being saved » Location data not saved (when only have country filled in, and leave it as the default country) problem w location_strip()
summit’s picture

Subscribing, needing solution for this also.
Anyone has a prober solution?
Greetings, Martijn

dverkade’s picture

Subscribing, where experiencing the same problems. The patch does work, only partially, the selected location is altered when saved and is not displayed on the same location

gregstout’s picture

Subscribing, too.

jerodfritz’s picture

subscribing

bdragon’s picture

StatusFileSize
new1.33 KB

See if this helps, please.

Locpick is being stripped out, but I forgot to copy out the changes first.

Hopefully this works without introducing regressions.

bdragon’s picture

Status: Needs review » Fixed

(From #511378)
* Fix emptiness check centrally, instead of relying on location_save().
* Remove cck validator -- the condition it was checking for was a bug, not
a feature.

http://drupal.org/cvs?commit=244962
http://drupal.org/cvs?commit=244966
http://drupal.org/cvs?commit=244968

This should take care of this bug.

Status: Fixed » Closed (fixed)
Issue tags: -location defaults

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