Skip to content

Commit

Permalink
ABS-1410: Filtered fields before starting data generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulitsa authored and ramanenka committed Mar 1, 2018
1 parent b141d14 commit f09a514
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 47 deletions.
2 changes: 1 addition & 1 deletion install_cli.php
Expand Up @@ -275,7 +275,7 @@
}

$dTool = new \Sugarcrm\Tidbit\DataTool($storageType);
$dTool->fields = $bean->field_defs;
$dTool->setFields($bean->field_defs);

$dTool->table_name = $bean->getTableName();
$dTool->module = $module;
Expand Down
30 changes: 26 additions & 4 deletions src/DataTool.php
Expand Up @@ -59,7 +59,7 @@ class DataTool
public $installDataCstm = array();

/** @var array stores fields and its values from vardefs.php for every module */
public $fields = array();
protected $fields = array();
public $table_name = '';
public $module = '';
public $count = 0;
Expand Down Expand Up @@ -112,6 +112,31 @@ public function __construct($storageType)
$this->coreIntervals = CoreFactory::getComponent('Intervals');
}

/**
* Getter for filtered fields data from vardef.php
*
* @return array
*/
public function getFields()
{
return $this->fields;
}

/**
* It takes fields from vardef.php for a module, filters it and sets filtered array to $fields variable.
*
* @param $fds array - Value of 'fields' key from vardef.php for a module.
*/
public function setFields($fds)
{
foreach ($fds as $f => $dt) {
if ((!empty($fds[$f]['source']) && $fds[$f]['source'] != 'custom_fields')
|| isset($GLOBALS['dataTool'][$this->module][$f]['skip'])) {
unset($fds[$f]);
}
}
$this->fields = $fds;
}


/**
Expand All @@ -121,9 +146,6 @@ public function __construct($storageType)
public function generateData()
{
foreach ($this->fields as $field => $data) {
if (!empty($this->fields[$field]['source']) && $this->fields[$field]['source'] != 'custom_fields') {
continue;
}
if (isset($this->installData[$field])) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Common.php
Expand Up @@ -256,7 +256,7 @@ protected function getDataToolForModel($modelName, $modelCounter)
$bean = \BeanFactory::getBean($modelName);

$dataTool = new DataTool($this->storageType);
$dataTool->fields = $bean->field_defs;
$dataTool->setFields($bean->field_defs);
$dataTool->table_name = $bean->table_name;
$dataTool->module = $modelName;
$dataTool->count = $modelCounter;
Expand Down
18 changes: 9 additions & 9 deletions tests/DataTool/Types/HandleBasicTest.php
Expand Up @@ -102,11 +102,11 @@ public function testSumType()

$type = array('sum' => array('subtotal', 'shipping', 'tax'));

$this->dataTool->fields = array(
$this->dataTool->setFields([
'subtotal' => 'subtotal',
'shipping' => 'shipping',
'tax' => 'tax',
);
'tax' => 'tax'
]);

$this->dataTool->installData = array(
'subtotal' => 10,
Expand All @@ -127,11 +127,11 @@ public function testSumReturnIsNotNumericType()

$type = array('sum' => array('subtotal', 'shipping', 'tax'));

$this->dataTool->fields = array(
$this->dataTool->setFields([
'subtotal' => 'subtotal',
'shipping' => 'shipping',
'tax' => 'tax',
);
'tax' => 'tax'
]);

$this->dataTool->installData = array(
'subtotal' => 10,
Expand All @@ -152,10 +152,10 @@ public function testSumFieldsPlusNumericValuesType()

$type = array('sum' => array('subtotal', 20, 'tax'));

$this->dataTool->fields = array(
$this->dataTool->setFields([
'subtotal' => 'subtotal',
'tax' => 'tax',
);
'tax' => 'tax'
]);

$this->dataTool->installData = array(
'subtotal' => 10,
Expand Down
16 changes: 8 additions & 8 deletions tests/DataTool/Types/RangeTest.php
Expand Up @@ -123,9 +123,9 @@ public function testSameDatetimeType()
{
$type = array('same_datetime' => 'field1');

$this->dataTool->fields = array(
'field1' => 'field1',
);
$this->dataTool->setFields([
'field1' => 'field1'
]);

$expectedDatetime = "'2016-05-20 10:12:13'";

Expand Down Expand Up @@ -173,10 +173,10 @@ public function testSameDatetimeModifyByFieldType()
)
);

$this->dataTool->fields = array(
$this->dataTool->setFields([
'field1' => 'field1',
'duration_hours' => 'duration_hours'
);
]);

$expectedDatetime = "'2016-05-20 10:12:13'";

Expand Down Expand Up @@ -209,9 +209,9 @@ public function testSameDatetimeModifyByConstantType()
)
);

$this->dataTool->fields = array(
'field1' => 'field1',
);
$this->dataTool->setFields([
'field1' => 'field1'
]);

$expectedDatetime = "'2016-05-20 10:12:13'";

Expand Down
48 changes: 24 additions & 24 deletions tests/DataTool/Types/SameTest.php
Expand Up @@ -46,11 +46,11 @@ public function testSumRefType()
)
));

$this->dataTool->fields = array(
$this->dataTool->setFields([
'field1' => 'field1',
'field2' => 'field2',
'field3' => 'field3',
);
'field3' => 'field3'
]);

$this->dataTool->installData = array(
'field1' => 10,
Expand All @@ -68,9 +68,9 @@ public function testSumRefType()
public function testSameType()
{
$type = array('same' => 'field1');
$this->dataTool->fields = array(
'field1' => 'field1',
);
$this->dataTool->setFields([
'field1' => 'field1'
]);

$expected = 'some_test_value';
$this->dataTool->installData['field1'] = $expected;
Expand Down Expand Up @@ -98,9 +98,9 @@ public function testSameNotStringType()
public function testSameValueTrimType()
{
$type = array('same' => 'field1');
$this->dataTool->fields = array(
'field1' => 'field1',
);
$this->dataTool->setFields([
'field1' => 'field1'
]);

$expected = ' some_test_value ';
$this->dataTool->installData['field1'] = $expected;
Expand All @@ -115,9 +115,9 @@ public function testSameValueTrimType()
public function testSameToUpperType()
{
$type = array('same' => 'field1', 'toUpper' => true);
$this->dataTool->fields = array(
'field1' => 'field1',
);
$this->dataTool->setFields([
'field1' => 'field1'
]);

$expected = 'some_test_value';
$this->dataTool->installData['field1'] = $expected;
Expand All @@ -132,9 +132,9 @@ public function testSameToUpperType()
public function testSameToLowerType()
{
$type = array('same' => 'field1', 'toLower' => true);
$this->dataTool->fields = array(
'field1' => 'field1',
);
$this->dataTool->setFields([
'field1' => 'field1'
]);

$expected = 'some_TesT_value';
$this->dataTool->installData['field1'] = $expected;
Expand All @@ -151,9 +151,9 @@ public function testSameToLowerType()
public function testSameHashType()
{
$type = array('same_hash' => 'field1');
$this->dataTool->fields = array(
'field1' => 'field1',
);
$this->dataTool->setFields([
'field1' => 'field1'
]);

$expected = 'field1 value';
$this->dataTool->installData['field1'] = "'" . $expected . "'";
Expand All @@ -171,9 +171,9 @@ public function testSameHashType()
public function testSameHashIntegerType()
{
$type = array('same_hash' => 'field1');
$this->dataTool->fields = array(
'field1' => 'field1',
);
$this->dataTool->setFields([
'field1' => 'field1'
]);

$expected = 20;
$this->dataTool->installData['field1'] = $expected;
Expand Down Expand Up @@ -209,9 +209,9 @@ public function testSameHashIntegerValueType()
public function testSameSugarHashType()
{
$type = array('same_sugar_hash' => 'field1');
$this->dataTool->fields = array(
'field1' => 'field1',
);
$this->dataTool->setFields([
'field1' => 'field1'
]);

$GLOBALS['sugar_config'] = array('sugar_version' => '7.6.2');

Expand Down

0 comments on commit f09a514

Please sign in to comment.