mirror of
https://github.com/espocrm/espocrm.git
synced 2026-07-01 08:26:04 +00:00
array merge fixes
This commit is contained in:
@@ -142,7 +142,7 @@ class Util
|
||||
if ($appendKey !== false) {
|
||||
unset($newArray[$currentName][$appendKey]);
|
||||
$newArray[$currentName] = array_merge($currentValue, $newArray[$currentName]);
|
||||
} else {
|
||||
} else if (!static::isSingleArray($newArray[$currentName])) {
|
||||
$newArray[$currentName] = static::merge($currentValue, $newArray[$currentName]);
|
||||
}
|
||||
|
||||
@@ -411,6 +411,18 @@ class Util
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function isSingleArray(array $array)
|
||||
{
|
||||
foreach ($array as $key => $value) {
|
||||
if (!is_int($key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -449,38 +449,137 @@ class UtilTest extends \PHPUnit_Framework_TestCase
|
||||
$result = array (
|
||||
'fields' =>
|
||||
array (
|
||||
'accountName' =>
|
||||
array (
|
||||
'type' => 'foreign',
|
||||
'relation' => 'account',
|
||||
'foreign' => 'name',
|
||||
),
|
||||
'accountId' =>
|
||||
array (
|
||||
'type' => 'foreignId',
|
||||
'index' => true,
|
||||
'where' =>
|
||||
array (
|
||||
'=' => 'contact.id IN ({value})',
|
||||
),
|
||||
'len' => 255,
|
||||
),
|
||||
'deleted' =>
|
||||
array (
|
||||
'type' => 'bool',
|
||||
'default' => false,
|
||||
'trueValue' => true,
|
||||
),
|
||||
'accountName' =>
|
||||
array (
|
||||
'type' => 'foreign',
|
||||
'relation' => 'account',
|
||||
'foreign' => 'name',
|
||||
),
|
||||
'accountId' =>
|
||||
array (
|
||||
'type' => 'foreignId',
|
||||
'index' => true,
|
||||
'where' =>
|
||||
array (
|
||||
'=' => 'contact.id IN ({value})',
|
||||
),
|
||||
'len' => 255,
|
||||
),
|
||||
'deleted' =>
|
||||
array (
|
||||
'type' => 'bool',
|
||||
'default' => false,
|
||||
'trueValue' => true,
|
||||
),
|
||||
),
|
||||
'relations' =>
|
||||
array (
|
||||
'createdBy' =>
|
||||
array (
|
||||
'type' => 'belongsTo',
|
||||
'entity' => 'User',
|
||||
'key' => 'createdById',
|
||||
'foreignKey' => 'id',
|
||||
),
|
||||
'createdBy' =>
|
||||
array (
|
||||
'type' => 'belongsTo',
|
||||
'entity' => 'User',
|
||||
'key' => 'createdById',
|
||||
'foreignKey' => 'id',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals($result, Util::merge($currentArray, $newArray));
|
||||
}
|
||||
|
||||
public function testMergeWithFieldsDefs()
|
||||
{
|
||||
$currentArray = array (
|
||||
'fields' =>
|
||||
array (
|
||||
'aaa1' =>
|
||||
array (
|
||||
'type' => 'enum',
|
||||
'required' => false,
|
||||
'options' =>
|
||||
array (
|
||||
0 => 'a1',
|
||||
1 => 'a3',
|
||||
2 => 'a3',
|
||||
),
|
||||
'isCustom' => true,
|
||||
),
|
||||
'hfghgfh' =>
|
||||
array (
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'isCustom' => true,
|
||||
'default' => 'hfghfgh',
|
||||
),
|
||||
'jghjghj' =>
|
||||
array (
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'isCustom' => true,
|
||||
'default' => 'jghjghjhg',
|
||||
),
|
||||
'gdfgdfg' =>
|
||||
array (
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'isCustom' => true,
|
||||
'default' => 'gdfgdfg',
|
||||
'maxLength' => 70,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$newArray = array (
|
||||
'fields' =>
|
||||
array (
|
||||
'aaa1' =>
|
||||
array (
|
||||
'type' => 'enum',
|
||||
'required' => false,
|
||||
'options' =>
|
||||
array (
|
||||
0 => 'a1',
|
||||
),
|
||||
'isCustom' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$result = array (
|
||||
'fields' =>
|
||||
array (
|
||||
'aaa1' =>
|
||||
array (
|
||||
'type' => 'enum',
|
||||
'required' => false,
|
||||
'options' =>
|
||||
array (
|
||||
0 => 'a1',
|
||||
),
|
||||
'isCustom' => true,
|
||||
),
|
||||
'hfghgfh' =>
|
||||
array (
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'isCustom' => true,
|
||||
'default' => 'hfghfgh',
|
||||
),
|
||||
'jghjghj' =>
|
||||
array (
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'isCustom' => true,
|
||||
'default' => 'jghjghjhg',
|
||||
),
|
||||
'gdfgdfg' =>
|
||||
array (
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'isCustom' => true,
|
||||
'default' => 'gdfgdfg',
|
||||
'maxLength' => 70,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user