type fixes

This commit is contained in:
Yuri Kuznetsov
2021-11-02 18:16:42 +02:00
parent 7250e0e5c4
commit 2a0ceceb2f
43 changed files with 258 additions and 100 deletions
@@ -38,6 +38,9 @@ use const MCRYPT_DEV_URANDOM;
class EspoManager implements Manager
{
/**
* @var EntityManager
*/
private $entityManager;
private $repository;
@@ -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) {
@@ -45,6 +45,9 @@ use Espo\Core\Api\Request;
class EmailLogin implements Login
{
/**
* @var EntityManager
*/
private $entityManager;
private $util;
@@ -78,6 +78,9 @@ class Util
*/
private const CODE_LIMIT_PERIOD = '10 minutes';
/**
* @var EntityManager
*/
private $entityManager;
private $config;
@@ -44,6 +44,9 @@ use Espo\Core\Api\Request;
class SmsLogin implements Login
{
/**
* @var EntityManager
*/
private $entityManager;
private $util;
@@ -77,6 +77,9 @@ class Util
*/
private const CODE_LIMIT_PERIOD = '20 minutes';
/**
* @var EntityManager
*/
private $entityManager;
private $config;
@@ -45,6 +45,9 @@ use Espo\Core\Api\Request;
class TotpLogin implements Login
{
/**
* @var EntityManager
*/
private $entityManager;
private $totp;
@@ -49,6 +49,9 @@ class TotpUserSetup implements UserSetup
private $config;
/**
* @var EntityManager
*/
private $entityManager;
public function __construct(Util $totp, Config $config, EntityManager $entityManager)
@@ -33,7 +33,7 @@ use Espo\Core\ORM\EntityManager;
trait EntityManagerSetter
{
/*
/**
* @var EntityManager
*/
protected $entityManager;
@@ -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) [];
@@ -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) [];
@@ -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();
@@ -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 ?? [];
}
@@ -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.");
@@ -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.");
@@ -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();
@@ -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);
}
@@ -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.");
@@ -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.");
@@ -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();
}
@@ -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);
}
}
@@ -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.");
@@ -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.");
@@ -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([
@@ -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.");
@@ -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();
}
@@ -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;
@@ -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();
}
}
@@ -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;
@@ -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();
@@ -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;
@@ -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.");
@@ -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);
}
}
@@ -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;
}
@@ -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]);
}
}
@@ -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.");
+30 -13
View File
@@ -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,
+15 -6
View File
@@ -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;
@@ -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);
@@ -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 = [];
@@ -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;
+4 -1
View File
@@ -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);
}
}
@@ -127,6 +127,9 @@ class Attachment extends \Espo\Core\Repositories\Database implements
}
}
/**
* @return AttachmentEntity
*/
public function getCopiedAttachment(AttachmentEntity $entity, $role = null)
{
$attachment = $this->get();