diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/CountType.php b/application/Espo/Core/Formula/Functions/RecordGroup/CountType.php index 33d857a0ab..c1f44debef 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/CountType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/CountType.php @@ -37,6 +37,7 @@ class CountType extends \Espo\Core\Formula\Functions\Base protected function init() { $this->addDependency('entityManager'); + $this->addDependency('selectManagerFactory'); } public function process(\StdClass $item) @@ -49,12 +50,27 @@ class CountType extends \Espo\Core\Formula\Functions\Base throw new Error(); } - if (count($item->value) < 3) { + if (count($item->value) < 1) { throw new Error(); } $entityType = $this->evaluate($item->value[0]); + if (count($item->value) < 3) { + $filter = null; + if (count($item->value) == 2) { + $filter = $this->evaluate($item->value[1]); + } + + $selectManager = $this->getInjection('selectManagerFactory')->create($entityType); + $selectParams = $selectManager->getEmptySelectParams(); + if ($filter) { + $selectManager->applyFilter($filter, $selectParams); + } + + return $this->getInjection('entityManager')->getRepository($entityType)->count($selectParams); + } + $whereClause = []; $i = 1; diff --git a/application/Espo/Jobs/CheckNewVersion.php b/application/Espo/Jobs/CheckNewVersion.php index c67779e6f9..5c2ac89b75 100644 --- a/application/Espo/Jobs/CheckNewVersion.php +++ b/application/Espo/Jobs/CheckNewVersion.php @@ -55,7 +55,7 @@ class CheckNewVersion extends \Espo\Core\Jobs\Base protected function getRunTime() { $hour = rand(0, 4); - $minute = rand(0, 60); + $minute = rand(0, 59); $nextDay = new \DateTime('+ 1 day'); $time = $nextDay->format('Y-m-d') . ' ' . $hour . ':' . $minute . ':00'; diff --git a/application/Espo/Resources/metadata/app/formula.json b/application/Espo/Resources/metadata/app/formula.json index f260ceb72c..185883109c 100644 --- a/application/Espo/Resources/metadata/app/formula.json +++ b/application/Espo/Resources/metadata/app/formula.json @@ -168,6 +168,14 @@ "name": "entity\\countRelated", "insertText": "entity\\countRelated(LINK, FILTER)" }, + { + "name": "record\\exists", + "insertText": "record\\exists(ENTITY_TYPE, KEY, VALUE)" + }, + { + "name": "record\\count", + "insertText": "record\\count(ENTITY_TYPE, KEY, VALUE)" + }, { "name": "env\\userAttribute", "insertText": "env\\userAttribute(ATTRIBUTE)" diff --git a/install/core/tpl/errors.tpl b/install/core/tpl/errors.tpl index 981e94782c..a5b12688ef 100644 --- a/install/core/tpl/errors.tpl +++ b/install/core/tpl/errors.tpl @@ -11,7 +11,7 @@
- +