This commit is contained in:
Yuri Kuznetsov
2024-11-09 23:24:40 +02:00
parent f6abfdc322
commit 664c5b0137
59 changed files with 185 additions and 180 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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.");

View File

@@ -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 {

View File

@@ -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.");

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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');

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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();

View File

@@ -68,6 +68,7 @@ class EntityManagerProxy
*/
public function getEntity(string $entityType, ?string $id = null): ?Entity
{
/** @noinspection PhpDeprecationInspection */
return $this->getEntityManager()->getEntity($entityType, $id);
}

View File

@@ -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

View File

@@ -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';

View File

@@ -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;
}

View File

@@ -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';

View File

@@ -71,6 +71,11 @@ class Notification extends Entity
return $this->get('data');
}
public function getUserId(): ?string
{
return $this->get('userId');
}
/**
* @param stdClass|array<string, mixed> $data
*/

View File

@@ -102,6 +102,6 @@ class RoundRobin
}
}
return $this->entityManager->getEntity(User::ENTITY_TYPE, $userIdList[$num]);
return $this->entityManager->getRDBRepositoryByClass(User::class)->getById($userIdList[$num]);
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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.");

View File

@@ -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();

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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();

View File

@@ -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();

View File

@@ -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<Notification> $notificationList */
$notificationList = $this->entityManager
/** @var Collection<Notification> $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;

View File

@@ -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 &&

View File

@@ -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 {

View File

@@ -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.");

View File

@@ -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.");

View File

@@ -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;

View File

@@ -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) {

View File

@@ -61,7 +61,7 @@ class ControlFollowers implements Job
return;
}
$entity = $this->entityManager->getEntity($entityType, $entityId);
$entity = $this->entityManager->getEntityById($entityType, $entityId);
if (!$entity) {
return;

View File

@@ -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;

View File

@@ -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();

View File

@@ -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();

View File

@@ -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()

View File

@@ -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')
);

View File

@@ -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'));
}

View File

@@ -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();

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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'));
}

View File

@@ -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',

View File

@@ -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);
}
}

View File

@@ -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'));

View File

@@ -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());