mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 23:16:03 +00:00
Bug fixing
This commit is contained in:
@@ -394,12 +394,6 @@ class Util
|
||||
$unsets = (array) $unsets;
|
||||
}
|
||||
|
||||
if (!isset($content)) {
|
||||
$e = new \Exception;
|
||||
var_dump($e->getTraceAsString());
|
||||
die;
|
||||
}
|
||||
|
||||
foreach ($unsets as $rootKey => $unsetItem) {
|
||||
$unsetItem = is_array($unsetItem) ? $unsetItem : (array) $unsetItem;
|
||||
|
||||
@@ -414,10 +408,17 @@ class Util
|
||||
$elem = & $content;
|
||||
for ($i = 0; $i <= $keyChainCount; $i++) {
|
||||
|
||||
if (array_key_exists($keyСhain[$i], $elem)) {
|
||||
if (is_array($elem) && array_key_exists($keyСhain[$i], $elem)) {
|
||||
|
||||
if ($i == $keyChainCount) {
|
||||
|
||||
unset($elem[$keyСhain[$i]]);
|
||||
|
||||
if ($unsetParentEmptyArray && is_array($elem) && empty($elem)) {
|
||||
unset($keyСhain[$i]);
|
||||
$content = static::unsetInArray($content, implode('.', $keyСhain), false);
|
||||
}
|
||||
|
||||
} else if (is_array($elem[$keyСhain[$i]])) {
|
||||
$elem = & $elem[$keyСhain[$i]];
|
||||
}
|
||||
|
||||
@@ -1316,6 +1316,38 @@ class UtilTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($result, Util::unsetInArray($input, $unsets));
|
||||
}
|
||||
|
||||
public function testUnsetInArrayEmptyParent()
|
||||
{
|
||||
$input = array(
|
||||
'Account' => array(
|
||||
'useCache' => true,
|
||||
'sub' => array (
|
||||
'subV' => '125',
|
||||
'subO' => array(
|
||||
'subOV' => '125',
|
||||
'subOV2' => '125',
|
||||
),
|
||||
),
|
||||
),
|
||||
'Contact' => array(
|
||||
'useCache' => true,
|
||||
),
|
||||
);
|
||||
|
||||
$unsets = array(
|
||||
'Account.useCache',
|
||||
'Account.sub',
|
||||
);
|
||||
|
||||
$result = array(
|
||||
'Contact' => array(
|
||||
'useCache' => true,
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals($result, Util::unsetInArray($input, $unsets, true));
|
||||
}
|
||||
|
||||
public function testGetValueByKey()
|
||||
{
|
||||
$inputArray = array(
|
||||
|
||||
Reference in New Issue
Block a user