aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-05-14 13:50:49 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-05-14 13:50:49 +0000
commit1119cf74af4e3fdc0b81e0667ba7f76f25313cc3 (patch)
treec08e719f5857618ac9d31ba71c346e463c05d024 /engine
parentcc2793708d645c7409576dd8cfca255eecfd01b6 (diff)
downloadelgg-1119cf74af4e3fdc0b81e0667ba7f76f25313cc3.tar.gz
elgg-1119cf74af4e3fdc0b81e0667ba7f76f25313cc3.tar.bz2
Fixed geocode stuff + version bump
git-svn-id: https://code.elgg.org/elgg/trunk@3289 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/location.php17
-rw-r--r--engine/schema/mysql.sql2
-rw-r--r--engine/schema/upgrades/2009051401.sql5
3 files changed, 18 insertions, 6 deletions
diff --git a/engine/lib/location.php b/engine/lib/location.php
index 482a241b4..69e2fe2b1 100644
--- a/engine/lib/location.php
+++ b/engine/lib/location.php
@@ -59,23 +59,30 @@
{
global $CONFIG;
+ // Handle cases where we are passed an array (shouldn't be but can happen if location is a tag field)
+ if (is_array($location))
+ $location = implode(', ', $location);
+
$location = sanitise_string($location);
// Look for cached version
$cached_location = get_data_row("SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='$location'");
- // Trigger geocode event
+ if ($cached_location)
+ return array('lat' => $cached_location->lat, 'long' => $cached_location->long);
+
+ // Trigger geocode event if not cached
$return = false;
- $return = trigger_plugin_hook('geocode', 'location', array('location' => $location, $return));
+ $return = trigger_plugin_hook('geocode', 'location', array('location' => $location), $return);
// If returned, cache and return value
if (($return) && (is_array($return)))
{
- $lat = (int)$return['lat'];
- $long = (int)$return['long'];
+ $lat = (float)$return['lat'];
+ $long = (float)$return['long'];
// Put into cache at the end of the page since we don't really care that much
- execute_delayed_write_query("INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache (lat, long) VALUES ({$lat}, {$long}) ON DUPLICATE KEY UPDATE lat={$lat} long={$long}");
+ execute_delayed_write_query("INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache (location, lat, `long`) VALUES ('$location', '{$lat}', '{$long}') ON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'");
}
return $return;
diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql
index 2c32482be..e8d823a3b 100644
--- a/engine/schema/mysql.sql
+++ b/engine/schema/mysql.sql
@@ -284,7 +284,7 @@ CREATE TABLE `prefix_geocode_cache` (
`long` varchar(20),
PRIMARY KEY (`id`),
- KEY `location` (`location`)
+ UNIQUE KEY `location` (`location`)
) ENGINE=MEMORY;
diff --git a/engine/schema/upgrades/2009051401.sql b/engine/schema/upgrades/2009051401.sql
new file mode 100644
index 000000000..57348968e
--- /dev/null
+++ b/engine/schema/upgrades/2009051401.sql
@@ -0,0 +1,5 @@
+-- Fix error in geocode cache table
+DELETE FROM `prefix_geocode_cache`;
+
+ALTER TABLE `prefix_geocode_cache` DROP KEY `location`;
+ALTER TABLE `prefix_geocode_cache` ADD UNIQUE KEY `location` (`location`);