Merge pull request #17808 from colemanw/bridge
[civicrm-core.git] / sql / GenerateData.php
index 057d8af5a13643d39e93d3f1472d5089f484d098..ee6b869bc5613956308a6d07bfc58d18b51b50da 100644 (file)
@@ -13,8 +13,6 @@
  *
  * @package CRM
  * @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id$
- *
  */
 
 /**
@@ -1269,21 +1267,22 @@ class CRM_GCD {
       }
     }
 
-    $offset = mt_rand(1, 43000);
-    $query = "SELECT city, state, zip, latitude, longitude FROM zipcodes LIMIT $offset, 1";
-    $dao = new CRM_Core_DAO();
-    $dao->query($query);
-    while ($dao->fetch()) {
-      if ($this->stateMap[$dao->state]) {
-        $stateID = $this->stateMap[$dao->state];
-      }
-      else {
-        $stateID = 1004;
-      }
+    static $zipCodes = NULL;
+    if ($zipCodes === NULL) {
+      $zipCodes = json_decode(file_get_contents(__DIR__ . '/zipcodes.json'));
+    }
 
-      $zip = str_pad($dao->zip, 5, '0', STR_PAD_LEFT);
-      return array(1228, $stateID, $dao->city, $zip, $dao->latitude, $dao->longitude);
+    $zipCode = $zipCodes[mt_rand(0, count($zipCodes))];
+
+    if ($this->stateMap[$zipCode->state]) {
+      $stateID = $this->stateMap[$zipCode->state];
+    }
+    else {
+      $stateID = 1004;
     }
+
+    $zip = str_pad($zipCode->zip, 5, '0', STR_PAD_LEFT);
+    return array(1228, $stateID, $zipCode->city, $zip, $zipCode->latitude, $zipCode->longitude);
   }
 
   /**