universeodon.com is part of the decentralized social network powered by Mastodon.
Be one with the #fediverse. Join millions of humans building, creating, and collaborating on Mastodon Social Network. Supports 1000 character posts.

Administered by:

Server stats:

3.6K
active users

Learn more
Pinned post

Time to : -izing my web presence.

✅I've had johnbeales.com forever.
✅Fresh new Mastodon account.
🔲 Set up rel="me" so my Mastodon link gives me a green check.
🔲Make sure my h-card is set up right.
...?

End goal: own my microblogging, mostly on my own site, while still participating in the fediverse, and not overwhelming longer-form blog posts.

Replied to John Beales

And today I learned there is no WKT representation of a circle. I guess I’ll use a polygon as a bumpy circle.

Also, MySQL is giving me an error when I try to pass a strategy to ST_Buffer, so there is that.

Replied to John Beales

Ha! It was me that flipped the latitude/longitude when importing data.

Time to add validation so I’ll get errors if I screw this up again in the future, instead of bad data.

John Beales boosted

One of the challenges of a testing device is getting content onto it to try out new features. I wanted to test out the new automatic live activities on watchOS 11 which need something playing on your iPhone. This is where Bono gives me a helping hand...all my testing devices have exactly one album always preloaded. 🤪

Replied to John Beales

Doing a sanity check here, the two locations at 92 degrees south latitude have around 34 degrees west longitude, which I think is somewhere in the Atlantic, but south of the South Pole.

Switching to 34 degrees north 92 degrees west puts them in North America, where they are expected.

I will have to check the provenance of this data, but I believe it comes from a multi-billion dollar corporation. Everyone makes mistakes, folks!

Replied to John Beales

And I found a page that says:

“Consequently CRS created with the "EPSG:4326" or "WGS84" strings use the latitude first, longitude second axis order.”
- gdal.org/tutorials/osr_api_tut

I reversed the arguments, and I still get an error:

"Query 1 ERROR at Line 8: : Latitude -92.163290 is out of range in function st_geometryfromtext. It must be within [-90.000000, 90.000000].”

Let’s go looking…

SELECT * FROM location WHERE latitude LIKE '%-92.16%';

I get two results with latitudes above 90 degrees… it seems I have a data problem. These results are imported from an external data source, it seems I need to add an additional sanity check to my data importer.

gdal.orgOGR Coordinate Reference Systems and Coordinate Transformation tutorial — GDAL documentation
Replied to John Beales

Following up on this, I found this gem in the MySQL docs:

“By default, geographic coordinates (latitude, longitude) are interpreted as in the order specified by the spatial reference system of geometry arguments.”
- dev.mysql.com/doc/refman/8.4/e

So it seems that the WKT for a point isn’t always POINT(x y) and I need to look up the order that WGS 84 expects.

dev.mysql.comMySQL :: MySQL 8.4 Reference Manual :: 14.16.3 Functions That Create Geometry Values from WKT Values
Replied to John Beales

So my migration is able to add the column, but the query to set the data based on the existing latitude & longitude columns is failing with this error:

3617 Latitude -90.134513 is out of range in function st_geometryfromtext. It must be within [-90.000000, 90.000000]

My query is:
UPDATE locations SET location=ST_GeometryFromText(CONCAT('POINT(',longitude,' ',latitude,')'), 4326))

It seems that the WKT for POINT(x y) might be expecting latitude to be the first value, but all the documentation I can find for WKT suggests that longitude, (the “x” value in a cartesian earth), should be first.

It seems that I need to investigate further - I don’t want all my latitudes & longitudes reversed!

Replied to John Beales

Today's part of the mission: create the migration and make it work. I want:

- A new column with the type ‘point’
- A spatial index on that column that I can use to get locations within an area.

There are some caveats in MySQL:
- point columns cannot have a default value
- columns with spatial indexes must be not null, and have an SRID set.

So the current plan is:
1. Create the column as a nullable column
2. Set the point data using the existing latitude & longitude columns
3. Alter the table so it is no longer nullable
4. Create the spatial index

Working on modernizing the way geographic data is stored in a Laravel/MySQL app this morning, and ended up down an internet rabbit hole of Spatial Reference Systems.

TL;DR as I understand it is that unless you know you want something else, you probably want to use WGS 84 / SRID 4326 for MySQL geographic columns.

Duplicate Orders in WooCommerce:

Before I build it, does anyone have a great solution to prevent customers from ordering twice by accident?

Sometimes customers are submitting multiple orders a few minutes apart when they really only want one item. I’m looking for a way to either put up an “Are you sure?” dialog or simply block orders within a certain timespan.

If a solution doesn’t exist I’ll build it, so if you need this functionality let me know and maybe you can help test what I build.

Replied to John Beales

And solved.

It turns out that in a custom plugin I wrote, I was exiting early from a function that I had hooked onto posts_search - a good thing! But I didn’t return the unchanged SQL, I just returned null, oops!

Changing:

return;

to

return $sql;

fixes the problem.

Xdebug saves the day!

Replied to John Beales

Half an hour to get Xdebug working and I already had it installed! 😬

It seems that while I had Xdebug installed, I did not have the xdebug.ini file I needed. Now that’s fixed, let’s start stepping through code.

Time for some live-tooting of debugging a problem I’m having in a client’s WordPress install.

The Problem:
When updating the product gallery for a WooCommerce product, the search box doesn’t seem to filter anything at all.

Background:
- The site is old, but has received many updates over the years.
- WordPress + WooCommerce + some other plugins.
- I like code, so no site builder.

I did some debugging the other day and narrowed the problem down to the posts_search filter in the WP Query class. Before running the filter the SQL to filter by the search parameter is there, but after running the filter it is not.

Doing a print_r() on the global $wp_filter it seems like nothing is hooked onto the posts_search filter.

At this point I think I should fire up a an actual debugger and follow along as the code is executed.

So, now I need to learn to get XDebug running in a WordPress site hosted locally with Laravel Valet.