Merge branch 'hotfix/4.4.1'

This commit is contained in:
yuri
2017-02-02 11:25:53 +02:00
7 changed files with 80 additions and 39 deletions
@@ -1,4 +1,4 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
@@ -1,4 +1,4 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
@@ -32,7 +32,7 @@ namespace Espo\Core\Formula\Functions\EntityGroup;
use \Espo\ORM\Entity;
use \Espo\Core\Exceptions\Error;
class AttributeFetchedType extends \Espo\Core\Formula\Functions\AttributeType
class AttributeFetchedType extends AttributeType
{
protected function getAttributeValue($attribute)
{
@@ -1,4 +1,4 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
@@ -34,4 +34,22 @@ use \Espo\Core\Exceptions\Error;
class AttributeType extends \Espo\Core\Formula\Functions\AttributeType
{
public function process(\StdClass $item)
{
if (!property_exists($item, 'value')) {
throw new Error();
}
if (!is_array($item->value)) {
throw new Error();
}
if (count($item->value) < 1) {
throw new Error();
}
$attribute = $this->evaluate($item->value[0]);
return $this->getAttributeValue($attribute);
}
}
@@ -1,4 +1,4 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
@@ -40,30 +40,21 @@ class IsAttributeChangedType extends \Espo\Core\Formula\Functions\Base
throw new Error();
}
$attributeList = [];
if (is_array($item->value)) {
$attributeList = $attribute;
foreach ($item->value as $value) {
$attribute = $this->evaluate($item->value);
$attributeList[] = $attribute;
}
} else {
$attribute = $this->evaluate($item->value);
$attributeList[] = $attribute;
if (!is_array($item->value)) {
throw new Error();
}
return $this->check($attributeList);
if (count($item->value) < 1) {
throw new Error();
}
$attribute = $this->evaluate($item->value[0]);
return $this->check($attribute);
}
protected function check(array $attributeList)
protected function check($attribute)
{
$result = true;
foreach ($attributeList as $i => $attribute) {
if (!$this->getEntity()->isAttributeChanged($attribute)) {
$result = false;
break;
}
}
return $result;
return $this->getEntity()->isAttributeChanged($attribute);
}
}
@@ -1,4 +1,4 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
@@ -33,8 +33,8 @@ use \Espo\ORM\Entity;
class IsAttributeNotChangedType extends IsAttributeChangedType
{
protected function check(array $attributeList)
protected function check($attribute)
{
return !parent::check($attributeList);
return !parent::check($attribute);
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
+42 -10
View File
@@ -139,12 +139,40 @@ class FormulaTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('Test', $result);
}
function testAttributeFetched()
function testEntityAttribute()
{
$item = json_decode('
{
"type": "entity\\\\attribute",
"value": [
{
"type": "value",
"value": "name"
}
]
}
');
$this->setEntityAttributes($this->entity, array(
'name' => 'Test'
));
$result = $this->formula->process($item, $this->entity);
$this->assertEquals('Test', $result);
}
function testEntityAttributeFetched()
{
$item = json_decode('
{
"type": "entity\\\\attributeFetched",
"value": "name"
"value": [
{
"type": "value",
"value": "name"
}
]
}
');
@@ -162,10 +190,12 @@ class FormulaTest extends \PHPUnit_Framework_TestCase
$item = json_decode('
{
"type": "entity\\\\isAttributeChanged",
"value": {
"type": "value",
"value": "name"
}
"value": [
{
"type": "value",
"value": "name"
}
]
}
');
@@ -188,10 +218,12 @@ class FormulaTest extends \PHPUnit_Framework_TestCase
$item = json_decode('
{
"type": "entity\\\\isAttributeNotChanged",
"value": {
"type": "value",
"value": "name"
}
"value": [
{
"type": "value",
"value": "name"
}
]
}
');