This commit is contained in:
Yuri Kuznetsov
2021-12-29 13:23:00 +02:00
parent cb5fdfba85
commit 2a4bd851ab
17 changed files with 102 additions and 42 deletions

View File

@@ -30,6 +30,7 @@
namespace Espo\Controllers;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
use Espo\Core\MassAction\Service;
use Espo\Core\MassAction\ServiceResult;
@@ -139,6 +140,10 @@ class MassAction
$result = $serviceResult->getResult();
if (!$result) {
throw new Error();
}
$data = (object) [];
if ($result->hasCount()) {

View File

@@ -78,7 +78,9 @@ class DefaultOwnershipChecker implements OwnershipOwnChecker, OwnershipTeamCheck
public function checkTeam(User $user, Entity $entity): bool
{
assert($entity instanceof CoreEntity);
if (!$entity instanceof CoreEntity) {
return false;
}
$userTeamIdList = $user->getLinkMultipleIdList(self::FIELD_TEAMS);

View File

@@ -103,7 +103,9 @@ class EspoManager implements Manager
public function inactivate(AuthToken $authToken): void
{
assert($authToken instanceof AuthTokenEntity);
if (!$authToken instanceof AuthTokenEntity) {
throw new RuntimeException();
}
$this->validateNotChanged($authToken);
@@ -114,7 +116,9 @@ class EspoManager implements Manager
public function renew(AuthToken $authToken): void
{
assert($authToken instanceof AuthTokenEntity);
if (!$authToken instanceof AuthTokenEntity) {
throw new RuntimeException();
}
$this->validateNotChanged($authToken);

View File

@@ -115,7 +115,11 @@ class FindRelatedManyType extends BaseFunction implements
$order = $order ?? 'asc';
}
assert($entity instanceof CoreEntity);
if (!$entity instanceof CoreEntity) {
$this->throwError("Only core entities are supported.");
return;
}
$relationType = $entity->getRelationParam($link, 'type');

View File

@@ -90,7 +90,11 @@ class FindRelatedOneType extends BaseFunction implements
$metadata = $this->metadata;
assert($entity instanceof CoreEntity);
if (!$entity instanceof CoreEntity) {
$this->throwError("Only core entities are supported.");
return;
}
$relationType = $entity->getRelationParam($link, 'type');

View File

@@ -444,7 +444,9 @@ class Importer
return;
}
assert($parent instanceof CoreEntity);
if (!$parent instanceof CoreEntity) {
return;
}
$parentTeamIdList = $parent->getLinkMultipleIdList('teams');

View File

@@ -66,8 +66,6 @@ class Process implements Job
{
$id = $data->getTargetId();
assert($id !== null);
if ($id === null) {
throw new Error("ID not passed to the mass action job.");
}

View File

@@ -48,17 +48,13 @@ class ServiceResult
return $this->result !== null;
}
public function getId(): string
public function getId(): ?string
{
assert($this->id !== null);
return $this->id;
}
public function getResult(): Result
public function getResult(): ?Result
{
assert($this->result !== null);
return $this->result;
}

View File

@@ -65,7 +65,9 @@ class DefaultAssignmentNotificator implements AssignmentNotificator
public function process(Entity $entity, Params $params): void
{
assert($entity instanceof CoreEntity);
if (!$entity instanceof CoreEntity) {
return;
}
if ($entity->hasLinkMultipleField('assignedUsers')) {
$userIdList = $entity->getLinkMultipleIdList('assignedUsers');

View File

@@ -31,6 +31,8 @@ namespace Espo\Core\Portal\Loaders;
use Espo\Core\Portal\AclManager as PortalAclManager;
use InvalidArgumentException;
use Espo\Core\{
Container\Loader,
AclManager,
@@ -48,7 +50,9 @@ class Acl implements Loader
public function __construct(AclManager $aclManager, User $user)
{
assert($aclManager instanceof PortalAclManager);
if (!$aclManager instanceof PortalAclManager) {
throw new InvalidArgumentException();
}
$this->aclManager = $aclManager;
$this->user = $user;

View File

@@ -1026,7 +1026,9 @@ class Service implements Crud,
throw new NotFound();
}
assert($entity instanceof CoreEntity);
if (!$entity instanceof CoreEntity) {
throw new Error("Only core entities are supported");
}
if ($this->noEditAccessRequiredForLink) {
if (!$this->acl->check($entity, AclTable::ACTION_READ)) {
@@ -1098,7 +1100,9 @@ class Service implements Crud,
throw new NotFound();
}
assert($entity instanceof CoreEntity);
if (!$entity instanceof CoreEntity) {
throw new Error("Only core entities are supported");
}
if ($this->noEditAccessRequiredForLink) {
if (!$this->acl->check($entity, AclTable::ACTION_READ)) {
@@ -1160,14 +1164,13 @@ class Service implements Crud,
throw new NotFound();
}
/** @var User|null $user */
$user = $this->entityManager->getEntity('User', $foreignId);
if (!$user) {
throw new NotFound();
}
assert($user instanceof User);
if (!$this->acl->check($entity, AclTable::ACTION_EDIT)) {
throw new ForbiddenSilent("No 'edit' access.");
}
@@ -1215,14 +1218,13 @@ class Service implements Crud,
throw new NotFound();
}
/** @var User|null $user */
$user = $this->entityManager->getEntity('User', $foreignId);
if (!$user) {
throw new NotFound();
}
assert($user instanceof User);
if (!$this->acl->check($entity, AclTable::ACTION_EDIT)) {
throw new ForbiddenSilent("No 'edit' access.");
}
@@ -1278,7 +1280,9 @@ class Service implements Crud,
return $this->$methodName($id, $searchParams);
}
assert($entity instanceof CoreEntity);
if (!$entity instanceof CoreEntity) {
throw new Error("Only core entities are supported");
}
$foreignEntityType = $entity->getRelationParam($link, 'entity');
@@ -1623,7 +1627,9 @@ class Service implements Crud,
}
}
else if ($type === 'linkMultiple') {
assert($entity instanceof CoreEntity);
if (!$entity instanceof CoreEntity) {
throw new Error("Only core entities are supported");
}
$foreignLink = $entity->getRelationParam($field, 'foreign');
$foreignEntityType = $entity->getRelationParam($field, 'entity');

View File

@@ -36,6 +36,8 @@ use Espo\Core\Field\Link;
use Espo\Core\MassAction\Data;
use Espo\Core\MassAction\Params;
use Espo\Core\Exceptions\Error;
use stdClass;
class MassAction extends Entity
@@ -54,12 +56,13 @@ class MassAction extends Entity
{
$raw = $this->get('params');
assert(is_string($raw));
if (!is_string($raw)) {
throw new Error("No 'params'.");
}
/** @var Params $params */
$params = unserialize($raw);
assert($params instanceof Params);
return $params;
}
@@ -67,7 +70,9 @@ class MassAction extends Entity
{
$raw = $this->get('data');
assert($raw instanceof stdClass);
if (!$raw instanceof stdClass) {
throw new Error("No 'data'.");
}
return Data::fromRaw($raw);
}
@@ -76,7 +81,9 @@ class MassAction extends Entity
{
$value = $this->get('entityType');
assert(is_string($value));
if (!is_string($value)) {
throw new Error("No 'entityType'.");
}
return $value;
}
@@ -85,7 +92,9 @@ class MassAction extends Entity
{
$value = $this->get('action');
assert(is_string($value));
if (!is_string($value)) {
throw new Error("No 'action'.");
}
return $value;
}
@@ -94,7 +103,9 @@ class MassAction extends Entity
{
$value = $this->get('status');
assert(is_string($value));
if (!is_string($value)) {
throw new Error("No 'status'.");
}
return $value;
}
@@ -108,7 +119,9 @@ class MassAction extends Entity
{
$value = $this->getValueObject('createdAt');
assert($value instanceof DateTime);
if (!$value instanceof DateTime) {
throw new Error("No 'createdAt'.");
}
return $value;
}
@@ -117,7 +130,9 @@ class MassAction extends Entity
{
$value = $this->getValueObject('createdBy');
assert($value instanceof Link);
if (!$value instanceof Link) {
throw new Error("No 'createdBy'.");
}
return $value;
}

View File

@@ -209,7 +209,9 @@ class RDBRepository implements Repository
{
$mapper = $this->getMapper();
assert($mapper instanceof BaseMapper);
if (!$mapper instanceof BaseMapper) {
throw new RuntimeException("Not supported 'restoreDeleted'.");
}
$mapper->restoreDeleted($this->entityType, $id);
}
@@ -245,7 +247,9 @@ class RDBRepository implements Repository
{
$mapper = $this->getMapper();
assert($mapper instanceof BaseMapper);
if (!$mapper instanceof BaseMapper) {
throw new RuntimeException("Not supported 'deleteFromDb'.");
}
$mapper->deleteFromDb($this->entityType, $id, $onlyDeleted);
}
@@ -287,7 +291,9 @@ class RDBRepository implements Repository
{
$mapper = $this->getMapper();
assert($mapper instanceof BaseMapper);
if (!$mapper instanceof BaseMapper) {
throw new RuntimeException("Not supported 'findBySql'.");
}
return $mapper->selectBySql($this->entityType, $sql);
}

View File

@@ -153,7 +153,9 @@ class RDBSelectBuilder
$mapper = $this->getMapper();
assert($mapper instanceof BaseMapper);
if (!$mapper instanceof BaseMapper) {
throw new RuntimeException("Not supported 'max'.");
}
return $mapper->max($query, $attribute);
}
@@ -169,7 +171,9 @@ class RDBSelectBuilder
$mapper = $this->getMapper();
assert($mapper instanceof BaseMapper);
if (!$mapper instanceof BaseMapper) {
throw new RuntimeException("Not supported 'min'.");
}
return $mapper->min($query, $attribute);
}
@@ -185,7 +189,9 @@ class RDBSelectBuilder
$mapper = $this->getMapper();
assert($mapper instanceof BaseMapper);
if (!$mapper instanceof BaseMapper) {
throw new RuntimeException("Not supported 'sum'.");
}
return $mapper->sum($query, $attribute);
}

View File

@@ -145,7 +145,9 @@ class AssignmentProcessor
return;
}
assert($entity instanceof Entity);
if (!$entity instanceof Entity) {
return;
}
$this->loadParentNameFields($entity);

View File

@@ -448,7 +448,9 @@ class Import
$entity = $this->entityManager->getEntity($this->entityType);
}
assert($entity instanceof Entity);
if (!$entity instanceof Entity) {
throw new Error("Import supports only `Espo\Core\ORM\Entity`.");
}
$isNew = $entity->isNew();

View File

@@ -89,7 +89,9 @@ class HookProcessor
{
$entityType = $entity->getEntityType();
assert($entity instanceof CoreEntity);
if (!$entity instanceof CoreEntity) {
return;
}
/**
* No need to process assignment notifications for entity types that have Stream enabled.