Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location module stores lat/lng incorrectly as integers in the database #2996

Closed
jessedobbelaere opened this issue Dec 2, 2019 · 8 comments
Closed
Labels
Milestone

Comments

@jessedobbelaere
Copy link
Member

jessedobbelaere commented Dec 2, 2019

Bug Report

Q A
Critical Bug no
Version 5.x.x

Problem description

When I use the Location module in the latest Fork CMS, instead of storing 51.0624 and 3.74855 as longitude/latitude in the database, it stores 51 and 3. This gives a totally different location.

image

Steps to reproduce

Enter an address in the Location module. Save it. The backend will do Geolocation using the Google Geo Coding API. It will find the lat/lng coordinates. When Spoon Database stores the record, it casts to integers.

Expected behavior / Proposed solution

Quick n dirty solution: typecast the float to strings before inserting the item in the Model.php. Spoon Database inserts those correctly as 51.0624 and 3.74855 instead of 51 and 3.

Actual solution: in Spoon Library's database.php there's some logic that binds values to the statement:

https://github.com/forkcms/library/blob/master/spoon/database/database.php#L1209-L1213

There's a bug in the getType($value) function: https://github.com/forkcms/library/blob/master/spoon/database/database.php#L713-L718

It considers floats to be of type PDO::PARAM_INT which should not be the case as it casts the float to an int and inserts an integer in the db.

There is no PDO::PARAM for floats and decimals so different sources suggest to use PDO::PARAM_STR. Tl;dr probably a oneliner fix in Spoon Library?

@carakas
Copy link
Member

carakas commented Dec 2, 2019

Any idea how it comes it suddenly started acting up?

@jessedobbelaere
Copy link
Member Author

jessedobbelaere commented Dec 2, 2019

No idea as I haven't used the Location module in a long time... But I see Jeroen refactored it a bit in #2525 in 2018 so maybe it used to be a string, now it's a float being sent to PDO?

Spoon Library should use PDO::PARAM_STR anyways in case of a float, thats a bug :D (https://stackoverflow.com/a/9542340/1409047). Should I just make a PR towards Spoon Library?

@jonasdekeukelaere
Copy link
Member

Can confirm, had this in one project, but can't remember when, I did cast it to strings because no time to figure out what the issue was.

@jessedobbelaere
Copy link
Member Author

This should do it ⬆️ https://github.com/forkcms/library/pull/74/files

@ohvitorino
Copy link

We should add some tests to cover this situation.

@carakas
Copy link
Member

carakas commented Dec 2, 2019

I think in the restructure_core there are already tests for the new location module

@ohvitorino
Copy link

I think in the restructure_core there are already tests for the new location module

That's correct. I've just tested it.

@carakas carakas added this to the 5.7.1 milestone Dec 5, 2019
@carakas
Copy link
Member

carakas commented Dec 5, 2019

fixed in #3001

@carakas carakas closed this as completed Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants