Merge pull request #17808 from colemanw/bridge
[civicrm-core.git] / sql / GenerateData.php
index 8875a4081f85e61f61a1a4808086d4e1322fe872..ee6b869bc5613956308a6d07bfc58d18b51b50da 100644 (file)
@@ -13,8 +13,6 @@
  *
  * @package CRM
  * @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id$
- *
  */
 
 /**
@@ -270,6 +268,7 @@ class CRM_GCD {
 
   private $groupMembershipStatus = array('Added', 'Removed', 'Pending');
   private $subscriptionHistoryMethod = array('Admin', 'Email');
+  private $deceasedContactIds = array();
 
   /*********************************
    * private methods
@@ -649,7 +648,13 @@ class CRM_GCD {
       }
 
       // Deceased probability based on age
-      if ($age > 40) {
+      if ($contact->gender_id && $contact->gender_id == 2) {
+        $checkAge = 64;
+      }
+      else {
+        $checkAge = 68;
+      }
+      if ($age > $checkAge && count($this->deceasedContactIds) < 4) {
         $contact->is_deceased = $this->probability(($age - 30) / 100);
         if ($contact->is_deceased && $this->probability(.7)) {
           $contact->deceased_date = $this->randomDate();
@@ -686,6 +691,9 @@ class CRM_GCD {
       $contact->hash = crc32($contact->sort_name);
       $contact->id = $cid;
       $this->_update($contact);
+      if ($contact->is_deceased) {
+        $this->deceasedContactIds[] = $cid;
+      }
     }
   }
 
@@ -1259,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'));
+    }
+
+    $zipCode = $zipCodes[mt_rand(0, count($zipCodes))];
 
-      $zip = str_pad($dao->zip, 5, '0', STR_PAD_LEFT);
-      return array(1228, $stateID, $dao->city, $zip, $dao->latitude, $dao->longitude);
+    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);
   }
 
   /**