Don't write a record for geolocation data if we don't have any and
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 18 Dec 2009 05:08:08 +0000 (00:08 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 18 Dec 2009 05:08:08 +0000 (00:08 -0500)
delete the record if one exists but we have no geolocation data.

kronolith/lib/Geo/Mysql.php
kronolith/lib/Geo/Sql.php

index 5104bb9..839e55a 100644 (file)
@@ -30,6 +30,15 @@ class Kronolith_Geo_Mysql extends Kronolith_Geo_Sql
         if ($count instanceof PEAR_Error) {
             throw new Horde_Exception($count->getMessage());
         }
+
+        /* Do we actually have data? */
+        if (!$point && $count) {
+            // Delete the record.
+            $sql = "DELETE FROM kronolith_events_geo WHERE event_id = '" . $event_id . "'";
+        } elseif (!$point) {
+            return;
+        }
+
         /* INSERT or UPDATE */
         if ($count) {
             $sql = "UPDATE kronolith_events_geo SET event_coordinates = GeomFromText('POINT(" . $point['lat'] . " " . $point['lon'] . ")') WHERE event_id = '" . $event_id . "'";
index 844417e..e643293 100644 (file)
@@ -117,6 +117,14 @@ class Kronolith_Geo_Sql extends Kronolith_Geo
             throw new Horde_Exception($count->getMessage());
         }
 
+        /* Do we actually have data? */
+        if (!$point && $count) {
+            // Delete the record.
+            $sql = "DELETE FROM kronolith_events_geo WHERE event_id = '" . $event_id . "'";
+        } elseif (!$point) {
+            return;
+        }
+
         /* INSERT or UPDATE */
         $params = array($point['lat'], $point['lng'], $event_id);
         if ($count) {