(REF) GenerateData - Allow external control randomness
authorTim Otten <totten@civicrm.org>
Wed, 16 Sep 2020 09:58:36 +0000 (02:58 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 16 Sep 2020 11:09:30 +0000 (04:09 -0700)
CRM/Core/CodeGen/GenerateData.php
sql/GenerateData.php

index 3d7268f5208117abb485e4a2300e15709791958d..31a2352c3f8c28df87b510a1a46e32d0ed6c20b3 100644 (file)
@@ -26,11 +26,16 @@ class CRM_Core_CodeGen_GenerateData {
 
   /**
    * Class constructor
+   *
+   * @param string|int $seed
+   *   Some scalar value used as the starting point for random-number generation.
+   * @param int $time
+   *   A timestamp; some facsimile of "now".
    */
-  public function __construct($seed = '123456789') {
+  public function __construct($seed, $time) {
     // initialize all the vars
     $this->seed = $seed;
-    $this->time = strtotime(date('Y') . '-01-01 02:03:04');
+    $this->time = $time;
     $this->numIndividual = self::INDIVIDUAL_PERCENT * self::NUM_CONTACT / 100;
     $this->numHousehold = self::HOUSEHOLD_PERCENT * self::NUM_CONTACT / 100;
     $this->numOrganization = self::ORGANIZATION_PERCENT * self::NUM_CONTACT / 100;
index 977a251b06de235c2bb97d64e263148b501fcc85..6928bf57afb8dec71a7ae15fe637f4610900dfe8 100644 (file)
@@ -76,7 +76,10 @@ CRM_Core_Config::singleton();
 echo ("Starting data generation on " . date("F dS h:i:s A") . "\n");
 try {
   $scope = CRM_Core_TemporaryErrorScope::useException();
-  $gcd = new CRM_Core_CodeGen_GenerateData();
+  // Generate reproducible data-set
+  // $gcd = new CRM_Core_CodeGen_GenerateData('1234', strtotime(date('Y') . '-01-01 02:03:04'));
+  // Generate unique data-set
+  $gcd = new CRM_Core_CodeGen_GenerateData(time(), time());
   $gcd->generateAll();
 }
 catch (Exception $e) {