diff --git a/application/Espo/Controllers/MassAction.php b/application/Espo/Controllers/MassAction.php index a8c0caf844..65a7234680 100644 --- a/application/Espo/Controllers/MassAction.php +++ b/application/Espo/Controllers/MassAction.php @@ -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()) { diff --git a/application/Espo/Core/Acl/DefaultOwnershipChecker.php b/application/Espo/Core/Acl/DefaultOwnershipChecker.php index 51006315c4..21dda5ac89 100644 --- a/application/Espo/Core/Acl/DefaultOwnershipChecker.php +++ b/application/Espo/Core/Acl/DefaultOwnershipChecker.php @@ -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); diff --git a/application/Espo/Core/Authentication/AuthToken/EspoManager.php b/application/Espo/Core/Authentication/AuthToken/EspoManager.php index 0199daf674..0499bd2f9f 100644 --- a/application/Espo/Core/Authentication/AuthToken/EspoManager.php +++ b/application/Espo/Core/Authentication/AuthToken/EspoManager.php @@ -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); diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php index 5b8b8a59fd..017bc15b44 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php @@ -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'); diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php index b484140753..71029b6d51 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php @@ -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'); diff --git a/application/Espo/Core/Mail/Importer.php b/application/Espo/Core/Mail/Importer.php index c9b295d9d7..f443eef6f3 100644 --- a/application/Espo/Core/Mail/Importer.php +++ b/application/Espo/Core/Mail/Importer.php @@ -444,7 +444,9 @@ class Importer return; } - assert($parent instanceof CoreEntity); + if (!$parent instanceof CoreEntity) { + return; + } $parentTeamIdList = $parent->getLinkMultipleIdList('teams'); diff --git a/application/Espo/Core/MassAction/Jobs/Process.php b/application/Espo/Core/MassAction/Jobs/Process.php index da469aeac8..5190e3fd7b 100644 --- a/application/Espo/Core/MassAction/Jobs/Process.php +++ b/application/Espo/Core/MassAction/Jobs/Process.php @@ -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."); } diff --git a/application/Espo/Core/MassAction/ServiceResult.php b/application/Espo/Core/MassAction/ServiceResult.php index 874e58912c..6c9ea99173 100644 --- a/application/Espo/Core/MassAction/ServiceResult.php +++ b/application/Espo/Core/MassAction/ServiceResult.php @@ -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; } diff --git a/application/Espo/Core/Notification/DefaultAssignmentNotificator.php b/application/Espo/Core/Notification/DefaultAssignmentNotificator.php index 6e8cb324e5..c03adbcc67 100644 --- a/application/Espo/Core/Notification/DefaultAssignmentNotificator.php +++ b/application/Espo/Core/Notification/DefaultAssignmentNotificator.php @@ -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'); diff --git a/application/Espo/Core/Portal/Loaders/Acl.php b/application/Espo/Core/Portal/Loaders/Acl.php index 4c7456495d..a76f152a7f 100644 --- a/application/Espo/Core/Portal/Loaders/Acl.php +++ b/application/Espo/Core/Portal/Loaders/Acl.php @@ -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; diff --git a/application/Espo/Core/Record/Service.php b/application/Espo/Core/Record/Service.php index 71850ea75c..0c0d22e6c5 100644 --- a/application/Espo/Core/Record/Service.php +++ b/application/Espo/Core/Record/Service.php @@ -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'); diff --git a/application/Espo/Entities/MassAction.php b/application/Espo/Entities/MassAction.php index 1dbe724c2d..7d59a495c8 100644 --- a/application/Espo/Entities/MassAction.php +++ b/application/Espo/Entities/MassAction.php @@ -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; } diff --git a/application/Espo/ORM/Repository/RDBRepository.php b/application/Espo/ORM/Repository/RDBRepository.php index fa3ab590ff..117fc5c618 100644 --- a/application/Espo/ORM/Repository/RDBRepository.php +++ b/application/Espo/ORM/Repository/RDBRepository.php @@ -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); } diff --git a/application/Espo/ORM/Repository/RDBSelectBuilder.php b/application/Espo/ORM/Repository/RDBSelectBuilder.php index 20e0ced968..94597c5257 100644 --- a/application/Espo/ORM/Repository/RDBSelectBuilder.php +++ b/application/Espo/ORM/Repository/RDBSelectBuilder.php @@ -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); } diff --git a/application/Espo/Tools/EmailNotification/AssignmentProcessor.php b/application/Espo/Tools/EmailNotification/AssignmentProcessor.php index d4c9d5ae4d..3f02209994 100644 --- a/application/Espo/Tools/EmailNotification/AssignmentProcessor.php +++ b/application/Espo/Tools/EmailNotification/AssignmentProcessor.php @@ -145,7 +145,9 @@ class AssignmentProcessor return; } - assert($entity instanceof Entity); + if (!$entity instanceof Entity) { + return; + } $this->loadParentNameFields($entity); diff --git a/application/Espo/Tools/Import/Import.php b/application/Espo/Tools/Import/Import.php index 0c816fb550..93dbe4a4e9 100644 --- a/application/Espo/Tools/Import/Import.php +++ b/application/Espo/Tools/Import/Import.php @@ -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(); diff --git a/application/Espo/Tools/Notification/HookProcessor.php b/application/Espo/Tools/Notification/HookProcessor.php index 779964e503..8f41b2820e 100644 --- a/application/Espo/Tools/Notification/HookProcessor.php +++ b/application/Espo/Tools/Notification/HookProcessor.php @@ -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.