-
Notifications
You must be signed in to change notification settings - Fork 49
How to generate data for new Modules
Using Tidbit you can populate custom modules or modules that are not covered by default in Tidbit with your own rules.
By default, Tidbit does not populate modules that are not specified in config/config.php
, so you need two modifications to Tidbit.
- Add new module to
config/config.php
config file - Create custom rules for module fields (required only if customization is needed)
Simply find the line in config/config.php
where $modules array is defined,
$modules = array(
'Tags' => 100,
'EmailAddresses' => 12000,
...
'KBContents' => 1000,
);
and add line with definition for your new module, f.e. "MyTests"
. You should also decide how many records should be populated for new module.
Tidbit is using Accounts module as a baseline to calculate total number of records for almost every module with respect to load factor (-l)
parameter. Please read more about supported CLI arguments in this article. There is a code part that is responsible for such calculation
$factor = $opts['l'] / $modules['Accounts'];
foreach ($modules as $m => $n) {
$modules[$m] *= $factor;
}
f.e when load factor param is 10000, $factor will be 10 (10000 / 1000), so total number of Notes
will be 40000.
Let's assume you choose 2000 as default number for new "MyTests"
module, so final line to insert into $modules array will be
$modules = array(
...
'MyTests' => 2000,
);
There are two places in code, where Tidbit is looking for data generation rules
-
./config/data/DefaultData.php
- responsible for default rules that could be found by field name or field db type. Used to define very generic rules -
./config/data/{moduleName}.php
- responsible for module specific rules, also supports defining rules by field name or db type. Used to define rules for one module
Knowing that, if your new module "MyTests"
contains only fields that already defined in DefaultData.php
file, creating of new file ./config/data/MyTests.php
is not necessary.
If your module contains custom fields or other fields that need to have custom rules, then create new file in Data directory with module name filename and specify fields you want to customized. Please note, that any rules defined for a field in ./config/data/MyTests.php
will override ./Data/DefaultData.php
rules.
Let's say, we need to add new rules for 2 fields: "my_custom_amount_1"
and "my_custom_amount_2"
that should contain some random integer numbers. In this case we to add those lines to ./Data/MyTests.php
file
$GLOBALS['dataTool']['MyTests']['my_custom_amount_1'] = array('range' => array('min' => 0, 'max' => 100));
$GLOBALS['dataTool']['MyTests']['my_custom_amount_2'] = array('range' => array('min' => 0, 'max' => 100));
For more information about supported data generation rules and example please read this article Also, please check existing examples below and in code
Defining Opportunities module data population
$GLOBALS['dataTool']['Opportunities']['amount'] = array('range' => array('min' => 500, 'max' => 1000000));
$GLOBALS['dataTool']['Opportunities']['amount_usdollar'] = array('range' => array('min' => 500, 'max' => 1000000));
$GLOBALS['dataTool']['Opportunities']['account_id'] = array('related' => array('module' => 'Accounts'));
$GLOBALS['dataTool']['Opportunities']['probability'] = array('range' => array('min' => 0, 'max' => 100));
Defining EmailAddresses field rules
$GLOBALS['dataTool']['EmailAddresses']['email_address'] = array('list' => 'last_name_array', 'suffix' => "@example.com");
$GLOBALS['dataTool']['EmailAddresses']['email_address_caps'] = array('same' => 'email_address', 'toUpper' => true);
Please submit your questions or documentation issues in Issues section