diff --git a/application/Espo/Core/Authentication/AuthToken/EspoManager.php b/application/Espo/Core/Authentication/AuthToken/EspoManager.php index e6dfd40b18..78c7e8af92 100644 --- a/application/Espo/Core/Authentication/AuthToken/EspoManager.php +++ b/application/Espo/Core/Authentication/AuthToken/EspoManager.php @@ -38,6 +38,9 @@ use const MCRYPT_DEV_URANDOM; class EspoManager implements Manager { + /** + * @var EntityManager + */ private $entityManager; private $repository; diff --git a/application/Espo/Core/Authentication/Authentication.php b/application/Espo/Core/Authentication/Authentication.php index 2aef975b5e..bea6addbb3 100644 --- a/application/Espo/Core/Authentication/Authentication.php +++ b/application/Espo/Core/Authentication/Authentication.php @@ -80,6 +80,9 @@ class Authentication private $configDataProvider; + /** + * @var EntityManagerProxy + */ private $entityManager; private $loginFactory; @@ -410,7 +413,7 @@ class Authentication if ($this->isPortal()) { $isPortalRelatedToUser = $this->entityManager - ->getRepository('Portal') + ->getRDBRepository('Portal') ->isRelated($this->getPortal(), 'users', $user); if (!$isPortalRelatedToUser) { diff --git a/application/Espo/Core/Authentication/TwoFactor/Email/EmailLogin.php b/application/Espo/Core/Authentication/TwoFactor/Email/EmailLogin.php index c46fe55705..f0580c3340 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Email/EmailLogin.php +++ b/application/Espo/Core/Authentication/TwoFactor/Email/EmailLogin.php @@ -45,6 +45,9 @@ use Espo\Core\Api\Request; class EmailLogin implements Login { + /** + * @var EntityManager + */ private $entityManager; private $util; diff --git a/application/Espo/Core/Authentication/TwoFactor/Email/Util.php b/application/Espo/Core/Authentication/TwoFactor/Email/Util.php index 351567d05c..b0ac29902f 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Email/Util.php +++ b/application/Espo/Core/Authentication/TwoFactor/Email/Util.php @@ -78,6 +78,9 @@ class Util */ private const CODE_LIMIT_PERIOD = '10 minutes'; + /** + * @var EntityManager + */ private $entityManager; private $config; diff --git a/application/Espo/Core/Authentication/TwoFactor/Sms/SmsLogin.php b/application/Espo/Core/Authentication/TwoFactor/Sms/SmsLogin.php index 89ed06f124..2ead988ac6 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Sms/SmsLogin.php +++ b/application/Espo/Core/Authentication/TwoFactor/Sms/SmsLogin.php @@ -44,6 +44,9 @@ use Espo\Core\Api\Request; class SmsLogin implements Login { + /** + * @var EntityManager + */ private $entityManager; private $util; diff --git a/application/Espo/Core/Authentication/TwoFactor/Sms/Util.php b/application/Espo/Core/Authentication/TwoFactor/Sms/Util.php index 21a3de3d8f..dcfaf57c5c 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Sms/Util.php +++ b/application/Espo/Core/Authentication/TwoFactor/Sms/Util.php @@ -77,6 +77,9 @@ class Util */ private const CODE_LIMIT_PERIOD = '20 minutes'; + /** + * @var EntityManager + */ private $entityManager; private $config; diff --git a/application/Espo/Core/Authentication/TwoFactor/Totp/TotpLogin.php b/application/Espo/Core/Authentication/TwoFactor/Totp/TotpLogin.php index 626223f2b2..61f480ce9b 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Totp/TotpLogin.php +++ b/application/Espo/Core/Authentication/TwoFactor/Totp/TotpLogin.php @@ -45,6 +45,9 @@ use Espo\Core\Api\Request; class TotpLogin implements Login { + /** + * @var EntityManager + */ private $entityManager; private $totp; diff --git a/application/Espo/Core/Authentication/TwoFactor/Totp/TotpUserSetup.php b/application/Espo/Core/Authentication/TwoFactor/Totp/TotpUserSetup.php index aa94da1141..b42dbefe05 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Totp/TotpUserSetup.php +++ b/application/Espo/Core/Authentication/TwoFactor/Totp/TotpUserSetup.php @@ -49,6 +49,9 @@ class TotpUserSetup implements UserSetup private $config; + /** + * @var EntityManager + */ private $entityManager; public function __construct(Util $totp, Config $config, EntityManager $entityManager) diff --git a/application/Espo/Core/Di/EntityManagerSetter.php b/application/Espo/Core/Di/EntityManagerSetter.php index b70fb6cc5b..afc4c6a176 100644 --- a/application/Espo/Core/Di/EntityManagerSetter.php +++ b/application/Espo/Core/Di/EntityManagerSetter.php @@ -33,7 +33,7 @@ use Espo\Core\ORM\EntityManager; trait EntityManagerSetter { - /* + /** * @var EntityManager */ protected $entityManager; diff --git a/application/Espo/Core/FieldProcessing/EmailAddress/Saver.php b/application/Espo/Core/FieldProcessing/EmailAddress/Saver.php index 02991b3f8e..eb63b3fbfa 100644 --- a/application/Espo/Core/FieldProcessing/EmailAddress/Saver.php +++ b/application/Espo/Core/FieldProcessing/EmailAddress/Saver.php @@ -30,6 +30,7 @@ namespace Espo\Core\FieldProcessing\EmailAddress; use Espo\Entities\EmailAddress; +use Espo\Repositories\EmailAddress as EmailAddressRepository; use Espo\ORM\Entity; @@ -42,6 +43,9 @@ use Espo\Core\{ class Saver implements SaverInterface { + /** + * @var EntityManager + */ private $entityManager; private $applicationState; @@ -119,9 +123,10 @@ class Saver implements SaverInterface $previousEmailAddressData = []; if (!$entity->isNew()) { - $previousEmailAddressData = $this->entityManager - ->getRepository('EmailAddress') - ->getEmailAddressData($entity); + /** @var EmailAddressRepository $repository */ + $repository = $this->entityManager->getRepository('EmailAddress'); + + $previousEmailAddressData = $repository->getEmailAddressData($entity); } $hash = (object) []; diff --git a/application/Espo/Core/FieldProcessing/PhoneNumber/Saver.php b/application/Espo/Core/FieldProcessing/PhoneNumber/Saver.php index 39463be8da..c403ce74df 100644 --- a/application/Espo/Core/FieldProcessing/PhoneNumber/Saver.php +++ b/application/Espo/Core/FieldProcessing/PhoneNumber/Saver.php @@ -30,11 +30,12 @@ namespace Espo\Core\FieldProcessing\PhoneNumber; use Espo\Entities\PhoneNumber; +use Espo\Repositories\PhoneNumber as PhoneNumberRepository; use Espo\ORM\Entity; +use Espo\ORM\EntityManager; use Espo\Core\{ - ORM\EntityManager, ApplicationState, Utils\Metadata, FieldProcessing\Saver as SaverInterface, @@ -43,6 +44,9 @@ use Espo\Core\{ class Saver implements SaverInterface { + /** + * @var EntityManager + */ private $entityManager; private $applicationState; @@ -125,9 +129,10 @@ class Saver implements SaverInterface $previousPhoneNumberData = []; if (!$entity->isNew()) { - $previousPhoneNumberData = $this->entityManager - ->getRepository('PhoneNumber') - ->getPhoneNumberData($entity); + /** @var PhoneNumberRepository $repository */ + $repository = $this->entityManager->getRepository('PhoneNumber'); + + $previousPhoneNumberData = $repository->getPhoneNumberData($entity); } $hash = (object) []; diff --git a/application/Espo/Core/Formula/Functions/AttributeType.php b/application/Espo/Core/Formula/Functions/AttributeType.php index 4778256fa2..2c623c1ab6 100644 --- a/application/Espo/Core/Formula/Functions/AttributeType.php +++ b/application/Espo/Core/Formula/Functions/AttributeType.php @@ -42,7 +42,7 @@ class AttributeType extends Base $this->attributeFetcher = $attributeFetcher; } - public function process(\StdClass $item) + public function process(\stdClass $item) { if (!property_exists($item, 'value')) { throw new Error(); diff --git a/application/Espo/Core/Formula/Functions/Base.php b/application/Espo/Core/Formula/Functions/Base.php index 13f34e818a..9b3636c329 100644 --- a/application/Espo/Core/Formula/Functions/Base.php +++ b/application/Espo/Core/Formula/Functions/Base.php @@ -36,10 +36,9 @@ use Espo\Core\Interfaces\Injectable; use Espo\ORM\Entity; use Espo\Core\Formula\Processor; -use Espo\Core\Formula\ArgumentList; use Espo\Core\Formula\Argument; -use StdClass; +use stdClass; /** * @deprecated Use BaseFormula instead. @@ -85,7 +84,7 @@ abstract class Base implements Injectable return $this->dependencyList; } - public function __construct(string $name, Processor $processor, ?Entity $entity = null, ?StdClass $variables = null) + public function __construct(string $name, Processor $processor, ?Entity $entity = null, ?stdClass $variables = null) { $this->name = $name; $this->processor = $processor; @@ -99,7 +98,7 @@ abstract class Base implements Injectable { } - protected function getVariables(): StdClass + protected function getVariables(): stdClass { return $this->variables; } @@ -112,7 +111,7 @@ abstract class Base implements Injectable return $this->entity; } - public abstract function process(StdClass $item); + public abstract function process(stdClass $item); protected function evaluate($item) { @@ -120,7 +119,7 @@ abstract class Base implements Injectable return $this->processor->process($item); } - protected function fetchArguments(StdClass $item): array + protected function fetchArguments(stdClass $item): array { $args = $item->value ?? []; @@ -132,7 +131,7 @@ abstract class Base implements Injectable return $eArgs; } - protected function fetchRawArguments(StdClass $item): array + protected function fetchRawArguments(stdClass $item): array { return $item->value ?? []; } diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/AddLinkMultipleIdType.php b/application/Espo/Core/Formula/Functions/EntityGroup/AddLinkMultipleIdType.php index 2dd77639f6..b30cc45098 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/AddLinkMultipleIdType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/AddLinkMultipleIdType.php @@ -33,7 +33,7 @@ use Espo\Core\Exceptions\Error; class AddLinkMultipleIdType extends \Espo\Core\Formula\Functions\Base { - public function process(\StdClass $item) + public function process(\stdClass $item) { if (count($item->value) < 2) { throw new Error("addLinkMultipleId function: Too few arguments."); diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/AttributeType.php b/application/Espo/Core/Formula/Functions/EntityGroup/AttributeType.php index 4b3eb49d3e..5f963ea394 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/AttributeType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/AttributeType.php @@ -33,7 +33,7 @@ use Espo\Core\Exceptions\Error; class AttributeType extends \Espo\Core\Formula\Functions\AttributeType { - public function process(\StdClass $item) + public function process(\stdClass $item) { if (count($item->value) < 1) { throw new Error("attribute function: Too few arguments."); diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php index 61255da64e..7fbcfb2d19 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php @@ -31,9 +31,11 @@ namespace Espo\Core\Formula\Functions\EntityGroup; use Espo\Core\Exceptions\Error; +use Espo\Core\ORM\EntityManager; + use Espo\Core\Di; -use StdClass; +use stdClass; class CountRelatedType extends \Espo\Core\Formula\Functions\Base implements Di\EntityManagerAware, @@ -42,7 +44,12 @@ class CountRelatedType extends \Espo\Core\Formula\Functions\Base implements use Di\EntityManagerSetter; use Di\SelectBuilderFactorySetter; - public function process(StdClass $item) + /** + * @var EntityManager + */ + protected $entityManager; + + public function process(stdClass $item) { if (count($item->value) < 1) { throw new Error("countRelated: roo few arguments."); @@ -78,7 +85,7 @@ class CountRelatedType extends \Espo\Core\Formula\Functions\Base implements $builder->withPrimaryFilter($filter); } - return $entityManager->getRepository($entity->getEntityType()) + return $entityManager->getRDBRepository($entity->getEntityType()) ->getRelation($entity, $link) ->clone($builder->build()) ->count(); diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php b/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php index f7672beb57..b7003f9bb5 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php @@ -31,6 +31,8 @@ namespace Espo\Core\Formula\Functions\EntityGroup; use Espo\Core\Exceptions\Error; +use Espo\Core\ORM\EntityManager; + use Espo\Core\Di; class GetLinkColumnType extends \Espo\Core\Formula\Functions\Base implements @@ -38,7 +40,12 @@ class GetLinkColumnType extends \Espo\Core\Formula\Functions\Base implements { use Di\EntityManagerSetter; - public function process(\StdClass $item) + /** + * @var EntityManager + */ + protected $entityManager; + + public function process(\stdClass $item) { $args = $item->value ?? []; @@ -51,7 +58,7 @@ class GetLinkColumnType extends \Espo\Core\Formula\Functions\Base implements $column = $this->evaluate($args[2]); $entityType = $this->getEntity()->getEntityType(); - $repository = $this->entityManager->getRepository($entityType); + $repository = $this->entityManager->getRDBRepository($entityType); return $repository->getRelationColumn($this->getEntity(), $link, $id, $column); } diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/HasLinkMultipleIdType.php b/application/Espo/Core/Formula/Functions/EntityGroup/HasLinkMultipleIdType.php index 8d331d8436..c8958ae7ad 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/HasLinkMultipleIdType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/HasLinkMultipleIdType.php @@ -33,7 +33,7 @@ use Espo\Core\Exceptions\Error; class HasLinkMultipleIdType extends \Espo\Core\Formula\Functions\Base { - public function process(\StdClass $item) + public function process(\stdClass $item) { if (count($item->value) < 2) { throw new Error("hasLinkMultipleId: too few arguments."); diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php index ce4cf2c336..8facff3c89 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php @@ -33,7 +33,7 @@ use Espo\Core\Exceptions\Error; class IsAttributeChangedType extends \Espo\Core\Formula\Functions\Base { - public function process(\StdClass $item) + public function process(\stdClass $item) { if (count($item->value) < 1) { throw new Error("isAttributeChanged: too few arguments."); diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsNewType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsNewType.php index 169040ea78..688e855b59 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsNewType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsNewType.php @@ -31,7 +31,7 @@ namespace Espo\Core\Formula\Functions\EntityGroup; class IsNewType extends \Espo\Core\Formula\Functions\Base { - public function process(\StdClass $item) + public function process(\stdClass $item) { return $this->getEntity()->isNew(); } diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php index 0c07a16917..5b5a23f025 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php @@ -31,6 +31,8 @@ namespace Espo\Core\Formula\Functions\EntityGroup; use Espo\Core\Exceptions\Error; +use Espo\Core\ORM\EntityManager; + use Espo\Core\Di; class IsRelatedType extends \Espo\Core\Formula\Functions\Base implements @@ -38,7 +40,12 @@ class IsRelatedType extends \Espo\Core\Formula\Functions\Base implements { use Di\EntityManagerSetter; - public function process(\StdClass $item) + /** + * @var EntityManager + */ + protected $entityManager; + + public function process(\stdClass $item) { if (count($item->value) < 2) { throw new Error("isRelated: roo few arguments."); @@ -47,6 +54,8 @@ class IsRelatedType extends \Espo\Core\Formula\Functions\Base implements $link = $this->evaluate($item->value[0]); $id = $this->evaluate($item->value[1]); - return $this->entityManager->getRepository($this->getEntity()->getEntityType())->isRelated($this->getEntity(), $link, $id); + return $this->entityManager + ->getRDBRepository($this->getEntity()->getEntityType()) + ->isRelated($this->getEntity(), $link, $id); } } diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/RemoveLinkMultipleIdType.php b/application/Espo/Core/Formula/Functions/EntityGroup/RemoveLinkMultipleIdType.php index a483735b00..60a32bbe10 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/RemoveLinkMultipleIdType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/RemoveLinkMultipleIdType.php @@ -33,7 +33,7 @@ use Espo\Core\Exceptions\Error; class RemoveLinkMultipleIdType extends \Espo\Core\Formula\Functions\Base { - public function process(\StdClass $item) + public function process(\stdClass $item) { if (count($item->value) < 2) { throw new Error("removeLinkMultipleId: roo few arguments."); diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php index 7a777bb5f6..69313ac73c 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php @@ -33,7 +33,7 @@ use Espo\Core\Exceptions\Error; use Espo\Core\Di; -use StdClass; +use stdClass; use PDO; class SumRelatedType extends \Espo\Core\Formula\Functions\Base implements @@ -43,7 +43,7 @@ class SumRelatedType extends \Espo\Core\Formula\Functions\Base implements use Di\EntityManagerSetter; use Di\SelectBuilderFactorySetter; - public function process(StdClass $item) + public function process(stdClass $item) { if (count($item->value) < 2) { throw new Error("sumRelated: Too few arguments."); diff --git a/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/ApplyTemplateType.php b/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/ApplyTemplateType.php index c0aab35bdb..e5b4699d23 100644 --- a/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/ApplyTemplateType.php +++ b/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/ApplyTemplateType.php @@ -29,6 +29,8 @@ namespace Espo\Core\Formula\Functions\ExtGroup\EmailGroup; +use Espo\Entities\Email; + use Espo\Core\Formula\{ Functions\BaseFunction, ArgumentList, @@ -74,13 +76,17 @@ class ApplyTemplateType extends BaseFunction implements $em = $this->entityManager; + /** @var Email $email */ $email = $em->getEntity('Email', $id); + $emailTemplate = $em->getEntity('EmailTemplate', $templateId); if (!$email) { $this->log("Email {$id} does not exist."); + return false; } + if (!$emailTemplate) { $this->log("EmailTemplate {$templateId} does not exist."); return false; @@ -108,6 +114,7 @@ class ApplyTemplateType extends BaseFunction implements } $emailAddressList = $email->get('toEmailAddresses'); + if (count($emailAddressList)) { $params['emailAddress'] = $emailAddressList[0]->get('name'); } @@ -115,6 +122,7 @@ class ApplyTemplateType extends BaseFunction implements $data = $emailTemplateService->parseTemplate($emailTemplate, $params, true, true); $attachmentsIds = $email->getLinkMultipleIdList('attachments'); + $attachmentsIds = array_merge($attachmentsIds, $data['attachmentsIds']); $email->set([ diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/AttributeType.php b/application/Espo/Core/Formula/Functions/RecordGroup/AttributeType.php index bab96e2e7e..4f6a77b83a 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/AttributeType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/AttributeType.php @@ -38,7 +38,7 @@ class AttributeType extends \Espo\Core\Formula\Functions\AttributeType implement { use Di\EntityManagerSetter; - public function process(\StdClass $item) + public function process(\stdClass $item) { if (count($item->value) < 3) { throw new Error("record\\attribute: too few arguments."); diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/CountType.php b/application/Espo/Core/Formula/Functions/RecordGroup/CountType.php index d0193d44ee..e006343ed4 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/CountType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/CountType.php @@ -71,7 +71,7 @@ class CountType extends BaseFunction implements } return $this->entityManager - ->getRepository($entityType) + ->getRDBRepository($entityType) ->clone($builder->build()) ->count(); } @@ -90,7 +90,7 @@ class CountType extends BaseFunction implements } return $this->entityManager - ->getRepository($entityType) + ->getRDBRepository($entityType) ->where($whereClause) ->count(); } diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php b/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php index 7011dcf2bb..d66b5fb715 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php @@ -71,7 +71,7 @@ class CreateType extends BaseFunction implements $entity = $this->entityManager->createEntity($entityType, $data); if ($entity) { - return $entity->id; + return $entity->getId(); } return null; diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/ExistsType.php b/application/Espo/Core/Formula/Functions/RecordGroup/ExistsType.php index 2f86feba9e..6e373757b6 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/ExistsType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/ExistsType.php @@ -29,6 +29,8 @@ namespace Espo\Core\Formula\Functions\RecordGroup; +use Espo\Core\ORM\EntityManager; + use Espo\Core\Formula\{ Functions\BaseFunction, ArgumentList, @@ -41,6 +43,11 @@ class ExistsType extends BaseFunction implements { use Di\EntityManagerSetter; + /** + * @var EntityManager + */ + protected $entityManager; + public function process(ArgumentList $args) { if (count($args) < 3) { @@ -59,6 +66,9 @@ class ExistsType extends BaseFunction implements $i = $i + 2; } - return (bool) $this->entityManager->getRepository($entityType)->where($whereClause)->findOne(); + return (bool) $this->entityManager + ->getRDBRepository($entityType) + ->where($whereClause) + ->findOne(); } } diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/FindOneType.php b/application/Espo/Core/Formula/Functions/RecordGroup/FindOneType.php index 810256e678..5287a2c15d 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/FindOneType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/FindOneType.php @@ -100,12 +100,12 @@ class FindOneType extends BaseFunction implements $queryBuilder->select(['id']); $entity = $this->entityManager - ->getRepository($entityType) + ->getRDBRepository($entityType) ->clone($queryBuilder->build()) ->findOne(); if ($entity) { - return $entity->id; + return $entity->getId(); } return null; diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php index dbd7c2e711..041e583f40 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php @@ -29,6 +29,8 @@ namespace Espo\Core\Formula\Functions\RecordGroup; +use Espo\Core\ORM\Entity as CoreEntity; + use Espo\Core\Formula\{ Functions\BaseFunction, ArgumentList, @@ -113,6 +115,8 @@ class FindRelatedManyType extends BaseFunction implements $order = $order ?? 'asc'; } + assert($entity instanceof CoreEntity); + $relationType = $entity->getRelationParam($link, 'type'); if (in_array($relationType, ['belongsTo', 'hasOne', 'belongsToParent'])) { @@ -191,7 +195,7 @@ class FindRelatedManyType extends BaseFunction implements } $collection = $entityManager - ->getRepository($foreignEntityType) + ->getRDBRepository($foreignEntityType) ->clone($queryBuilder->build()) ->select(['id']) ->find(); diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php index add55a3fce..b484140753 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php @@ -29,6 +29,8 @@ namespace Espo\Core\Formula\Functions\RecordGroup; +use Espo\Core\ORM\Entity as CoreEntity; + use Espo\Core\Formula\{ Functions\BaseFunction, ArgumentList, @@ -88,11 +90,13 @@ class FindRelatedOneType extends BaseFunction implements $metadata = $this->metadata; + assert($entity instanceof CoreEntity); + $relationType = $entity->getRelationParam($link, 'type'); if (in_array($relationType, ['belongsTo', 'hasOne', 'belongsToParent'])) { $relatedEntity = $entityManager - ->getRepository($entityType) + ->getRDBRepository($entityType) ->getRelation($entity, $link) ->select(['id']) ->findOne(); @@ -101,7 +105,7 @@ class FindRelatedOneType extends BaseFunction implements return null; } - return $relatedEntity->id; + return $relatedEntity->getId(); } if (!$orderBy) { @@ -168,7 +172,7 @@ class FindRelatedOneType extends BaseFunction implements if ($relationType === 'hasChildren') { $queryBuilder->where([ - $foreignLink . 'Id' => $entity->id, + $foreignLink . 'Id' => $entity->getId(), $foreignLink . 'Type' => $entity->getEntityType(), ]); } @@ -176,7 +180,7 @@ class FindRelatedOneType extends BaseFunction implements $queryBuilder ->join($foreignLink) ->where([ - $foreignLink . '.id' => $entity->id, + $foreignLink . '.id' => $entity->getId(), ]); } @@ -185,13 +189,13 @@ class FindRelatedOneType extends BaseFunction implements } $relatedEntity = $entityManager - ->getRepository($foreignEntityType) + ->getRDBRepository($foreignEntityType) ->clone($queryBuilder->build()) ->select(['id']) ->findOne(); if ($relatedEntity) { - return $relatedEntity->id; + return $relatedEntity->getId(); } return null; diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/RelateType.php b/application/Espo/Core/Formula/Functions/RecordGroup/RelateType.php index 853ddc5b20..a57909b603 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/RelateType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/RelateType.php @@ -55,12 +55,15 @@ class RelateType extends BaseFunction implements if (!$entityType || !is_string($entityType)) { $this->throwBadArgumentType(1, 'string'); } + if (!$id) { return null; } + if (!$link || !is_string($link)) { $this->throwBadArgumentType(3, 'string'); } + if (!$foreignId) { return null; } @@ -72,20 +75,25 @@ class RelateType extends BaseFunction implements } $entity = $em->getEntity($entityType, $id); - if (!$entity) return null; + + if (!$entity) { + return null; + } if (is_array($foreignId)) { foreach ($foreignId as $itemId) { - $em->getRepository($entityType)->relate($entity, $link, $itemId); + $em->getRDBRepository($entityType)->relate($entity, $link, $itemId); } + return true; } if (is_string($foreignId)) { - if ($em->getRepository($entityType)->isRelated($entity, $link, $foreignId)) { + if ($em->getRDBRepository($entityType)->isRelated($entity, $link, $foreignId)) { return true; } - return $em->getRepository($entityType)->relate($entity, $link, $foreignId); + + return $em->getRDBRepository($entityType)->relate($entity, $link, $foreignId); } $this->throwError("foreignId type is wrong."); diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/RelationColumnType.php b/application/Espo/Core/Formula/Functions/RecordGroup/RelationColumnType.php index dc890aa3ff..1bfbd8de78 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/RelationColumnType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/RelationColumnType.php @@ -58,15 +58,19 @@ class RelationColumnType extends BaseFunction implements if (!$entityType) { $this->throwError("Empty entityType."); } + if (!$id) { return null; } + if (!$link) { $this->throwError("Empty link."); } + if (!$foreignId) { return null; } + if (!$column) { $this->throwError("Empty column."); } @@ -78,8 +82,11 @@ class RelationColumnType extends BaseFunction implements } $entity = $em->getEntity($entityType, $id); - if (!$entity) return null; - return $em->getRepository($entityType)->getRelationColumn($entity, $link, $foreignId, $column); + if (!$entity) { + return null; + } + + return $em->getRDBRepository($entityType)->getRelationColumn($entity, $link, $foreignId, $column); } } diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/UnrelateType.php b/application/Espo/Core/Formula/Functions/RecordGroup/UnrelateType.php index adfc26126d..484e16ea67 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/UnrelateType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/UnrelateType.php @@ -80,11 +80,11 @@ class UnrelateType extends BaseFunction implements return null; } - if (!$em->getRepository($entityType)->isRelated($entity, $link, $foreignId)) { + if (!$em->getRDBRepository($entityType)->isRelated($entity, $link, $foreignId)) { return true; } - $em->getRepository($entityType)->unrelate($entity, $link, $foreignId); + $em->getRDBRepository($entityType)->unrelate($entity, $link, $foreignId); return true; } diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/UpdateRelationColumnType.php b/application/Espo/Core/Formula/Functions/RecordGroup/UpdateRelationColumnType.php index 31cd6c5b89..7607457d1f 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/UpdateRelationColumnType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/UpdateRelationColumnType.php @@ -56,11 +56,25 @@ class UpdateRelationColumnType extends BaseFunction implements $column = $args[4]; $value = $args[5]; - if (!$entityType) $this->throwError("Empty entityType."); - if (!$id) return null; - if (!$link) $this->throwError("Empty link."); - if (!$foreignId) return null; - if (!$column) $this->throwError("Empty column."); + if (!$entityType) { + $this->throwError("Empty entityType."); + } + + if (!$id) { + return null; + } + + if (!$link) { + $this->throwError("Empty link."); + } + + if (!$foreignId) { + return null; + } + + if (!$column) { + $this->throwError("Empty column."); + } $em = $this->entityManager; @@ -70,8 +84,10 @@ class UpdateRelationColumnType extends BaseFunction implements $entity = $em->getEntity($entityType, $id); - if (!$entity) return null; + if (!$entity) { + return null; + } - return $em->getRepository($entityType)->updateRelation($entity, $link, $foreignId, [$column => $value]); + return $em->getRDBRepository($entityType)->updateRelation($entity, $link, $foreignId, [$column => $value]); } } diff --git a/application/Espo/Core/Formula/Functions/SetAttributeType.php b/application/Espo/Core/Formula/Functions/SetAttributeType.php index bf59222f1e..b6d4e6f109 100644 --- a/application/Espo/Core/Formula/Functions/SetAttributeType.php +++ b/application/Espo/Core/Formula/Functions/SetAttributeType.php @@ -33,7 +33,7 @@ use Espo\Core\Exceptions\Error; class SetAttributeType extends Base { - public function process(\StdClass $item) + public function process(\stdClass $item) { if (count($item->value) < 2) { throw new Error("SetAttribute: Too few arguments."); diff --git a/application/Espo/Core/Mail/Importer.php b/application/Espo/Core/Mail/Importer.php index 16c5a169f6..ef478a4165 100644 --- a/application/Espo/Core/Mail/Importer.php +++ b/application/Espo/Core/Mail/Importer.php @@ -30,6 +30,7 @@ namespace Espo\Core\Mail; use Espo\Entities\Email; +use Espo\Repositories\Email as EmailRepository; use Espo\ORM\EntityManager; @@ -41,6 +42,7 @@ use Espo\Core\Utils\Config; use Espo\Core\FieldProcessing\Relation\LinkMultipleSaver; use Espo\Core\FieldProcessing\Saver\Params as SaverParams; use Espo\Core\Job\QueueName; +use Espo\Core\ORM\Entity as CoreEntity; use Espo\Modules\Crm\Entities\Lead; @@ -53,6 +55,9 @@ use Exception; */ class Importer { + /** + * @var EntityManager + */ private $entityManager; private $config; @@ -97,6 +102,8 @@ class Importer $email = $this->entityManager->getEntity('Email'); + assert($email instanceof Email); + $email->set('isBeingImported', true); $subject = ''; @@ -265,6 +272,7 @@ class Importer $inReplyTo = '<' . $inReplyTo . '>'; } + /** @var Email $replied */ $replied = $this->entityManager ->getRDBRepository('Email') ->where([ @@ -273,7 +281,8 @@ class Importer ->findOne(); if ($replied) { - $email->set('repliedId', $replied->id); + $email->set('repliedId', $replied->getId()); + $repliedTeamIdList = $replied->getLinkMultipleIdList('teams'); foreach ($repliedTeamIdList as $repliedTeamId) { @@ -364,7 +373,10 @@ class Importer 'replyToString' => $email->get('replyToString'), ]); - $this->entityManager->getRepository('Email')->fillAccount($duplicate); + /** @var EmailRepository $emailRepository */ + $emailRepository = $this->entityManager->getRDBRepository('Email'); + + $emailRepository->fillAccount($duplicate); $this->processDuplicate( $duplicate, @@ -435,6 +447,8 @@ class Importer return; } + assert($parent instanceof CoreEntity); + $parentTeamIdList = $parent->getLinkMultipleIdList('teams'); foreach ($parentTeamIdList as $parentTeamId) { @@ -562,7 +576,7 @@ class Importer } $email->set('parentType', 'Contact'); - $email->set('parentId', $contact->id); + $email->set('parentId', $contact->getId()); return true; } @@ -576,7 +590,7 @@ class Importer if ($account) { $email->set('parentType', 'Account'); - $email->set('parentId', $account->id); + $email->set('parentId', $account->getId()); return true; } @@ -590,7 +604,7 @@ class Importer if ($lead) { $email->set('parentType', 'Lead'); - $email->set('parentId', $lead->id); + $email->set('parentId', $lead->getId()); return true; } @@ -623,9 +637,12 @@ class Importer array $teamIdList ): void { + /** @var EmailRepository $emailRepository */ + $emailRepository = $this->entityManager->getRDBRepository('Email'); + if ($duplicate->get('status') == Email::STATUS_ARCHIVED) { - $this->entityManager->getRepository('Email')->loadFromField($duplicate); - $this->entityManager->getRepository('Email')->loadToField($duplicate); + $emailRepository->loadFromField($duplicate); + $emailRepository->loadToField($duplicate); } $duplicate->loadLinkMultipleField('users'); @@ -662,7 +679,7 @@ class Importer } $this->entityManager - ->getRepository('Email') + ->getRDBRepository('Email') ->updateRelation($duplicate, 'users', $uId, [ 'folderId' => $folderId, ]); @@ -670,9 +687,7 @@ class Importer $duplicate->set('isBeingImported', true); - $this->entityManager - ->getRepository('Email') - ->applyUsersFilters($duplicate); + $emailRepository->applyUsersFilters($duplicate); $saverParams = SaverParams::create()->withRawOptions([ 'skipLinkMultipleRemove' => true, @@ -695,7 +710,9 @@ class Importer if (!in_array($teamId, $fetchedTeamIdList)) { $processNoteAcl = true; - $this->entityManager->getRepository('Email')->relate($duplicate, 'teams', $teamId); + $this->entityManager + ->getRDBRepository('Email') + ->relate($duplicate, 'teams', $teamId); } } @@ -717,7 +734,7 @@ class Importer 'methodName' => 'processNoteAclJob', 'data' => [ 'targetType' => 'Email', - 'targetId' => $duplicate->id + 'targetId' => $duplicate->getId(), ], 'executeAt' => $executeAt, 'queue' => QueueName::Q1, diff --git a/application/Espo/Core/Mail/Sender.php b/application/Espo/Core/Mail/Sender.php index a67afa648e..70f645feb7 100644 --- a/application/Espo/Core/Mail/Sender.php +++ b/application/Espo/Core/Mail/Sender.php @@ -29,6 +29,8 @@ namespace Espo\Core\Mail; +use Espo\Repositories\Attachment as AttachmentRepository; + use Laminas\{ Mime\Message as MimeMessage, Mime\Part as MimePart, @@ -70,6 +72,9 @@ class Sender { private $config; + /** + * @var EntityManager + */ private $entityManager; private $serviceFactory; @@ -376,7 +381,7 @@ class Sender if (!$this->systemInboundEmailIsCached && $address) { $this->systemInboundEmail = $this->entityManager - ->getRepository('InboundEmail') + ->getRDBRepository('InboundEmail') ->where([ 'status' => 'Active', 'useSmtp' => true, @@ -482,7 +487,7 @@ class Sender if (!$email->isNew()) { $attachmentCollection = $this->entityManager - ->getRepository('Email') + ->getRDBRepository('Email') ->getRelation($email, 'attachments') ->find(); } @@ -494,14 +499,15 @@ class Sender } if (!empty($attachmentCollection)) { + /** @var AttachmentRepository $attachmentRepository */ + $attachmentRepository = $this->entityManager->getRepository('Attachment'); + foreach ($attachmentCollection as $a) { if ($a->get('contents')) { $contents = $a->get('contents'); } else { - $fileName = $this->entityManager - ->getRepository('Attachment') - ->getFilePath($a); + $fileName = $attachmentRepository->getFilePath($a); if (!is_file($fileName)) { continue; @@ -527,12 +533,15 @@ class Sender $attachmentInlineList = $email->getInlineAttachmentList(); if (!empty($attachmentInlineList)) { + /** @var AttachmentRepository $attachmentRepository */ + $attachmentRepository = $this->entityManager->getRepository('Attachment'); + foreach ($attachmentInlineList as $a) { if ($a->get('contents')) { $contents = $a->get('contents'); } else { - $fileName = $this->entityManager->getRepository('Attachment')->getFilePath($a); + $fileName = $attachmentRepository->getFilePath($a); if (!is_file($fileName)) { continue; diff --git a/application/Espo/Core/MassAction/Actions/MassDelete.php b/application/Espo/Core/MassAction/Actions/MassDelete.php index ab507cbf16..ebad07f6c0 100644 --- a/application/Espo/Core/MassAction/Actions/MassDelete.php +++ b/application/Espo/Core/MassAction/Actions/MassDelete.php @@ -49,6 +49,9 @@ class MassDelete implements MassAction protected $recordServiceContainer; + /** + * @var EntityManager + */ protected $entityManager; public function __construct( @@ -77,7 +80,7 @@ class MassDelete implements MassAction $service = $this->recordServiceContainer->get($entityType); - $repository = $this->entityManager->getRepository($entityType); + $repository = $this->entityManager->getRDBRepository($entityType); $query = $this->queryBuilder->build($params); diff --git a/application/Espo/Core/MassAction/Actions/MassUpdate.php b/application/Espo/Core/MassAction/Actions/MassUpdate.php index 22f1c32b39..e35298d6d4 100644 --- a/application/Espo/Core/MassAction/Actions/MassUpdate.php +++ b/application/Espo/Core/MassAction/Actions/MassUpdate.php @@ -29,6 +29,8 @@ namespace Espo\Core\MassAction\Actions; +use Espo\Repositories\Attachment as AttachmentRepository; + use Espo\Core\{ MassAction\QueryBuilder, MassAction\Params, @@ -44,7 +46,7 @@ use Espo\Core\{ }; use Exception; -use StdClass; +use stdClass; class MassUpdate implements MassAction { @@ -54,6 +56,9 @@ class MassUpdate implements MassAction protected $recordServiceContainer; + /** + * @var EntityManager + */ protected $entityManager; protected $fieldUtil; @@ -88,7 +93,7 @@ class MassUpdate implements MassAction $service = $this->recordServiceContainer->get($entityType); - $repository = $this->entityManager->getRepository($entityType); + $repository = $this->entityManager->getRDBRepository($entityType); $service->filterUpdateInput($valueMap); @@ -147,10 +152,10 @@ class MassUpdate implements MassAction protected function prepareItemValueMap( string $entityType, - StdClass $valueMap, + stdClass $valueMap, int $i, array $fieldToCopyList - ): StdClass { + ): stdClass { $clonedValueMap = ObjectUtil::clone($valueMap); @@ -181,7 +186,7 @@ class MassUpdate implements MassAction return $clonedValueMap; } - protected function copyFileField(string $field, StdClass $valueMap): void + protected function copyFileField(string $field, stdClass $valueMap): void { $idAttribute = $field . 'Id'; @@ -199,14 +204,15 @@ class MassUpdate implements MassAction return; } - $copiedAttachment = $this->entityManager - ->getRepository('Attachment') - ->getCopiedAttachment($attachment); + /** @var AttachmentRepository $attachmentRepository */ + $attachmentRepository = $this->entityManager->getRepository('Attachment'); - $valueMap->$idAttribute = $copiedAttachment->id; + $copiedAttachment = $attachmentRepository->getCopiedAttachment($attachment); + + $valueMap->$idAttribute = $copiedAttachment->getId(); } - protected function copyAttachmentMultipleField(string $field, StdClass $valueMap): void + protected function copyAttachmentMultipleField(string $field, stdClass $valueMap): void { $idsAttribute = $field . 'Ids'; @@ -216,6 +222,9 @@ class MassUpdate implements MassAction return; } + /** @var AttachmentRepository $attachmentRepository */ + $attachmentRepository = $this->entityManager->getRepository('Attachment'); + $copiedIds = []; foreach ($ids as $id) { @@ -225,17 +234,15 @@ class MassUpdate implements MassAction continue; } - $copiedAttachment = $this->entityManager - ->getRepository('Attachment') - ->getCopiedAttachment($attachment); + $copiedAttachment = $attachmentRepository->getCopiedAttachment($attachment); - $copiedIds[] = $copiedAttachment->id; + $copiedIds[] = $copiedAttachment->getId(); } $valueMap->$idsAttribute = $copiedIds; } - protected function detectFieldToCopyList(string $entityType, StdClass $valueMap): array + protected function detectFieldToCopyList(string $entityType, stdClass $valueMap): array { $resultFieldList = []; diff --git a/application/Espo/Core/Portal/Acl/DefaultOwnershipChecker.php b/application/Espo/Core/Portal/Acl/DefaultOwnershipChecker.php index 698a304c05..4fdcf6ef15 100644 --- a/application/Espo/Core/Portal/Acl/DefaultOwnershipChecker.php +++ b/application/Espo/Core/Portal/Acl/DefaultOwnershipChecker.php @@ -74,6 +74,9 @@ class DefaultOwnershipChecker implements private const FIELD_PARENT = 'parent'; + /** + * @var EntityManager + */ private $entityManager; public function __construct(EntityManager $entityManager) @@ -116,7 +119,7 @@ class DefaultOwnershipChecker implements $entity->hasRelation(self::FIELD_ACCOUNTS) && $this->getRelationParam($entity, self::FIELD_ACCOUNTS, 'entity') === self::ENTITY_ACCOUNT ) { - $repository = $this->entityManager->getRepository($entity->getEntityType()); + $repository = $this->entityManager->getRDBRepository($entity->getEntityType()); foreach ($accountIdList as $accountId) { if ($repository->isRelated($entity, self::FIELD_ACCOUNTS, $accountId)) { @@ -158,7 +161,7 @@ class DefaultOwnershipChecker implements $entity->hasRelation(self::FIELD_CONTACTS) && $this->getRelationParam($entity, self::FIELD_CONTACTS, 'entity') === self::ENTITY_CONTACT ) { - $repository = $this->entityManager->getRepository($entity->getEntityType()); + $repository = $this->entityManager->getRDBRepository($entity->getEntityType()); if ($repository->isRelated($entity, self::FIELD_CONTACTS, $contactId)) { return true; diff --git a/application/Espo/Core/Utils/ScheduledJob.php b/application/Espo/Core/Utils/ScheduledJob.php index f9d877b9fd..0e980061ec 100644 --- a/application/Espo/Core/Utils/ScheduledJob.php +++ b/application/Espo/Core/Utils/ScheduledJob.php @@ -65,6 +65,9 @@ class ScheduledJob private $language; + /** + * @var EntityManager + */ private $entityManager; private $metadataProvider; @@ -162,6 +165,6 @@ class ScheduledJob ] ]; - return (bool) $this->entityManager->getRepository('Job')->findOne($selectParams); + return (bool) $this->entityManager->getRDBRepository('Job')->findOne($selectParams); } } diff --git a/application/Espo/Repositories/Attachment.php b/application/Espo/Repositories/Attachment.php index 54922082d4..43bc97672a 100644 --- a/application/Espo/Repositories/Attachment.php +++ b/application/Espo/Repositories/Attachment.php @@ -127,6 +127,9 @@ class Attachment extends \Espo\Core\Repositories\Database implements } } + /** + * @return AttachmentEntity + */ public function getCopiedAttachment(AttachmentEntity $entity, $role = null) { $attachment = $this->get();