diff --git a/application/Espo/Classes/Acl/Attachment/AccessChecker.php b/application/Espo/Classes/Acl/Attachment/AccessChecker.php index 0af8a7a861..168415566f 100644 --- a/application/Espo/Classes/Acl/Attachment/AccessChecker.php +++ b/application/Espo/Classes/Acl/Attachment/AccessChecker.php @@ -148,7 +148,7 @@ class AccessChecker implements AccessEntityCREDChecker return null; } - $parent = $this->entityManager->getEntity($note->getParentType(), $note->getParentId()); + $parent = $this->entityManager->getEntityById($note->getParentType(), $note->getParentId()); if ($parent && $this->aclManager->checkEntity($user, $parent)) { return true; diff --git a/application/Espo/Classes/Acl/Note/AccessChecker.php b/application/Espo/Classes/Acl/Note/AccessChecker.php index 15eb723d06..2c93dded67 100644 --- a/application/Espo/Classes/Acl/Note/AccessChecker.php +++ b/application/Espo/Classes/Acl/Note/AccessChecker.php @@ -84,7 +84,7 @@ class AccessChecker implements AccessEntityCREDChecker return true; } - $parent = $this->entityManager->getEntity($parentType, $parentId); + $parent = $this->entityManager->getEntityById($parentType, $parentId); if ($parent && $this->aclManager->checkEntityStream($user, $parent)) { return true; diff --git a/application/Espo/Classes/AclPortal/Attachment/AccessChecker.php b/application/Espo/Classes/AclPortal/Attachment/AccessChecker.php index 4e94b45dfa..a8747f36b0 100644 --- a/application/Espo/Classes/AclPortal/Attachment/AccessChecker.php +++ b/application/Espo/Classes/AclPortal/Attachment/AccessChecker.php @@ -154,7 +154,7 @@ class AccessChecker implements AccessEntityCREDChecker return null; } - $parent = $this->entityManager->getEntity($note->getParentType(), $note->getParentId()); + $parent = $this->entityManager->getEntityById($note->getParentType(), $note->getParentId()); if ($parent && $this->aclManager->checkEntity($user, $parent)) { return true; diff --git a/application/Espo/Classes/FieldDuplicators/Wysiwyg.php b/application/Espo/Classes/FieldDuplicators/Wysiwyg.php index 75baf39730..b322fd85d8 100644 --- a/application/Espo/Classes/FieldDuplicators/Wysiwyg.php +++ b/application/Espo/Classes/FieldDuplicators/Wysiwyg.php @@ -76,7 +76,7 @@ class Wysiwyg implements FieldDuplicator foreach ($attachmentIdList as $id) { /** @var Attachment|null $attachment */ - $attachment = $this->entityManager->getEntity(Attachment::ENTITY_TYPE, $id); + $attachment = $this->entityManager->getEntityById(Attachment::ENTITY_TYPE, $id); if (!$attachment) { continue; diff --git a/application/Espo/Classes/FieldProcessing/Email/IcsDataLoader.php b/application/Espo/Classes/FieldProcessing/Email/IcsDataLoader.php index 1655ac1747..3180273b7c 100644 --- a/application/Espo/Classes/FieldProcessing/Email/IcsDataLoader.php +++ b/application/Espo/Classes/FieldProcessing/Email/IcsDataLoader.php @@ -188,7 +188,7 @@ class IcsDataLoader implements Loader } $createdEvent = $this->entityManager - ->getEntity($emailSameEvent->get('createdEventType'), $emailSameEvent->get('createdEventId')); + ->getEntityById($emailSameEvent->get('createdEventType'), $emailSameEvent->get('createdEventId')); if (!$createdEvent) { return; diff --git a/application/Espo/Core/Action/Actions/Merge/Merger.php b/application/Espo/Core/Action/Actions/Merge/Merger.php index 6d93e9ca50..4bff4fdae2 100644 --- a/application/Espo/Core/Action/Actions/Merge/Merger.php +++ b/application/Espo/Core/Action/Actions/Merge/Merger.php @@ -67,7 +67,7 @@ class Merger $entityType = $params->getEntityType(); $id = $params->getId(); - $entity = $this->entityManager->getEntity($entityType, $id); + $entity = $this->entityManager->getEntityById($entityType, $id); if (!$entity) { throw new NotFound("Record not found."); @@ -167,7 +167,7 @@ class Merger $list = []; foreach ($sourceIdList as $sourceId) { - $sourceEntity = $this->entityManager->getEntity($entityType, $sourceId); + $sourceEntity = $this->entityManager->getEntityById($entityType, $sourceId); if (!$sourceEntity) { throw new NotFound("Source record not found."); diff --git a/application/Espo/Core/Formula/Functions/ExtGroup/PdfGroup/GenerateType.php b/application/Espo/Core/Formula/Functions/ExtGroup/PdfGroup/GenerateType.php index 8af1e9c551..c37fb5afa8 100644 --- a/application/Espo/Core/Formula/Functions/ExtGroup/PdfGroup/GenerateType.php +++ b/application/Espo/Core/Formula/Functions/ExtGroup/PdfGroup/GenerateType.php @@ -83,7 +83,7 @@ class GenerateType extends BaseFunction implements $em = $this->entityManager; try { - $entity = $em->getEntity($entityType, $id); + $entity = $em->getEntityById($entityType, $id); } catch (Exception $e) { $this->log("Message: " . $e->getMessage() . "."); @@ -106,7 +106,7 @@ class GenerateType extends BaseFunction implements } if ($fileName) { - if (substr($fileName, -4) !== '.pdf') { + if (!str_ends_with($fileName, '.pdf')) { $fileName .= '.pdf'; } } else { diff --git a/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php b/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php index 50c6cbb9c6..1eed65a2de 100644 --- a/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php +++ b/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php @@ -61,7 +61,7 @@ class SendType extends BaseFunction implements } /** @var Sms|null $sms */ - $sms = $this->entityManager->getEntity(Sms::ENTITY_TYPE, $id); + $sms = $this->entityManager->getEntityById(Sms::ENTITY_TYPE, $id); if (!$sms) { $this->log("Sms '{$id}' does not exist."); diff --git a/application/Espo/Core/Formula/Functions/ExtGroup/UserGroup/SendAccessInfoType.php b/application/Espo/Core/Formula/Functions/ExtGroup/UserGroup/SendAccessInfoType.php index 731089ca68..32e0387428 100644 --- a/application/Espo/Core/Formula/Functions/ExtGroup/UserGroup/SendAccessInfoType.php +++ b/application/Espo/Core/Formula/Functions/ExtGroup/UserGroup/SendAccessInfoType.php @@ -62,10 +62,10 @@ class SendAccessInfoType extends BaseFunction implements $this->throwBadArgumentType(1, 'string'); } - $user = $this->entityManager->getEntity(User::ENTITY_TYPE, $userId); + $user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $userId); if (!$user) { - $this->log("User '{$userId}' does not exist."); + $this->log("User '$userId' does not exist."); return; } diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/AttributeType.php b/application/Espo/Core/Formula/Functions/RecordGroup/AttributeType.php index 08f8d75c8c..705362b13c 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/AttributeType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/AttributeType.php @@ -38,6 +38,9 @@ class AttributeType extends \Espo\Core\Formula\Functions\AttributeType implement { use Di\EntityManagerSetter; + /** + * @throws Error + */ public function process(\stdClass $item) { if (count($item->value) < 3) { @@ -60,7 +63,7 @@ class AttributeType extends \Espo\Core\Formula\Functions\AttributeType implement throw new Error("Formula record\\attribute: Empty attribute."); } - $entity = $this->entityManager->getEntity($entityType, $id); + $entity = $this->entityManager->getEntityById($entityType, $id); if (!$entity) { return null; diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php index 3150893bd0..53608fdede 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php @@ -29,6 +29,12 @@ namespace Espo\Core\Formula\Functions\RecordGroup; +use Espo\Core\Exceptions\BadRequest; +use Espo\Core\Exceptions\Forbidden; +use Espo\Core\Formula\Exceptions\BadArgumentType; +use Espo\Core\Formula\Exceptions\Error; +use Espo\Core\Formula\Exceptions\ExecutionException; +use Espo\Core\Formula\Exceptions\TooFewArguments; use Espo\Core\ORM\Entity as CoreEntity; use Espo\Core\Formula\ArgumentList; use Espo\Core\Formula\Functions\BaseFunction; @@ -46,6 +52,14 @@ class FindRelatedManyType extends BaseFunction implements use Di\MetadataSetter; use Di\InjectableFactorySetter; + /** + * @throws Error + * @throws BadRequest + * @throws TooFewArguments + * @throws BadArgumentType + * @throws Forbidden + * @throws ExecutionException + */ public function process(ArgumentList $args) { $args = $this->evaluate($args); @@ -94,7 +108,7 @@ class FindRelatedManyType extends BaseFunction implements $this->throwBadArgumentType(4, 'string'); } - $entity = $entityManager->getEntity($entityType, $id); + $entity = $entityManager->getEntityById($entityType, $id); if (!$entity) { $this->log("record\\findRelatedMany: Entity $entityType $id not found.", 'notice'); diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php index 6be8433735..b3f0065527 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php @@ -82,7 +82,7 @@ class FindRelatedOneType extends BaseFunction implements $this->throwBadArgumentType(3, 'string'); } - $entity = $entityManager->getEntity($entityType, $id); + $entity = $entityManager->getEntityById($entityType, $id); if (!$entity) { return null; diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/RelationColumnType.php b/application/Espo/Core/Formula/Functions/RecordGroup/RelationColumnType.php index 3533e411e9..bdacb07a48 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/RelationColumnType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/RelationColumnType.php @@ -78,10 +78,10 @@ class RelationColumnType extends BaseFunction implements $em = $this->entityManager; if (!$em->hasRepository($entityType)) { - $this->throwError("Repository '{$entityType}' does not exist."); + $this->throwError("Repository '$entityType' does not exist."); } - $entity = $em->getEntity($entityType, $id); + $entity = $em->getEntityById($entityType, $id); if (!$entity) { return null; diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/UpdateRelationColumnType.php b/application/Espo/Core/Formula/Functions/RecordGroup/UpdateRelationColumnType.php index 58e0f1dabe..4d84b28051 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/UpdateRelationColumnType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/UpdateRelationColumnType.php @@ -86,7 +86,7 @@ class UpdateRelationColumnType extends BaseFunction implements $this->throwError("Repository does not exist."); } - $entity = $em->getEntity($entityType, $id); + $entity = $em->getEntityById($entityType, $id); if (!$entity) { return null; diff --git a/application/Espo/Core/Job/ScheduleUtil.php b/application/Espo/Core/Job/ScheduleUtil.php index 56c56f5c51..41611a072f 100644 --- a/application/Espo/Core/Job/ScheduleUtil.php +++ b/application/Espo/Core/Job/ScheduleUtil.php @@ -81,7 +81,7 @@ class ScheduleUtil } /** @var ScheduledJobEntity|null $scheduledJob */ - $scheduledJob = $this->entityManager->getEntity(ScheduledJobEntity::ENTITY_TYPE, $scheduledJobId); + $scheduledJob = $this->entityManager->getEntityById(ScheduledJobEntity::ENTITY_TYPE, $scheduledJobId); if (!$scheduledJob) { return; diff --git a/application/Espo/Core/Loaders/Preferences.php b/application/Espo/Core/Loaders/Preferences.php index 34df84815f..2ec3fb6ef6 100644 --- a/application/Espo/Core/Loaders/Preferences.php +++ b/application/Espo/Core/Loaders/Preferences.php @@ -51,6 +51,6 @@ class Preferences implements Loader $this->systemUser->getId(); /** @var PreferencesEntity */ - return $this->entityManager->getEntity(PreferencesEntity::ENTITY_TYPE, $id); + return $this->entityManager->getEntityById(PreferencesEntity::ENTITY_TYPE, $id); } } diff --git a/application/Espo/Core/Mail/Account/GroupAccount/Hooks/AfterFetch.php b/application/Espo/Core/Mail/Account/GroupAccount/Hooks/AfterFetch.php index e5e74d6895..d9ee2c3f38 100644 --- a/application/Espo/Core/Mail/Account/GroupAccount/Hooks/AfterFetch.php +++ b/application/Espo/Core/Mail/Account/GroupAccount/Hooks/AfterFetch.php @@ -102,7 +102,7 @@ class AfterFetch implements AfterFetchInterface $emailToProcess = $email; if ($email->isFetched()) { - $emailToProcess = $this->entityManager->getEntity(Email::ENTITY_TYPE, $email->getId()); + $emailToProcess = $this->entityManager->getEntityById(Email::ENTITY_TYPE, $email->getId()); } else { $emailToProcess->updateFetchedValues(); } @@ -122,7 +122,7 @@ class AfterFetch implements AfterFetchInterface $user = null; if ($account->getAssignedUser()) { - $user = $this->entityManager->getEntity(User::ENTITY_TYPE, $account->getAssignedUser()->getId()); + $user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $account->getAssignedUser()->getId()); } $this->autoReply($account, $email, null, $user); @@ -137,7 +137,7 @@ class AfterFetch implements AfterFetchInterface return; } - $parent = $this->entityManager->getEntity($parentLink->getEntityType(), $parentLink->getId()); + $parent = $this->entityManager->getEntityById($parentLink->getEntityType(), $parentLink->getId()); if (!$parent) { return; @@ -438,7 +438,7 @@ class AfterFetch implements AfterFetchInterface private function emailToCase(Email $email, array $params): CaseObj { /** @var CaseObj $case */ - $case = $this->entityManager->getEntity(CaseObj::ENTITY_TYPE); + $case = $this->entityManager->getNewEntity(CaseObj::ENTITY_TYPE); $case->populateDefaults(); diff --git a/application/Espo/Core/Mail/Account/PersonalAccount/Hooks/AfterFetch.php b/application/Espo/Core/Mail/Account/PersonalAccount/Hooks/AfterFetch.php index 9aa0297955..df8e303b3f 100644 --- a/application/Espo/Core/Mail/Account/PersonalAccount/Hooks/AfterFetch.php +++ b/application/Espo/Core/Mail/Account/PersonalAccount/Hooks/AfterFetch.php @@ -58,7 +58,7 @@ class AfterFetch implements AfterFetchInterface return; } - $parent = $this->entityManager->getEntity($parentLink->getEntityType(), $parentLink->getId()); + $parent = $this->entityManager->getEntityById($parentLink->getEntityType(), $parentLink->getId()); if (!$parent) { return; diff --git a/application/Espo/Core/MassAction/Jobs/Process.php b/application/Espo/Core/MassAction/Jobs/Process.php index a65ba5f453..c8cc76566d 100644 --- a/application/Espo/Core/MassAction/Jobs/Process.php +++ b/application/Espo/Core/MassAction/Jobs/Process.php @@ -50,6 +50,9 @@ class Process implements Job private Language $language ) {} + /** + * @throws Error + */ public function run(JobData $data): void { $id = $data->getTargetId(); @@ -59,17 +62,17 @@ class Process implements Job } /** @var MassActionEntity|null $entity */ - $entity = $this->entityManager->getEntity(MassActionEntity::ENTITY_TYPE, $id); + $entity = $this->entityManager->getEntityById(MassActionEntity::ENTITY_TYPE, $id); if ($entity === null) { - throw new Error("MassAction '{$id}' not found."); + throw new Error("MassAction '$id' not found."); } /** @var User|null $user */ - $user = $this->entityManager->getEntity(User::ENTITY_TYPE, $entity->getCreatedBy()->getId()); + $user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $entity->getCreatedBy()->getId()); if (!$user) { - throw new Error("MassAction '{$id}', user not found."); + throw new Error("MassAction '$id', user not found."); } $params = $entity->getParams(); diff --git a/application/Espo/Core/ORM/EntityManagerProxy.php b/application/Espo/Core/ORM/EntityManagerProxy.php index f95d61a8a8..8267b14539 100644 --- a/application/Espo/Core/ORM/EntityManagerProxy.php +++ b/application/Espo/Core/ORM/EntityManagerProxy.php @@ -68,6 +68,7 @@ class EntityManagerProxy */ public function getEntity(string $entityType, ?string $id = null): ?Entity { + /** @noinspection PhpDeprecationInspection */ return $this->getEntityManager()->getEntity($entityType, $id); } diff --git a/application/Espo/Core/Portal/Application.php b/application/Espo/Core/Portal/Application.php index 710f8d0b98..a3a58df808 100644 --- a/application/Espo/Core/Portal/Application.php +++ b/application/Espo/Core/Portal/Application.php @@ -44,6 +44,11 @@ use Espo\Core\Portal\Utils\Config; class Application extends BaseApplication { + /** + * @throws Forbidden + * @throws Error + * @throws NotFound + */ public function __construct(?string $portalId) { date_default_timezone_set('UTC'); @@ -56,12 +61,13 @@ class Application extends BaseApplication public function getContainer(): Container { - $container = parent::getContainer(); - /** @var Container */ - return $container; + return parent::getContainer(); } + /** + * @throws Error + */ protected function initContainer(): void { $container = (new ContainerBuilder()) @@ -77,6 +83,11 @@ class Application extends BaseApplication $this->container = $container; } + /** + * @throws Forbidden + * @throws Error + * @throws NotFound + */ protected function initPortal(?string $portalId): void { if (!$portalId) { @@ -85,7 +96,7 @@ class Application extends BaseApplication $entityManager = $this->container->getByClass(EntityManager::class); - $portal = $entityManager->getEntity(Portal::ENTITY_TYPE, $portalId); + $portal = $entityManager->getEntityById(Portal::ENTITY_TYPE, $portalId); if (!$portal) { $portal = $entityManager diff --git a/application/Espo/Core/Select/Helpers/UserTimeZoneProvider.php b/application/Espo/Core/Select/Helpers/UserTimeZoneProvider.php index d1cffb3f23..e504262811 100644 --- a/application/Espo/Core/Select/Helpers/UserTimeZoneProvider.php +++ b/application/Espo/Core/Select/Helpers/UserTimeZoneProvider.php @@ -44,7 +44,7 @@ class UserTimeZoneProvider public function get(): string { - $preferences = $this->entityManager->getEntity(Preferences::ENTITY_TYPE, $this->user->getId()); + $preferences = $this->entityManager->getEntityById(Preferences::ENTITY_TYPE, $this->user->getId()); if (!$preferences) { return 'UTC'; diff --git a/application/Espo/Core/Select/SelectManager.php b/application/Espo/Core/Select/SelectManager.php index 852e6caa25..34c0e01c5e 100644 --- a/application/Espo/Core/Select/SelectManager.php +++ b/application/Espo/Core/Select/SelectManager.php @@ -276,7 +276,7 @@ class SelectManager protected function getSeed(): Entity { if (empty($this->seed)) { - $this->seed = $this->entityManager->getEntity($this->entityType); + $this->seed = $this->entityManager->getNewEntity($this->entityType); } return $this->seed; } diff --git a/application/Espo/Core/Utils/DateTime/DateTimeFactory.php b/application/Espo/Core/Utils/DateTime/DateTimeFactory.php index 0c16f51e29..7f0f7786d0 100644 --- a/application/Espo/Core/Utils/DateTime/DateTimeFactory.php +++ b/application/Espo/Core/Utils/DateTime/DateTimeFactory.php @@ -46,7 +46,7 @@ class DateTimeFactory public function createWithUserTimeZone(User $user): DateTime { - $preferences = $this->entityManager->getEntity(Preferences::ENTITY_TYPE, $user->getId()); + $preferences = $this->entityManager->getEntityById(Preferences::ENTITY_TYPE, $user->getId()); $timeZone = $this->config->get('timeZone') ?? 'UTC'; diff --git a/application/Espo/Entities/Notification.php b/application/Espo/Entities/Notification.php index 3aa9ef41b6..371e677482 100644 --- a/application/Espo/Entities/Notification.php +++ b/application/Espo/Entities/Notification.php @@ -71,6 +71,11 @@ class Notification extends Entity return $this->get('data'); } + public function getUserId(): ?string + { + return $this->get('userId'); + } + /** * @param stdClass|array $data */ diff --git a/application/Espo/Modules/Crm/Business/Distribution/Lead/RoundRobin.php b/application/Espo/Modules/Crm/Business/Distribution/Lead/RoundRobin.php index 948125459a..8ccd468353 100644 --- a/application/Espo/Modules/Crm/Business/Distribution/Lead/RoundRobin.php +++ b/application/Espo/Modules/Crm/Business/Distribution/Lead/RoundRobin.php @@ -102,6 +102,6 @@ class RoundRobin } } - return $this->entityManager->getEntity(User::ENTITY_TYPE, $userIdList[$num]); + return $this->entityManager->getRDBRepositoryByClass(User::class)->getById($userIdList[$num]); } } diff --git a/application/Espo/Modules/Crm/Classes/Acl/CampaignLogRecord/OwnershipChecker.php b/application/Espo/Modules/Crm/Classes/Acl/CampaignLogRecord/OwnershipChecker.php index b389759715..02905e8cee 100644 --- a/application/Espo/Modules/Crm/Classes/Acl/CampaignLogRecord/OwnershipChecker.php +++ b/application/Espo/Modules/Crm/Classes/Acl/CampaignLogRecord/OwnershipChecker.php @@ -54,7 +54,7 @@ class OwnershipChecker implements OwnershipOwnChecker, OwnershipTeamChecker return false; } - $campaign = $this->entityManager->getEntity('Campaign', $campaignId); + $campaign = $this->entityManager->getEntityById('Campaign', $campaignId); if ($campaign && $this->aclManager->checkOwnershipOwn($user, $campaign)) { return true; @@ -71,7 +71,7 @@ class OwnershipChecker implements OwnershipOwnChecker, OwnershipTeamChecker return false; } - $campaign = $this->entityManager->getEntity('Campaign', $campaignId); + $campaign = $this->entityManager->getEntityById('Campaign', $campaignId); if ($campaign && $this->aclManager->checkOwnershipTeam($user, $campaign)) { return true; diff --git a/application/Espo/Modules/Crm/Classes/Acl/CampaignTrackingUrl/OwnershipChecker.php b/application/Espo/Modules/Crm/Classes/Acl/CampaignTrackingUrl/OwnershipChecker.php index 8abc320b06..49f7ae2dd3 100644 --- a/application/Espo/Modules/Crm/Classes/Acl/CampaignTrackingUrl/OwnershipChecker.php +++ b/application/Espo/Modules/Crm/Classes/Acl/CampaignTrackingUrl/OwnershipChecker.php @@ -54,7 +54,7 @@ class OwnershipChecker implements OwnershipOwnChecker, OwnershipTeamChecker return false; } - $campaign = $this->entityManager->getEntity('Campaign', $campaignId); + $campaign = $this->entityManager->getEntityById('Campaign', $campaignId); if ($campaign && $this->aclManager->checkOwnershipOwn($user, $campaign)) { return true; @@ -71,7 +71,7 @@ class OwnershipChecker implements OwnershipOwnChecker, OwnershipTeamChecker return false; } - $campaign = $this->entityManager->getEntity('Campaign', $campaignId); + $campaign = $this->entityManager->getEntityById('Campaign', $campaignId); if ($campaign && $this->aclManager->checkOwnershipTeam($user, $campaign)) { return true; diff --git a/application/Espo/Modules/Crm/Classes/RecordHooks/TargetList/AfterCreate.php b/application/Espo/Modules/Crm/Classes/RecordHooks/TargetList/AfterCreate.php index ffb11e7799..0c7a44907f 100644 --- a/application/Espo/Modules/Crm/Classes/RecordHooks/TargetList/AfterCreate.php +++ b/application/Espo/Modules/Crm/Classes/RecordHooks/TargetList/AfterCreate.php @@ -93,7 +93,7 @@ class AfterCreate implements SaveHook array $excludingActionList ): void { - $campaign = $this->entityManager->getEntity(Campaign::ENTITY_TYPE, $sourceCampaignId); + $campaign = $this->entityManager->getEntityById(Campaign::ENTITY_TYPE, $sourceCampaignId); if (!$campaign) { throw new NotFound("Campaign not found."); diff --git a/application/Espo/Modules/Crm/Tools/Activities/Service.php b/application/Espo/Modules/Crm/Tools/Activities/Service.php index 51e5ad62d4..1e57382fd9 100644 --- a/application/Espo/Modules/Crm/Tools/Activities/Service.php +++ b/application/Espo/Modules/Crm/Tools/Activities/Service.php @@ -248,7 +248,7 @@ class Service protected function getActivitiesUserEmailQuery(User $entity, array $statusList = []) { if ($entity->isPortal() && $entity->get('contactId')) { - $contact = $this->entityManager->getEntity(Contact::ENTITY_TYPE, $entity->get('contactId')); + $contact = $this->entityManager->getEntityById(Contact::ENTITY_TYPE, $entity->get('contactId')); if ($contact) { return $this->getActivitiesEmailQuery($contact, $statusList); @@ -767,7 +767,7 @@ class Service throw new Forbidden(); } - $entity = $this->entityManager->getEntity($scope, $id); + $entity = $this->entityManager->getEntityById($scope, $id); if (!$entity) { throw new NotFound(); diff --git a/application/Espo/Modules/Crm/Tools/Meeting/Service.php b/application/Espo/Modules/Crm/Tools/Meeting/Service.php index 8d404f2284..1f05d32a31 100644 --- a/application/Espo/Modules/Crm/Tools/Meeting/Service.php +++ b/application/Espo/Modules/Crm/Tools/Meeting/Service.php @@ -155,7 +155,7 @@ class Service } foreach ($ids as $id) { - $entity = $this->entityManager->getEntity($entityType, $id); + $entity = $this->entityManager->getEntityById($entityType, $id); if ($entity && $this->acl->checkEntityEdit($entity)) { $entity->set('status', Meeting::STATUS_HELD); diff --git a/application/Espo/ORM/Repository/RDBRelation.php b/application/Espo/ORM/Repository/RDBRelation.php index 634d9609a4..80682a1fe2 100644 --- a/application/Espo/ORM/Repository/RDBRelation.php +++ b/application/Espo/ORM/Repository/RDBRelation.php @@ -442,7 +442,7 @@ class RDBRelation $typeAttribute = $this->relationName . 'Type'; if (!$fromEntity->has($idAttribute) || !$fromEntity->has($typeAttribute)) { - $fromEntity = $this->entityManager->getEntity($fromEntity->getEntityType(), $fromEntity->getId()); + $fromEntity = $this->entityManager->getEntityById($fromEntity->getEntityType(), $fromEntity->getId()); } if (!$fromEntity) { @@ -461,7 +461,7 @@ class RDBRelation $idAttribute = $this->relationName . 'Id'; if (!$fromEntity->has($idAttribute)) { - $fromEntity = $this->entityManager->getEntity($fromEntity->getEntityType(), $fromEntity->getId()); + $fromEntity = $this->entityManager->getEntityById($fromEntity->getEntityType(), $fromEntity->getId()); } if (!$fromEntity) { diff --git a/application/Espo/Repositories/EmailAddress.php b/application/Espo/Repositories/EmailAddress.php index 14c811e3a6..17bce62016 100644 --- a/application/Espo/Repositories/EmailAddress.php +++ b/application/Espo/Repositories/EmailAddress.php @@ -227,7 +227,7 @@ class EmailAddress extends Database implements ->where(['id' => $itemEntityId]) ->findOne(); } else { - $entity = $this->entityManager->getEntity($itemEntityType, $itemEntityId); + $entity = $this->entityManager->getEntityById($itemEntityType, $itemEntityId); } if (!$entity) { @@ -295,7 +295,7 @@ class EmailAddress extends Database implements ->where(['id' => $itemEntityId]) ->findOne(); } else { - $entity = $this->entityManager->getEntity($itemEntityType, $itemEntityId); + $entity = $this->entityManager->getEntityById($itemEntityType, $itemEntityId); } if ($entity) { @@ -354,7 +354,7 @@ class EmailAddress extends Database implements continue; } - $entity = $this->entityManager->getEntity($itemEntityType, $itemEntityId); + $entity = $this->entityManager->getEntityById($itemEntityType, $itemEntityId); if ($entity) { if ($entity instanceof UserEntity) { diff --git a/application/Espo/Repositories/PhoneNumber.php b/application/Espo/Repositories/PhoneNumber.php index 3010be8dc5..90977d84a5 100644 --- a/application/Espo/Repositories/PhoneNumber.php +++ b/application/Espo/Repositories/PhoneNumber.php @@ -191,7 +191,7 @@ class PhoneNumber extends Database implements continue; } - $entity = $this->entityManager->getEntity($itemEntityType, $itemEntityId); + $entity = $this->entityManager->getEntityById($itemEntityType, $itemEntityId); if (!$entity) { continue; @@ -244,7 +244,7 @@ class PhoneNumber extends Database implements continue; } - $entity = $this->entityManager->getEntity($itemEntityType, $itemEntityId); + $entity = $this->entityManager->getEntityById($itemEntityType, $itemEntityId); if ($entity) { if ($entity instanceof UserEntity) { diff --git a/application/Espo/Repositories/Preferences.php b/application/Espo/Repositories/Preferences.php index 9bf0993998..ba00db719f 100644 --- a/application/Espo/Repositories/Preferences.php +++ b/application/Espo/Repositories/Preferences.php @@ -273,7 +273,7 @@ class Preferences implements Repository, $this->entityManager->getQueryExecutor()->execute($insert); /** @var User|null $user */ - $user = $this->entityManager->getEntity(User::ENTITY_TYPE, $entity->getId()); + $user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $entity->getId()); if ($user && !$user->isPortal()) { $this->storeAutoFollowEntityTypeList($entity); diff --git a/application/Espo/Services/RecordTree.php b/application/Espo/Services/RecordTree.php index 5220d4ba89..1d4bbc62de 100644 --- a/application/Espo/Services/RecordTree.php +++ b/application/Espo/Services/RecordTree.php @@ -213,7 +213,7 @@ class RecordTree extends Record return null; } - $category = $this->entityManager->getEntity($this->entityType, $id); + $category = $this->entityManager->getEntityById($this->entityType, $id); if (!$category) { throw new NotFound(); diff --git a/application/Espo/Tools/DataPrivacy/Erasor.php b/application/Espo/Tools/DataPrivacy/Erasor.php index 5bdf33824d..837ec0fde2 100644 --- a/application/Espo/Tools/DataPrivacy/Erasor.php +++ b/application/Espo/Tools/DataPrivacy/Erasor.php @@ -78,7 +78,7 @@ class Erasor implements $service = $this->recordServiceContainer->get($entityType); - $entity = $this->entityManager->getEntity($entityType, $id); + $entity = $this->entityManager->getEntityById($entityType, $id); if (!$entity) { throw new NotFound(); diff --git a/application/Espo/Tools/EmailNotification/Processor.php b/application/Espo/Tools/EmailNotification/Processor.php index 036a723948..8ddef7d1d1 100644 --- a/application/Espo/Tools/EmailNotification/Processor.php +++ b/application/Espo/Tools/EmailNotification/Processor.php @@ -41,7 +41,6 @@ use Espo\Entities\Notification; use Espo\Entities\Portal; use Espo\Entities\Preferences; use Espo\Entities\User; -use Espo\ORM\Entity; use Espo\ORM\EntityManager; use Espo\ORM\Query\SelectBuilder as SelectBuilder; use Espo\Core\Htmlizer\Htmlizer; @@ -163,12 +162,12 @@ class Processor ->getQueryComposer() ->compose($unionQuery); - /** @var Collection $notificationList */ - $notificationList = $this->entityManager + /** @var Collection $notifications */ + $notifications = $this->entityManager ->getRDBRepository(Notification::ENTITY_TYPE) ->findBySql($sql); - foreach ($notificationList as $notification) { + foreach ($notifications as $notification) { $notification->set('emailIsProcessed', true); $type = $notification->getType(); @@ -255,7 +254,7 @@ class Processor return $builder; } - protected function processNotificationMentionInPost(Entity $notification): void + protected function processNotificationMentionInPost(Notification $notification): void { if (!$notification->get('userId')) { return; @@ -264,7 +263,7 @@ class Processor $userId = $notification->get('userId'); /** @var ?User $user */ - $user = $this->entityManager->getEntity(User::ENTITY_TYPE, $userId); + $user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $userId); if (!$user) { return; @@ -276,7 +275,7 @@ class Processor return; } - $preferences = $this->entityManager->getEntity(Preferences::ENTITY_TYPE, $userId); + $preferences = $this->entityManager->getEntityById(Preferences::ENTITY_TYPE, $userId); if (!$preferences) { return; @@ -286,12 +285,12 @@ class Processor return; } - if ($notification->get('relatedType') !== Note::ENTITY_TYPE || !$notification->get('relatedId')) { + if (!$notification->getRelated() || $notification->getRelated()->getEntityType() !== Note::ENTITY_TYPE) { return; } /** @var ?Note $note */ - $note = $this->entityManager->getEntity(Note::ENTITY_TYPE, $notification->get('relatedId')); + $note = $this->entityManager->getEntityById(Note::ENTITY_TYPE, $notification->getRelated()->getId()); if (!$note) { return; @@ -299,19 +298,19 @@ class Processor $parent = null; - $parentId = $note->get('parentId'); - $parentType = $note->get('parentType'); + $parentId = $note->getParentId(); + $parentType = $note->getParentType(); $data = []; if ($parentId && $parentType) { - $parent = $this->entityManager->getEntity($parentType, $parentId); + $parent = $this->entityManager->getEntityById($parentType, $parentId); if (!$parent) { return; } - $data['url'] = $this->getSiteUrl($user) . '/#' . $parentType . '/view/' . $parentId; + $data['url'] = "{$this->getSiteUrl($user)}/#$parentType/view/$parentId"; $data['parentName'] = $parent->get('name'); $data['parentType'] = $parentType; $data['parentId'] = $parentId; @@ -345,15 +344,13 @@ class Processor ->addToAddress($emailAddress); $email->set('isSystem', true); - - if ($parentId && $parentType) { $email->setParent(LinkParent::create($parentType, $parentId)); } $senderParams = SenderParams::create(); - if ($parent) { + if ($parent && $parentType) { $handler = $this->getHandler('mention', $parentType); if ($handler) { @@ -372,18 +369,18 @@ class Processor } } - protected function processNotificationNote(Entity $notification): void + protected function processNotificationNote(Notification $notification): void { - if ($notification->get('relatedType') !== Note::ENTITY_TYPE) { + if (!$notification->getRelated()) { return; } - if (!$notification->get('relatedId')) { + if ($notification->getRelated()->getEntityType() !== Note::ENTITY_TYPE) { return; } /** @var ?Note $note */ - $note = $this->entityManager->getEntity(Note::ENTITY_TYPE, $notification->get('relatedId')); + $note = $this->entityManager->getEntityById(Note::ENTITY_TYPE, $notification->getRelated()->getId()); if (!$note) { return; @@ -391,30 +388,30 @@ class Processor $noteNotificationTypeList = $this->config->get('streamEmailNotificationsTypeList', []); - if (!in_array($note->get('type'), $noteNotificationTypeList)) { + if (!in_array($note->getType(), $noteNotificationTypeList)) { return; } - if (!$notification->get('userId')) { + if (!$notification->getUserId()) { return; } - $userId = $notification->get('userId'); + $userId = $notification->getUserId(); /** @var ?User $user */ - $user = $this->entityManager->getEntity(User::ENTITY_TYPE, $userId); + $user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $userId); if (!$user) { return; } - $emailAddress = $user->get('emailAddress'); + $emailAddress = $user->getEmailAddress(); if (!$emailAddress) { return; } - $preferences = $this->entityManager->getEntity(Preferences::ENTITY_TYPE, $userId); + $preferences = $this->entityManager->getEntityById(Preferences::ENTITY_TYPE, $userId); if (!$preferences) { return; @@ -643,7 +640,7 @@ class Processor return; } - $parent = $this->entityManager->getEntity($parentType, $parentId); + $parent = $this->entityManager->getEntityById($parentType, $parentId); if (!$parent) { return; diff --git a/application/Espo/Tools/EmailTemplate/Processor.php b/application/Espo/Tools/EmailTemplate/Processor.php index 64258036f8..10546a61ce 100644 --- a/application/Espo/Tools/EmailTemplate/Processor.php +++ b/application/Espo/Tools/EmailTemplate/Processor.php @@ -108,7 +108,7 @@ class Processor $data->getParentId() && $data->getParentType() ) { - $parent = $this->entityManager->getEntity($data->getParentType(), $data->getParentId()); + $parent = $this->entityManager->getEntityById($data->getParentType(), $data->getParentId()); if ($parent) { $service = $this->recordServiceContainer->get($data->getParentType()); @@ -141,7 +141,7 @@ class Processor } if ($data->getRelatedId() && $data->getRelatedType()) { - $related = $this->entityManager->getEntity($data->getRelatedType(), $data->getRelatedId()); + $related = $this->entityManager->getEntityById($data->getRelatedType(), $data->getRelatedId()); if ( $related && diff --git a/application/Espo/Tools/Export/Jobs/Process.php b/application/Espo/Tools/Export/Jobs/Process.php index d4baf81031..b7142e0acd 100644 --- a/application/Espo/Tools/Export/Jobs/Process.php +++ b/application/Espo/Tools/Export/Jobs/Process.php @@ -40,7 +40,6 @@ use Espo\Tools\Export\Result; use Espo\Core\Utils\Language; use Espo\ORM\EntityManager; - use Espo\Entities\Export as ExportEntity; use Espo\Entities\Notification; use Espo\Entities\User; @@ -49,22 +48,15 @@ use Throwable; class Process implements Job { - private EntityManager $entityManager; - - private Factory $factory; - - private Language $language; - public function __construct( - EntityManager $entityManager, - Factory $factory, - Language $language - ) { - $this->entityManager = $entityManager; - $this->factory = $factory; - $this->language = $language; - } + private EntityManager $entityManager, + private Factory $factory, + private Language $language + ) {} + /** + * @throws Error + */ public function run(JobData $data): void { $id = $data->getTargetId(); @@ -74,17 +66,17 @@ class Process implements Job } /** @var ExportEntity|null $entity */ - $entity = $this->entityManager->getEntity(ExportEntity::ENTITY_TYPE, $id); + $entity = $this->entityManager->getEntityById(ExportEntity::ENTITY_TYPE, $id); if ($entity === null) { - throw new Error("Export '{$id}' not found."); + throw new Error("Export '$id' not found."); } /** @var User|null $user */ - $user = $this->entityManager->getEntity(User::ENTITY_TYPE, $entity->getCreatedBy()->getId()); + $user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $entity->getCreatedBy()->getId()); if (!$user) { - throw new Error("Export entity '{$id}', user not found."); + throw new Error("Export entity '$id', user not found."); } try { diff --git a/application/Espo/Tools/Import/Service.php b/application/Espo/Tools/Import/Service.php index 0eb6a36b1e..d1ef810ab9 100644 --- a/application/Espo/Tools/Import/Service.php +++ b/application/Espo/Tools/Import/Service.php @@ -152,7 +152,7 @@ class Service public function importById(string $id, bool $startFromLastIndex = false, bool $forceResume = false): Result { /** @var ?ImportEntity $import */ - $import = $this->entityManager->getEntity(ImportEntity::ENTITY_TYPE, $id); + $import = $this->entityManager->getEntityById(ImportEntity::ENTITY_TYPE, $id); if (!$import) { throw new NotFound("Import '$id' not found."); diff --git a/application/Espo/Tools/LeadCapture/ConfirmationSender.php b/application/Espo/Tools/LeadCapture/ConfirmationSender.php index fbf5f898b6..9c017b4cfe 100644 --- a/application/Espo/Tools/LeadCapture/ConfirmationSender.php +++ b/application/Espo/Tools/LeadCapture/ConfirmationSender.php @@ -117,7 +117,7 @@ class ConfirmationSender } /** @var ?LeadCaptureEntity $leadCapture */ - $leadCapture = $this->entityManager->getEntity(LeadCaptureEntity::ENTITY_TYPE, $leadCaptureId); + $leadCapture = $this->entityManager->getEntityById(LeadCaptureEntity::ENTITY_TYPE, $leadCaptureId); if (!$leadCapture) { throw new Error("LeadCapture: LeadCapture not found."); diff --git a/application/Espo/Tools/Notification/NoteHookProcessor.php b/application/Espo/Tools/Notification/NoteHookProcessor.php index 95ea7e2c91..3bf46543c8 100644 --- a/application/Espo/Tools/Notification/NoteHookProcessor.php +++ b/application/Espo/Tools/Notification/NoteHookProcessor.php @@ -35,7 +35,6 @@ use Espo\Core\Acl\Table; use Espo\Tools\Stream\Service as StreamService; use Espo\ORM\EntityManager; -use Espo\ORM\Collection; use Espo\ORM\SthCollection; use Espo\ORM\EntityCollection; @@ -278,7 +277,7 @@ class NoteHookProcessor $notifyUserIdList = []; foreach ($targetTeamIdList as $teamId) { - $team = $this->entityManager->getEntity(Team::ENTITY_TYPE, $teamId); + $team = $this->entityManager->getEntityById(Team::ENTITY_TYPE, $teamId); if (!$team) { continue; @@ -316,7 +315,7 @@ class NoteHookProcessor $notifyUserIdList = []; foreach ($targetPortalIdList as $portalId) { - $portal = $this->entityManager->getEntity(Portal::ENTITY_TYPE, $portalId); + $portal = $this->entityManager->getEntityById(Portal::ENTITY_TYPE, $portalId); if (!$portal) { continue; diff --git a/application/Espo/Tools/Notification/NoteMentionHookProcessor.php b/application/Espo/Tools/Notification/NoteMentionHookProcessor.php index 9ca7707f6c..62cf77e3c1 100644 --- a/application/Espo/Tools/Notification/NoteMentionHookProcessor.php +++ b/application/Espo/Tools/Notification/NoteMentionHookProcessor.php @@ -106,10 +106,7 @@ class NoteMentionHookProcessor $mentionCount = 0; $parent = $note->getParentId() && $note->getParentType() ? - $this->entityManager->getEntity( - $note->getParentType(), - $note->getParentId() - ) : + $this->entityManager->getEntityById($note->getParentType(), $note->getParentId()) : null; foreach ($matchList as $item) { diff --git a/application/Espo/Tools/Stream/Jobs/ControlFollowers.php b/application/Espo/Tools/Stream/Jobs/ControlFollowers.php index 80396aab7f..c01ecc5eac 100644 --- a/application/Espo/Tools/Stream/Jobs/ControlFollowers.php +++ b/application/Espo/Tools/Stream/Jobs/ControlFollowers.php @@ -61,7 +61,7 @@ class ControlFollowers implements Job return; } - $entity = $this->entityManager->getEntity($entityType, $entityId); + $entity = $this->entityManager->getEntityById($entityType, $entityId); if (!$entity) { return; diff --git a/application/Espo/Tools/UserSecurity/Password/Jobs/RemoveRecoveryRequest.php b/application/Espo/Tools/UserSecurity/Password/Jobs/RemoveRecoveryRequest.php index b4406b3ede..76c76cb0d3 100644 --- a/application/Espo/Tools/UserSecurity/Password/Jobs/RemoveRecoveryRequest.php +++ b/application/Espo/Tools/UserSecurity/Password/Jobs/RemoveRecoveryRequest.php @@ -52,7 +52,7 @@ class RemoveRecoveryRequest implements Job throw new RuntimeException(); } - $entity = $this->entityManager->getEntity(PasswordChangeRequest::ENTITY_TYPE, $id); + $entity = $this->entityManager->getEntityById(PasswordChangeRequest::ENTITY_TYPE, $id); if (!$entity) { return; diff --git a/application/Espo/Tools/UserSecurity/TwoFactor/EmailService.php b/application/Espo/Tools/UserSecurity/TwoFactor/EmailService.php index fbb4881f05..b52e98bbb8 100644 --- a/application/Espo/Tools/UserSecurity/TwoFactor/EmailService.php +++ b/application/Espo/Tools/UserSecurity/TwoFactor/EmailService.php @@ -30,40 +30,27 @@ namespace Espo\Tools\UserSecurity\TwoFactor; use Espo\Core\Authentication\TwoFactor\Email\EmailLogin; -use Espo\Core\Exceptions\Error; use Espo\Core\Exceptions\Forbidden; use Espo\Core\Exceptions\NotFound; - +use Espo\Core\Mail\Exceptions\SendingError; use Espo\Core\Utils\Config; use Espo\Core\Authentication\TwoFactor\Email\Util; - use Espo\ORM\EntityManager; - use Espo\Entities\User; class EmailService { - private Util $util; - private User $user; - private EntityManager $entityManager; - private Config $config; - public function __construct( - Util $util, - User $user, - EntityManager $entityManager, - Config $config - ) { - $this->util = $util; - $this->user = $user; - $this->entityManager = $entityManager; - $this->config = $config; - } + private Util $util, + private User $user, + private EntityManager $entityManager, + private Config $config + ) {} /** * @throws Forbidden * @throws NotFound - * @throws Error + * @throws SendingError */ public function sendCode(string $userId, string $emailAddress): void { @@ -74,7 +61,7 @@ class EmailService $this->checkAllowed(); /** @var ?User $user */ - $user = $this->entityManager->getEntity(User::ENTITY_TYPE, $userId); + $user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $userId); if (!$user) { throw new NotFound(); diff --git a/application/Espo/Tools/UserSecurity/TwoFactor/SmsService.php b/application/Espo/Tools/UserSecurity/TwoFactor/SmsService.php index 9e41c6e7c4..a79bdc3346 100644 --- a/application/Espo/Tools/UserSecurity/TwoFactor/SmsService.php +++ b/application/Espo/Tools/UserSecurity/TwoFactor/SmsService.php @@ -61,7 +61,7 @@ class SmsService $this->checkAllowed(); /** @var ?User $user */ - $user = $this->entityManager->getEntity(User::ENTITY_TYPE, $userId); + $user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $userId); if (!$user) { throw new NotFound(); diff --git a/install/core/Installer.php b/install/core/Installer.php index 46e0d4d3e4..e866c095e4 100644 --- a/install/core/Installer.php +++ b/install/core/Installer.php @@ -483,7 +483,7 @@ class Installer $em = $this->getEntityManager(); if ($id) { - $entity = $em->getEntity($entityType, $id); + $entity = $em->getEntityById($entityType, $id); if (!$entity) { $selectQuery = $em->getQueryBuilder() diff --git a/tests/integration/Espo/Actions/ActionTest.php b/tests/integration/Espo/Actions/ActionTest.php index 36ccaf69d4..e58632fed9 100644 --- a/tests/integration/Espo/Actions/ActionTest.php +++ b/tests/integration/Espo/Actions/ActionTest.php @@ -118,7 +118,7 @@ class ActionTest extends \tests\integration\Core\BaseTestCase $account2 = $this->entityManager->createEntity('Account', []); /* @var $contact1 Contact */ - $contact1 = $this->entityManager->getEntity('Contact'); + $contact1 = $this->entityManager->getNewEntity('Contact'); $emailAddressGroup1 = $contact1->getEmailAddressGroup() ->withAdded(EmailAddress::create('c1a@test.com')) @@ -137,7 +137,7 @@ class ActionTest extends \tests\integration\Core\BaseTestCase $contact1->set('teamsIds', [$team1->getId()]); /* @var $contact2 Contact */ - $contact2 = $this->entityManager->getEntity('Contact'); + $contact2 = $this->entityManager->getNewEntity('Contact'); $emailAddressGroup2 = $contact1->getEmailAddressGroup() ->withAdded(EmailAddress::create('c2a@test.com')) @@ -205,8 +205,8 @@ class ActionTest extends \tests\integration\Core\BaseTestCase $this->action->process($request); /* @var $contact1Reloaded Contact */ - $contact1Reloaded = $this->entityManager->getEntity('Contact', $contact1->getId()); - $contact2Reloaded = $this->entityManager->getEntity('Contact', $contact2->getId()); + $contact1Reloaded = $this->entityManager->getEntityById('Contact', $contact1->getId()); + $contact2Reloaded = $this->entityManager->getEntityById('Contact', $contact2->getId()); $this->assertEquals('merged', $contact1Reloaded->get('description')); @@ -247,7 +247,7 @@ class ActionTest extends \tests\integration\Core\BaseTestCase $this->assertEquals( $contact1->getId(), $this->entityManager - ->getEntity('Note', $note2->getId()) + ->getEntityById('Note', $note2->getId()) ->get('parentId') ); diff --git a/tests/integration/Espo/Actions/MassActionTest.php b/tests/integration/Espo/Actions/MassActionTest.php index 0c5269cf15..1d465b9c06 100644 --- a/tests/integration/Espo/Actions/MassActionTest.php +++ b/tests/integration/Espo/Actions/MassActionTest.php @@ -130,7 +130,7 @@ class MassActionTest extends \tests\integration\Core\BaseTestCase $this->action->process($request); - $accountReloaded = $this->entityManager->getEntity('Account', $account->getId()); + $accountReloaded = $this->entityManager->getEntityById('Account', $account->getId()); $this->assertEquals($adminUser->getId(), $accountReloaded->get('assignedUserId')); } diff --git a/tests/integration/Espo/Core/FieldProcessing/EmailAddressTest.php b/tests/integration/Espo/Core/FieldProcessing/EmailAddressTest.php index 124f5cf4ab..8651a3b5c4 100644 --- a/tests/integration/Espo/Core/FieldProcessing/EmailAddressTest.php +++ b/tests/integration/Espo/Core/FieldProcessing/EmailAddressTest.php @@ -50,7 +50,7 @@ class EmailAddressTest extends BaseTestCase 'emailAddress' => 'test@test.com', ]); - $contact = $entityManager->getEntity('Contact', $contact->getId()); + $contact = $entityManager->getEntityById('Contact', $contact->getId()); /* @var $group1 EmailAddressGroup */ $group1 = $contact->getEmailAddressGroup(); @@ -71,7 +71,7 @@ class EmailAddressTest extends BaseTestCase $entityManager->saveEntity($contact); - $contact = $entityManager->getEntity('Contact', $contact->getId()); + $contact = $entityManager->getEntityById('Contact', $contact->getId()); /* @var $group3 EmailAddressGroup */ $group3 = $contact->getEmailAddressGroup(); @@ -90,7 +90,7 @@ class EmailAddressTest extends BaseTestCase $entityManager->saveEntity($contact); - $contact = $entityManager->getEntity('Contact', $contact->getId()); + $contact = $entityManager->getEntityById('Contact', $contact->getId()); /* @var $group5 EmailAddressGroup */ $group5 = $contact->getEmailAddressGroup(); @@ -111,7 +111,7 @@ class EmailAddressTest extends BaseTestCase 'emailAddress' => 'test@test.com', ]); - $contactFetched = $entityManager->getEntity('Contact', $contact->getId()); + $contactFetched = $entityManager->getEntityById('Contact', $contact->getId()); /* @var $group EmailAddressGroup */ $group = $contactFetched->getEmailAddressGroup(); diff --git a/tests/integration/Espo/Core/FieldProcessing/FileTest.php b/tests/integration/Espo/Core/FieldProcessing/FileTest.php index b56b759210..d345b89073 100644 --- a/tests/integration/Espo/Core/FieldProcessing/FileTest.php +++ b/tests/integration/Espo/Core/FieldProcessing/FileTest.php @@ -49,7 +49,7 @@ class FileTest extends \tests\integration\Core\BaseTestCase 'fileId' => $attachment1->getId(), ]); - $attachment1 = $entityManager->getEntity('Attachment', $attachment1->getId()); + $attachment1 = $entityManager->getEntityById('Attachment', $attachment1->getId()); $this->assertEquals($document->getId(), $attachment1->get('relatedId')); @@ -62,11 +62,11 @@ class FileTest extends \tests\integration\Core\BaseTestCase $entityManager->saveEntity($document); - $attachment2 = $entityManager->getEntity('Attachment', $attachment2->getId()); + $attachment2 = $entityManager->getEntityById('Attachment', $attachment2->getId()); $this->assertEquals($document->getId(), $attachment2->get('relatedId')); - $attachment1 = $entityManager->getEntity('Attachment', $attachment1->getId()); + $attachment1 = $entityManager->getEntityById('Attachment', $attachment1->getId()); $this->assertNull($attachment1); } diff --git a/tests/integration/Espo/Core/FieldProcessing/PhoneNumberTest.php b/tests/integration/Espo/Core/FieldProcessing/PhoneNumberTest.php index 39e63941d8..62afe744eb 100644 --- a/tests/integration/Espo/Core/FieldProcessing/PhoneNumberTest.php +++ b/tests/integration/Espo/Core/FieldProcessing/PhoneNumberTest.php @@ -45,13 +45,13 @@ class PhoneNumberTest extends BaseTestCase { $entityManager = $this->getContainer()->getByClass(EntityManager::class); - $contact = $entityManager->getEntity(Contact::ENTITY_TYPE); + $contact = $entityManager->getNewEntity(Contact::ENTITY_TYPE); $contact->set('phoneNumber', '+1'); $entityManager->saveEntity($contact); $this->assertEquals('+1', $contact->get('phoneNumber')); - $contact = $entityManager->getEntity('Contact', $contact->getId()); + $contact = $entityManager->getEntityById('Contact', $contact->getId()); /* @var $group1 PhoneNumberGroup */ $group1 = $contact->getPhoneNumberGroup(); @@ -73,7 +73,7 @@ class PhoneNumberTest extends BaseTestCase $entityManager->saveEntity($contact); - $contact = $entityManager->getEntity('Contact', $contact->getId()); + $contact = $entityManager->getEntityById('Contact', $contact->getId()); /* @var $group3 PhoneNumberGroup */ $group3 = $contact->getPhoneNumberGroup(); @@ -93,7 +93,7 @@ class PhoneNumberTest extends BaseTestCase $entityManager->saveEntity($contact); - $contact = $entityManager->getEntity('Contact', $contact->getId()); + $contact = $entityManager->getEntityById('Contact', $contact->getId()); /* @var $group5 PhoneNumberGroup */ $group5 = $contact->getPhoneNumberGroup(); diff --git a/tests/integration/Espo/Core/FieldProcessing/RelationTest.php b/tests/integration/Espo/Core/FieldProcessing/RelationTest.php index e492ca980d..c522c6bd60 100644 --- a/tests/integration/Espo/Core/FieldProcessing/RelationTest.php +++ b/tests/integration/Espo/Core/FieldProcessing/RelationTest.php @@ -57,7 +57,7 @@ class RelationTest extends BaseTestCase ], ]); - $opportunity = $entityManager->getEntity('Opportunity', $opportunity->getId()); + $opportunity = $entityManager->getEntityById('Opportunity', $opportunity->getId()); $this->assertEquals( self::sortArray([ @@ -91,7 +91,7 @@ class RelationTest extends BaseTestCase $entityManager->saveEntity($opportunity); - $opportunity = $entityManager->getEntity('Opportunity', $opportunity->getId()); + $opportunity = $entityManager->getEntityById('Opportunity', $opportunity->getId()); $this->assertEquals( self::sortArray([ @@ -108,7 +108,7 @@ class RelationTest extends BaseTestCase $this->assertEquals('Evaluator', $column3); - $opportunity = $entityManager->getEntity('Opportunity', $opportunity->getId()); + $opportunity = $entityManager->getEntityById('Opportunity', $opportunity->getId()); $opportunity->set([ 'contactsColumns' => (object) [ @@ -179,11 +179,11 @@ class RelationTest extends BaseTestCase $entityManager->saveEntity($lead2); - $lead1 = $entityManager->getEntity('Lead', $lead1->getId()); + $lead1 = $entityManager->getEntityById('Lead', $lead1->getId()); $this->assertNull($lead1->get('createdAccountId')); - $lead2 = $entityManager->getEntity('Lead', $lead2->getId()); + $lead2 = $entityManager->getEntityById('Lead', $lead2->getId()); $this->assertEquals($account->getId(), $lead2->get('createdAccountId')); } @@ -202,7 +202,7 @@ class RelationTest extends BaseTestCase $entityManager->saveEntity($account); - $account = $entityManager->getEntity('Account', $account->getId()); + $account = $entityManager->getEntityById('Account', $account->getId()); $account->set([ 'originalLeadId' => $lead2->getId(), @@ -210,11 +210,11 @@ class RelationTest extends BaseTestCase $entityManager->saveEntity($account); - $lead2 = $entityManager->getEntity('Lead', $lead2->getId()); + $lead2 = $entityManager->getEntityById('Lead', $lead2->getId()); $this->assertEquals($account->getId(), $lead2->get('createdAccountId')); - $lead1 = $entityManager->getEntity('Lead', $lead1->getId()); + $lead1 = $entityManager->getEntityById('Lead', $lead1->getId()); $this->assertEquals(null, $lead1->get('createdAccountId')); } diff --git a/tests/integration/Espo/Core/Select/SelectBuilderTest.php b/tests/integration/Espo/Core/Select/SelectBuilderTest.php index 37f850187f..7e2e2e8100 100644 --- a/tests/integration/Espo/Core/Select/SelectBuilderTest.php +++ b/tests/integration/Espo/Core/Select/SelectBuilderTest.php @@ -42,11 +42,7 @@ use Espo\Entities\Email; use Espo\Modules\Crm\Entities\Account; use Espo\Modules\Crm\Entities\Opportunity; use Espo\ORM\EntityManager; -use Espo\ORM\Query\Part\Condition; -use Espo\ORM\Query\Part\Expression; -use Espo\ORM\Query\Part\WhereClause; use Espo\ORM\Query\Select; -use Espo\ORM\Query\SelectBuilder; use tests\integration\Core\BaseTestCase; class SelectBuilderTest extends BaseTestCase @@ -950,7 +946,7 @@ class SelectBuilderTest extends BaseTestCase $em = $container->getByClass(EntityManager::class); - $user = $em->getEntity('User', $userId); + $user = $em->getEntityById('User', $userId); $emailAddress = $em->createEntity('EmailAddress', [ 'name' => 'test@test.com', diff --git a/tests/integration/Espo/Export/ExportTest.php b/tests/integration/Espo/Export/ExportTest.php index 4c3ae6d0b7..564cc7f186 100644 --- a/tests/integration/Espo/Export/ExportTest.php +++ b/tests/integration/Espo/Export/ExportTest.php @@ -121,16 +121,16 @@ class ExportTest extends \tests\integration\Core\BaseTestCase ->run() ->getAttachmentId(); - $attachment = $this->entityManager->getEntity('Attachment', $attachmentId); + $attachment = $this->entityManager->getEntityById('Attachment', $attachmentId); $contents = $this->fileStorageManager->getContents($attachment); - $exepectedContents = + $expectedContents = "name,assignedUserId,assignedUserName\n" . "test-2,user-id,User\n" . "test-1,user-id,User\n"; - $this->assertEquals($exepectedContents, $contents); + $this->assertEquals($expectedContents, $contents); } public function testCsvWithAttributeList(): void @@ -170,16 +170,16 @@ class ExportTest extends \tests\integration\Core\BaseTestCase ->run() ->getAttachmentId(); - $attachment = $this->entityManager->getEntity('Attachment', $attachmentId); + $attachment = $this->entityManager->getEntityById('Attachment', $attachmentId); $contents = $this->fileStorageManager->getContents($attachment); - $exepectedContents = + $expectedContents = "id,name,assignedUserId\n" . "2,test-2,user-id\n" . "1,test-1,user-id\n"; - $this->assertEquals($exepectedContents, $contents); + $this->assertEquals($expectedContents, $contents); } public function testCsvCollection(): void @@ -235,15 +235,15 @@ class ExportTest extends \tests\integration\Core\BaseTestCase ->run() ->getAttachmentId(); - $attachment = $this->entityManager->getEntity('Attachment', $attachmentId); + $attachment = $this->entityManager->getEntityById('Attachment', $attachmentId); $contents = $this->fileStorageManager->getContents($attachment); - $exepectedContents = + $expectedContents = "name,assignedUserId\n" . "test-1,user-id\n" . "test-2,user-id\n"; - $this->assertEquals($exepectedContents, $contents); + $this->assertEquals($expectedContents, $contents); } } diff --git a/tests/integration/Espo/Note/AclTest.php b/tests/integration/Espo/Note/AclTest.php index 26ef1304cf..66f1799ca2 100644 --- a/tests/integration/Espo/Note/AclTest.php +++ b/tests/integration/Espo/Note/AclTest.php @@ -95,7 +95,7 @@ class AclTest extends \tests\integration\Core\BaseTestCase $em->saveEntity($opportunity); - $note1 = $em->getEntity('Note', $note1->getId()); + $note1 = $em->getEntityById('Note', $note1->getId()); $this->assertEquals([$team2->getId()], $note1->getLinkMultipleIdList('teams')); $this->assertEquals([$user2->getId()], $note1->getLinkMultipleIdList('users')); @@ -130,7 +130,7 @@ class AclTest extends \tests\integration\Core\BaseTestCase $em->saveEntity($meeting); - $note2 = $em->getEntity('Note', $note2->getId()); + $note2 = $em->getEntityById('Note', $note2->getId()); $this->assertEquals([$team2->getId()], $note2->getLinkMultipleIdList('teams')); $this->assertEquals([$user2->getId()], $note2->getLinkMultipleIdList('users')); diff --git a/tests/integration/Espo/ORM/RelationsTest.php b/tests/integration/Espo/ORM/RelationsTest.php index c5637c1b6c..8574ebca3b 100644 --- a/tests/integration/Espo/ORM/RelationsTest.php +++ b/tests/integration/Espo/ORM/RelationsTest.php @@ -53,7 +53,7 @@ class RelationsTest extends BaseTestCase $em = $this->getEntityManager(); - $opp = $em->getEntity(Opportunity::ENTITY_TYPE); + $opp = $em->getNewEntity(Opportunity::ENTITY_TYPE); $this->assertInstanceOf(OpportunityExtended::class, $opp); $this->assertNull($opp->getRelatedAccount()); @@ -98,7 +98,7 @@ class RelationsTest extends BaseTestCase $em = $this->getEntityManager(); - $account = $em->getEntity(Account::ENTITY_TYPE); + $account = $em->getNewEntity(Account::ENTITY_TYPE); $this->assertInstanceOf(AccountExtended::class, $account); $this->assertInstanceOf(EntityCollection::class, $account->getRelatedOpportunities());