mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 23:16:03 +00:00
type fixes
This commit is contained in:
@@ -58,6 +58,10 @@ class Argument implements Evaluatable
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!property_exists($this->data, 'type')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->data->type ?? null;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,8 +102,7 @@ class FunctionFactory
|
||||
]);
|
||||
|
||||
if (
|
||||
property_exists($className, 'hasAttributeFetcher') ||
|
||||
method_exists($className, 'setAttributeFetcher')
|
||||
method_exists($object, 'setAttributeFetcher')
|
||||
) {
|
||||
$object->setAttributeFetcher($this->attributeFetcher);
|
||||
}
|
||||
|
||||
@@ -60,11 +60,13 @@ class ClosestType extends BaseFunction implements Di\ConfigAware
|
||||
}
|
||||
|
||||
$inPast = false;
|
||||
|
||||
if (count($args) > 3) {
|
||||
$inPast = $args[3];
|
||||
}
|
||||
|
||||
$timezone = null;
|
||||
|
||||
if (count($args) > 4) {
|
||||
$timezone = $args[4];
|
||||
}
|
||||
@@ -82,6 +84,7 @@ class ClosestType extends BaseFunction implements Di\ConfigAware
|
||||
}
|
||||
|
||||
$isDate = false;
|
||||
|
||||
if (strlen($value) === 10) {
|
||||
$isDate = true;
|
||||
$value .= ' 00:00:00';
|
||||
@@ -95,20 +98,26 @@ class ClosestType extends BaseFunction implements Di\ConfigAware
|
||||
|
||||
/** @var DateTime */
|
||||
$dt = DateTime::createFromFormat($format, $value, new DateTimeZone($timezone));
|
||||
|
||||
$valueTimestamp = $dt->getTimestamp();
|
||||
|
||||
if ($type === 'time') {
|
||||
if (!is_string($target)) {
|
||||
$this->throwBadArgumentType(3, 'string');
|
||||
}
|
||||
|
||||
list($hour, $minute) = explode(':', $target);
|
||||
|
||||
if (!$hour) {
|
||||
$hour = 0;
|
||||
}
|
||||
|
||||
if (!$minute) {
|
||||
$minute = 0;
|
||||
}
|
||||
$dt->setTime($hour, $minute, 0);
|
||||
|
||||
$dt->setTime((int) $hour, (int) $minute, 0);
|
||||
|
||||
if ($valueTimestamp < $dt->getTimestamp()) {
|
||||
if ($inPast) {
|
||||
$dt->modify('-1 day');
|
||||
@@ -118,32 +127,39 @@ class ClosestType extends BaseFunction implements Di\ConfigAware
|
||||
$dt->modify('+1 day');
|
||||
}
|
||||
}
|
||||
} else if ($type === 'hour') {
|
||||
}
|
||||
else if ($type === 'hour') {
|
||||
$target = intval($target);
|
||||
$dt->setTime($target, 0, 0);
|
||||
|
||||
if ($valueTimestamp < $dt->getTimestamp()) {
|
||||
if ($inPast) {
|
||||
$dt->modify('-1 day');
|
||||
}
|
||||
} else if ($valueTimestamp > $dt->getTimestamp()) {
|
||||
}
|
||||
else if ($valueTimestamp > $dt->getTimestamp()) {
|
||||
if (!$inPast) {
|
||||
$dt->modify('+1 day');
|
||||
}
|
||||
}
|
||||
} else if ($type === 'minute') {
|
||||
}
|
||||
else if ($type === 'minute') {
|
||||
$target = intval($target);
|
||||
|
||||
$dt->setTime(intval($dt->format('G')), intval($target), 0);
|
||||
|
||||
if ($valueTimestamp < $dt->getTimestamp()) {
|
||||
if ($inPast) {
|
||||
$dt->modify('-1 hour');
|
||||
}
|
||||
} else if ($valueTimestamp > $dt->getTimestamp()) {
|
||||
}
|
||||
else if ($valueTimestamp > $dt->getTimestamp()) {
|
||||
if (!$inPast) {
|
||||
$dt->modify('+1 hour');
|
||||
}
|
||||
}
|
||||
} else if ($type === 'dayOfWeek') {
|
||||
}
|
||||
else if ($type === 'dayOfWeek') {
|
||||
$target = intval($target);
|
||||
$dt->setTime(0, 0, 0);
|
||||
|
||||
@@ -155,36 +171,45 @@ class ClosestType extends BaseFunction implements Di\ConfigAware
|
||||
if ($inPast) {
|
||||
$dt->modify('-1 week');
|
||||
}
|
||||
} else if ($valueTimestamp > $dt->getTimestamp()) {
|
||||
}
|
||||
else if ($valueTimestamp > $dt->getTimestamp()) {
|
||||
if (!$inPast) {
|
||||
$dt->modify('+1 week');
|
||||
}
|
||||
}
|
||||
} else if ($type === 'date') {
|
||||
}
|
||||
else if ($type === 'date') {
|
||||
$target = intval($target);
|
||||
$dt->setTime(0, 0, 0);
|
||||
|
||||
if ($inPast) {
|
||||
while (true) {
|
||||
$date = intval($dt->format('d'));
|
||||
|
||||
if ($date === $target) {
|
||||
break;
|
||||
}
|
||||
|
||||
$dt->modify('-1 day');
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if ($valueTimestamp > $dt->getTimestamp()) {
|
||||
$dt->modify('+1 day');
|
||||
}
|
||||
|
||||
while (true) {
|
||||
$date = intval($dt->format('d'));
|
||||
|
||||
if ($date === $target) {
|
||||
break;
|
||||
}
|
||||
|
||||
$dt->modify('+1 day');
|
||||
}
|
||||
}
|
||||
} else if ($type === 'month') {
|
||||
}
|
||||
else if ($type === 'month') {
|
||||
$target = intval($target);
|
||||
|
||||
$dt->setTime(0, 0, 0);
|
||||
@@ -194,20 +219,26 @@ class ClosestType extends BaseFunction implements Di\ConfigAware
|
||||
if ($inPast) {
|
||||
while (true) {
|
||||
$month = intval($dt->format('m'));
|
||||
|
||||
if ($month === $target) {
|
||||
break;
|
||||
}
|
||||
|
||||
$dt->modify('-1 month');
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if ($valueTimestamp > $dt->getTimestamp()) {
|
||||
$dt->modify('+1 month');
|
||||
}
|
||||
|
||||
while (true) {
|
||||
$month = intval($dt->format('m'));
|
||||
|
||||
if ($month === $target) {
|
||||
break;
|
||||
}
|
||||
|
||||
$dt->modify('+1 month');
|
||||
}
|
||||
}
|
||||
@@ -219,9 +250,10 @@ class ClosestType extends BaseFunction implements Di\ConfigAware
|
||||
|
||||
if (!$isDate) {
|
||||
$dt->setTimezone(new DateTimeZone('UTC'));
|
||||
|
||||
return $dt->format('Y-m-d H:i');
|
||||
} else {
|
||||
return $dt->format('Y-m-d');
|
||||
}
|
||||
|
||||
return $dt->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ class ApplyTemplateType extends BaseFunction implements
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var \Espo\Services\EmailTemplate */
|
||||
$emailTemplateService = $this->serviceFactory->create('EmailTemplate');
|
||||
|
||||
$params = [];
|
||||
|
||||
@@ -75,7 +75,9 @@ class SendType extends BaseFunction implements
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var \Espo\Services\Email */
|
||||
$service = $this->serviceFactory->create('Email');
|
||||
|
||||
$service->loadAdditionalFields($email);
|
||||
|
||||
$toSave = false;
|
||||
|
||||
@@ -73,6 +73,7 @@ class RetrieveType extends BaseFunction
|
||||
*/
|
||||
private function splitPath(string $path): array
|
||||
{
|
||||
/** @var string[] */
|
||||
$pathArray = preg_split('/(?<!\\\)\./', $path);
|
||||
|
||||
foreach ($pathArray as $i => $item) {
|
||||
|
||||
@@ -48,6 +48,6 @@ class CeilType extends BaseFunction
|
||||
return null;
|
||||
}
|
||||
|
||||
return intval(ceil($value));
|
||||
return intval(ceil((float) $value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,6 @@ class FloorType extends BaseFunction
|
||||
return null;
|
||||
}
|
||||
|
||||
return intval(floor($value));
|
||||
return intval(floor((float) $value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ class RoundType extends BaseFunction
|
||||
$value = $this->evaluate($args[0]);
|
||||
|
||||
$precision = 0;
|
||||
|
||||
if (count($args) > 1) {
|
||||
$precision = $this->evaluate($args[1]);
|
||||
}
|
||||
@@ -53,6 +54,6 @@ class RoundType extends BaseFunction
|
||||
return null;
|
||||
}
|
||||
|
||||
return round($value, $precision);
|
||||
return round((float) $value, $precision);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,8 @@ class CreateType extends BaseFunction implements
|
||||
$this->throwBadArgumentType($i + 1, 'string');
|
||||
}
|
||||
|
||||
/** @var string $attribute */
|
||||
|
||||
$value = $args[$i + 1];
|
||||
|
||||
$data[$attribute] = $value;
|
||||
|
||||
@@ -55,6 +55,7 @@ class UpdateType extends BaseFunction implements
|
||||
if (!is_string($entityType)) {
|
||||
$this->throwBadArgumentType(1, 'string');
|
||||
}
|
||||
|
||||
if (!is_string($id)) {
|
||||
$this->throwBadArgumentType(2, 'string');
|
||||
}
|
||||
@@ -62,13 +63,20 @@ class UpdateType extends BaseFunction implements
|
||||
$data = [];
|
||||
|
||||
$i = 2;
|
||||
|
||||
while ($i < count($args) - 1) {
|
||||
$attribute = $args[$i];
|
||||
|
||||
if (!is_string($entityType)) {
|
||||
$this->throwBadArgumentType($i + 1, 'string');
|
||||
}
|
||||
|
||||
/** @var string $attribute */
|
||||
|
||||
$value = $args[$i + 1];
|
||||
|
||||
$data[$attribute] = $value;
|
||||
|
||||
$i = $i + 2;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user