Hotfix for foreign keys in profile_address edition (Closes #1228)
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 5 Sep 2010 23:02:12 +0000 (01:02 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 5 Sep 2010 23:09:51 +0000 (01:09 +0200)
Some foreign_key-referenced fields where empty (''), which meant
inserting '' into the DB instead of NULL.

There might be other similar issues with other foreign keys.

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
modules/profile/addresses.inc.php

index 9722476..6fe6f75 100644 (file)
@@ -94,6 +94,15 @@ class ProfileSettingAddress extends ProfileSettingGeocoding
         Geocoder::getAreaId($address, "administrativeArea");
         Geocoder::getAreaId($address, "subAdministrativeArea");
         Geocoder::getAreaId($address, "locality");
+
+        // Cleanup foreign keys
+        $foreign_keys = array('localityId', 'subAdministrativeAreaId', 'administrativeAreaId', 'countryId');
+        foreach ($foreign_keys as $key) {
+            if ($address[$key] == '') {
+                $address[$key] = null;
+            }
+        }
+
         XDB::execute("INSERT INTO  profile_addresses (pid, type, id, flags, accuracy,
                                                       text, postalText, postalCode, localityId,
                                                       subAdministrativeAreaId, administrativeAreaId,