mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
formula sandbox log errors
This commit is contained in:
@@ -30,31 +30,33 @@
|
||||
namespace Espo\Controllers;
|
||||
|
||||
use Espo\Core\Api\Request;
|
||||
|
||||
use Espo\Core\Exceptions\NotFoundSilent;
|
||||
use Espo\Tools\Formula\Service;
|
||||
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\ForbiddenSilent;
|
||||
|
||||
use Espo\Entities\User;
|
||||
|
||||
use Espo\Core\Field\LinkParent;
|
||||
|
||||
use stdClass;
|
||||
|
||||
class Formula
|
||||
{
|
||||
private Service $service;
|
||||
|
||||
public function __construct(Service $service, User $user)
|
||||
{
|
||||
$this->service = $service;
|
||||
|
||||
/**
|
||||
* @throws ForbiddenSilent
|
||||
*/
|
||||
public function __construct(
|
||||
private Service $service,
|
||||
User $user,
|
||||
) {
|
||||
if (!$user->isAdmin()) {
|
||||
throw new ForbiddenSilent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
*/
|
||||
public function postActionCheckSyntax(Request $request): stdClass
|
||||
{
|
||||
$expression = $request->getParsedBody()->expression ?? null;
|
||||
@@ -66,6 +68,10 @@ class Formula
|
||||
return $this->service->checkSyntax($expression)->toStdClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
* @throws NotFoundSilent
|
||||
*/
|
||||
public function postActionRun(Request $request): stdClass
|
||||
{
|
||||
$expression = $request->getParsedBody()->expression ?? null;
|
||||
|
||||
@@ -34,26 +34,19 @@ use Espo\Core\Formula\Exceptions\SyntaxError;
|
||||
use Espo\Core\Formula\Exceptions\Error;
|
||||
use Espo\Core\Formula\Manager;
|
||||
use Espo\Core\Field\LinkParent;
|
||||
|
||||
use Espo\Core\Exceptions\NotFoundSilent;
|
||||
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class Service
|
||||
{
|
||||
private Parser $parser;
|
||||
|
||||
private Manager $manager;
|
||||
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(Parser $parser, Manager $manager, EntityManager $entityManager)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->manager = $manager;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
public function __construct(
|
||||
private Parser $parser,
|
||||
private Manager $manager,
|
||||
private EntityManager $entityManager,
|
||||
private Log $log,
|
||||
) {}
|
||||
|
||||
public function checkSyntax(string $expression): SyntaxCheckResult
|
||||
{
|
||||
@@ -68,6 +61,9 @@ class Service
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotFoundSilent
|
||||
*/
|
||||
public function run(string $expression, ?LinkParent $targetLink = null): RunResult
|
||||
{
|
||||
$syntaxCheckResult = $this->checkSyntax($expression);
|
||||
@@ -96,6 +92,8 @@ class Service
|
||||
} catch (Error $e) {
|
||||
$output = $variables->__output ?? null;
|
||||
|
||||
$this->log->error("Formula sandbox run error.", ['exception' => $e->getPrevious()]);
|
||||
|
||||
return RunResult::createError($e, $output);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user