Closed (duplicate)
Project:
GMap Module
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
15 Feb 2007 at 16:53 UTC
Updated:
14 Mar 2007 at 17:03 UTC
Not submitted a patch before, so not sure of the protocol, but:
http://drupal.org/node/118817 explains the original problem, which was that users couldn't set their location via a google map through their 'my account' link (in use with the location module.) The primary key needed a new value.
With this addition, users can now set their location via their 'my account' link. Line 622-632 in gmap_location.module. The problem was that the primary key (lid in the 'location' table) wasn't being set, so I just pull out the maximum value of that field and add one. Only other change, then, is to add lid into the INSERT query.
$query = db_query("SELECT MAX(lid) FROM {location}");
$lid = db_result($query);
$lid++;
db_query("INSERT INTO {location} (eid, lid, type, latitude, longitude, source) VALUES (%d, %d, 'user', %s, %s, 1)",
$user->uid,
$lid,
gmap_decimal($edit['gmap_location_latitude']),
gmap_decimal($edit['gmap_location_longitude']));
Comments
Comment #1
danaktivix commentedHaving done the above fix, I discovered a related problem: new users have an entry made for them in the location table, but the location values do no exist yet - so it enters 0 for both. This means when the new user goes to set their location via their accounts page, they initially find themselves just south of Africa!
Anyway, here's a fix. I imagine it doesn't really fit into the overall gmap.location methods, but it works. Note: I've hard-wired my default location values in, but I guess there's a way to access the default values set in the gmap.location settings page. (I don't need to do this, so didn't bother, sorry!)
Anyway, in gmap_location.module from line 622. It checks to see if user->id exists in the table and, if so, whether latitude is null or zero. If so, we presume its a new user and set the default values into {location} rather than use the $edit array.
Comment #2
brady747 commentedExcuse me, as I'm not as knowledgeable as I could be. I was about to put the patches above in place as I was having the user location problem referenced when I realized my problem is slightly different. I don't even have a lid column in my location table. I checked gmap_location.install and it doesn't create the lid column, so where should that column come from? I believe I have all relevant modules installed and enabled to allow users to add their location under my account and all the fields exist for their location info, I just get errors stating the lid column is unknown which I can verify in phpmyadmin. Sorry if I should start a new topic somewhere else, I just thought the problem was similar in natures and others who are new (like me) might not notice the difference in errors at first glance and might wonder why the patch above doesn't solve their problem.
Thanks for the above efforts, I hope to figure out why I don't have a lid column so i can put the patches to use.
brady
Comment #3
danaktivix commentedHia,
First, I have to say my patch is, er, patchy! There may well be a much simpler fix for the problem elsewhere in the code, and I'm not at all sure why you're install shouldn't have created the lid column - sorry. I'm also new to this module, and just trying to get it to work.
I've also discovered some whole new problems: when an admin creates a new account, a {location} entry is made for the user. When a user creates their own account, it isn't. This means that my previous test for setting default location values wasn't working. Here's a fix again - it checks the user table to see if the user has accessed their account. If they haven't, admin made it (and so values already exist for location.) If they have, when they access their location setter, they don't want the values set to default, but the one they select.
I'm hoping someone who knows about this project is going to come along and say why this is a complicated solution, and that there's something much simpler...! But needs must, and this has worked for me. (Sorry I can't help with the missing column conundrum...)
Remember, those are my default lat and long values... I haven't taken them from Gmap's own. From line 622 of gmap_location again:
Comment #4
danaktivix commentedJust thought I'd add: I'm not sure anyone should be using these patches until we hear back from someone more experienced with this project. They've worked for me - but then I also keep on finding new problems as a result of my attempted fixes! The last one does now seem to be working, but some other problems might turn up...
Comment #5
brady747 commentedThanks. Im just working on a test site, so i wont hold you accountable ;). I just added the lid field myself with phpmyadmin, although I had to guess at the fact its an integer field and a few of the other values. Anyhow, thats interesting re: the admin created user vs. user created user situation. I have been adding test users thru admin ao Im glad you posted this difference.
Brady
Comment #6
brady747 commentedDamn. Im getting:
Parse error: syntax error, unexpected '<' in xxxxxxxxxxxxxdrupal/modules/gmap/gmap_location.module on line 621
When I place in your code. I guess I need to learn some php and figure out why I couldn't just cut and paste your code in. Maybe you removed a bracket or something?
Off to look a php syntax i go...
Comment #7
brady747 commentedOk. So I removed
andwhen I paste in the code and added an extra bracket at the end and now its working!! Not sure why I needed that extra bracket. Initially I didn't put in theandbut I was getting an unexpected T_CASE error. Then theandwere giving me the other syntax error and eventually I just started matching brackets and for some reason your code (or my code) seemed a bracket short. Quite possibly I removed on in my cutting and pasting I gather. Oh well, THANKS for putting this stuff up even if its a temp fix - it got me up and running for the moment and I learned a bit :)Brady
Hopefully we can get someone to clarify this patch, but it seems good to me.
Comment #8
danaktivix commentedAh! I think I can explain this one, sorry, should have said:
1. You have to put the
tags around code when pasting to the forum, otherwise it won't make it nice and pretty coloured - but you should leave them out of the pasting in.2. And, just to make things even more odd, drupal modules don't use both PHP tags. You're supposed to open with <?php - but not close it again at the end of the code.
Hope that might help. I also hope you haven't spent five hours trying to work this out. Ah, the joys of the open source community...
Comment #9
brady747 commentedThanks, yeah...that should be obvious I guess. Like I said, I left the php out initially because I assumed it didn't belong, but got errors because I somehow was missing a bracket. Time to get a real php editor to help me sort out code late at night.....lol
Comment #10
danaktivix commentedJedit is a nice, light editor that has PHP highlighting: I've enjoed using it lots.
http://www.jedit.org/
(You need to turn on the PHP parser in the plug-ins...)
Comment #11
bdragon commentedI recently purchased a copy of Komodo IDE 4, and I love it.
The editor component of it is available for free.
http://www.activestate.com/products/komodo_edit/
Anyway, gmap_location.module should no longer be attempting to touch the location table directly if at all possible. Unfortunately, fixing user locations is a bit low priority at the moment for me, I still have so much other stuff to finish... :-/
Comment #12
nvoyageur commentedI just installed the latest build from March 8 and still have problems with setting/updating the user location that is found at "My Account > Edit > Location Map"
This problem of being able to add/update the user location on the gmap gives the following error.
user warning: Duplicate entry '0' for key 1 query: INSERT INTO location (eid, type, latitude, longitude, source) VALUES (1, 'user', 0.01441955551185579, -0.064544677734375, 1) in /var/www/drupal/includes/database.mysql.inc on line 172.
I guess it's trying to do an INSERT into the table when the field already exists. It should be checking if the field exists then doing an UPDATE if it does. I have not looked at the code to see where the logic/fix should be (still learning the Drupal way).
Thanks again for all the hard work going into this pivital module.
Comment #13
emeij commentedSee http://drupal.org/node/118817
Comment #14
denney commentedI to can confirm this error when updating a profile.
The initial setting of my location (being admin) worked fine but when someone else tried to set their location, and when I tried to to update my location, they received this error.
Also, just subscribing so I know when a fix is available. BTW... the link above, by 'emeij' contains code that doesn't exist or has moved from the latest version of this module (updated 13.03.07).
Comment #15
bdragon commentedMarking as duplicate of http://drupal.org/node/118817.
Thank you.
--Brandon