Solving RT ticket #1092988
[civicrm-core.git] / sql / GenerateData.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates data for the schema located in Contact.sql
20 *
21 * each public method generates data for the concerned table.
22 * so for example the addContactDomain method generates and adds
23 * data to the contact_domain table
24 *
25 * Data generation is a bit tricky since the data generated
26 * randomly in one table could be used as a FKEY in another
27 * table.
28 *
29 * In order to ensure that a randomly generated FKEY matches
30 * a field in the referened table, the field in the referenced
31 * table is always generated linearly.
32 *
33 *
34 *
35 *
36 * Some numbers
37 *
38 * Domain ID's - 1 to NUM_DOMAIN
39 *
40 * Context - 3/domain
41 *
42 * Contact - 1 to NUM_CONTACT
43 * 80% - Individual
44 * 10% - Household
45 * 10% - Organization
46 *
47 * Contact to Domain distribution should be equal.
48 *
49 *
50 * Contact Individual = 1 to 0.8*NUM_CONTACT
51 *
52 * Contact Household = 0.8*NUM_CONTACT to 0.9*NUM_CONTACT
53 *
54 * Contact Organization = 0.9*NUM_CONTACT to NUM_CONTACT
55 *
56 * Assumption is that each household contains 4 individuals
57 *
58 */
59
60 /**
61 *
62 * Note: implication of using of mt_srand(1) in constructor
63 * The data generated will be done in a consistent manner
64 * so as to give the same data during each run (but this
65 * would involve populating the entire db at one go - since
66 * mt_srand(1) is in the constructor, if one needs to be able
67 * to get consistent random numbers then the mt_srand(1) shld
68 * be in each function that adds data to each table.
69 *
70 */
71
72 if (!(php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0))) {
73 header("HTTP/1.0 404 Not Found");
74 return;
75 }
76
77 require_once '../civicrm.config.php';
78 CRM_Core_Config::singleton();
79
80 echo ("Starting data generation on " . date("F dS h:i:s A") . "\n");
81 try {
82 // Generate reproducible data-set
83 // $gcd = new CRM_Core_CodeGen_GenerateData('1234', strtotime(date('Y') . '-01-01 02:03:04'));
84 // Generate unique data-set
85 $gcd = new CRM_Core_CodeGen_GenerateData(time(), time());
86 $gcd->generateAll();
87 }
88 catch (Exception $e) {
89 echo CRM_Core_Error::formatTextException($e);
90 }
91 echo ("Ending data generation on " . date("F dS h:i:s A") . "\n");