type fixes

This commit is contained in:
Yuri Kuznetsov
2021-11-10 16:04:31 +02:00
parent f496f386ee
commit 3a68ebcbf4
10 changed files with 160 additions and 24 deletions

View File

@@ -40,8 +40,19 @@ use Espo\Core\{
*/
class TemplateEntityTypeList
{
/**
* @var Acl
*/
protected $acl;
/**
* @var SelectBuilderFactory
*/
protected $selectBuilderFactory;
/**
* @var EntityManager
*/
protected $entityManager;
public function __construct(Acl $acl, SelectBuilderFactory $selectBuilderFactory, EntityManager $entityManager)
@@ -51,7 +62,7 @@ class TemplateEntityTypeList
$this->entityManager = $entityManager;
}
public function get() : array
public function get(): array
{
if (!$this->acl->checkScope('Template')) {
return [];
@@ -69,7 +80,7 @@ class TemplateEntityTypeList
->build();
$templateCollection = $this->entityManager
->getRepository('Template')
->getRDBRepository('Template')
->clone($query)
->find();

View File

@@ -40,8 +40,14 @@ use DateTimeZone;
class CheckNewVersion implements JobDataLess
{
/**
* @var Config
*/
protected $config;
/**
* @var EntityManager
*/
protected $entityManager;
public function __construct(Config $config, EntityManager $entityManager)

View File

@@ -44,12 +44,16 @@ use Espo\{
class FromEquals implements ItemConverter
{
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var EmailAddressHelper
*/
protected $emailAddressHelper;
protected $randomStringGenerator;
public function __construct(
EntityManager $entityManager,
EmailAddressHelper $emailAddressHelper

View File

@@ -45,10 +45,19 @@ use Espo\{
class InFolder implements ItemConverter
{
/**
* @var User
*/
protected $user;
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var JoinHelper
*/
protected $joinHelper;
public function __construct(User $user, EntityManager $entityManager, JoinHelper $joinHelper)
@@ -186,7 +195,7 @@ class InFolder implements ItemConverter
protected function getEmailAddressIdList(): array
{
$emailAddressList = $this->entityManager
->getRepository('User')
->getRDBRepository('User')
->getRelation($this->user, 'emailAddresses')
->select(['id'])
->find();
@@ -194,7 +203,7 @@ class InFolder implements ItemConverter
$emailAddressIdList = [];
foreach ($emailAddressList as $emailAddress) {
$emailAddressIdList[] = $emailAddress->id;
$emailAddressIdList[] = $emailAddress->getId();
}
return $emailAddressIdList;

View File

@@ -45,8 +45,14 @@ class CampaignTrackOpened implements EntryPoint
{
use NoAuth;
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var Service
*/
protected $service;
public function __construct(EntityManager $entityManager, Service $service)

View File

@@ -30,6 +30,7 @@
namespace Espo\Modules\Crm\EntryPoints;
use Espo\Modules\Crm\Services\Campaign as Service;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use Espo\{
Modules\Crm\Entities\EmailQueueItem,
@@ -54,16 +55,34 @@ class CampaignUrl implements EntryPoint
{
use NoAuth;
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var Service
*/
protected $service;
/**
* @var Hasher
*/
protected $hasher;
/**
* @var HookManager
*/
protected $hookManager;
/**
* @var ClientManager
*/
protected $clientManager;
/**
* @var Metadata
*/
protected $metadata;
public function __construct(
@@ -180,7 +199,7 @@ class CampaignUrl implements EntryPoint
throw new NotFoundSilent();
}
$eaRepository = $this->entityManager->getRepository('EmailAddress');
$eaRepository = $this->getEmailAddressRepository();
$ea = $eaRepository->getByAddress($emailAddress);
@@ -229,4 +248,10 @@ class CampaignUrl implements EntryPoint
$this->clientManager->display($runScript);
}
private function getEmailAddressRepository(): EmailAddressRepository
{
/** @var EmailAddressRepository */
return $this->entityManager->getRepository('EmailAddress');
}
}

View File

@@ -46,10 +46,19 @@ class EventConfirmation implements EntryPoint
{
use NoAuth;
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var ClientManager
*/
protected $clientManager;
/**
* @var HookManager
*/
protected $hookManager;
public function __construct(EntityManager $entityManager, ClientManager $clientManager, HookManager $hookManager) {
@@ -71,7 +80,10 @@ class EventConfirmation implements EntryPoint
throw new BadRequest();
}
$uniqueId = $this->entityManager->getRepository('UniqueId')->where(['name' => $uid])->findOne();
$uniqueId = $this->entityManager
->getRDBRepository('UniqueId')
->where(['name' => $uid])
->findOne();
if (!$uniqueId) {
throw new NotFound();
@@ -111,18 +123,21 @@ class EventConfirmation implements EntryPoint
$data = (object) [
'status' => $status
];
$this->entityManager->getRepository($eventType)->updateRelation($event, $link, $invitee->id, $data);
$this->entityManager
->getRDBRepository($eventType)
->updateRelation($event, $link, $invitee->getId(), $data);
$actionData = [
'eventName' => $event->get('name'),
'eventType' => $event->getEntityType(),
'eventId' => $event->id,
'eventId' => $event->getId(),
'dateStart' => $event->get('dateStart'),
'action' => $action,
'status' => $status,
'link' => $link,
'inviteeType' => $invitee->getEntityType(),
'inviteeId' => $invitee->id
'inviteeId' => $invitee->getId(),
];
$this->hookManager->process($event->getEntityType(), $hookMethodName, $event, [], $actionData);

View File

@@ -29,6 +29,8 @@
namespace Espo\Modules\Crm\EntryPoints;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use Espo\Core\{
Exceptions\NotFound,
Exceptions\BadRequest,
@@ -48,16 +50,34 @@ class SubscribeAgain implements EntryPoint
{
use NoAuth;
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var ClientManager
*/
protected $clientManager;
/**
* @var HookManager
*/
protected $hookManager;
/**
* @var Config
*/
protected $config;
/**
* @var Metadata
*/
protected $metadata;
/**
* @var Hasher
*/
protected $hasher;
public function __construct(
@@ -131,7 +151,7 @@ class SubscribeAgain implements EntryPoint
$emailAddress = $target->get('emailAddress');
if ($emailAddress) {
$ea = $this->entityManager->getRepository('EmailAddress')->getByAddress($emailAddress);
$ea = $this->getEmailAddressRepository()->getByAddress($emailAddress);
if ($ea) {
$ea->set('optOut', false);
@@ -155,14 +175,14 @@ class SubscribeAgain implements EntryPoint
if ($link) {
$targetListList = $this->entityManager
->getRepository('MassEmail')
->getRDBRepository('MassEmail')
->getRelation($massEmail, 'targetLists')
->find();
foreach ($targetListList as $targetList) {
$optedInResult = $this->entityManager
->getRepository('TargetList')
->updateRelation($targetList, $link, $target->id, ['optedOut' => false]);
->getRDBRepository('TargetList')
->updateRelation($targetList, $link, $target->getId(), ['optedOut' => false]);
if ($optedInResult) {
$hookData = [
@@ -171,7 +191,8 @@ class SubscribeAgain implements EntryPoint
'targetType' => $targetType,
];
$this->hookManager->process('TargetList', 'afterCancelOptOut', $targetList, [], $hookData);
$this->hookManager
->process('TargetList', 'afterCancelOptOut', $targetList, [], $hookData);
}
}
@@ -185,7 +206,7 @@ class SubscribeAgain implements EntryPoint
if ($campaign && $target) {
$logRecord = $this->entityManager
->getRepository('CampaignLogRecord')->where([
->getRDBRepository('CampaignLogRecord')->where([
'queueItemId' => $queueItemId,
'action' => 'Opted Out',
])
@@ -225,11 +246,12 @@ class SubscribeAgain implements EntryPoint
throw new NotFound();
}
$repository = $this->entityManager->getRepository('EmailAddress');
$repository = $this->getEmailAddressRepository();
$ea = $repository->getByAddress($emailAddress);
if ($ea) {
$entityList = $repository->getEntityListByAddressId($ea->id);
$entityList = $repository->getEntityListByAddressId($ea->getId());
if ($ea->get('optOut')) {
$ea->set('optOut', false);
@@ -250,4 +272,10 @@ class SubscribeAgain implements EntryPoint
throw new NotFound();
}
}
private function getEmailAddressRepository(): EmailAddressRepository
{
/** @var EmailAddressRepository */
return $this->entityManager->getRepository('EmailAddress');
}
}

View File

@@ -30,6 +30,7 @@
namespace Espo\Modules\Crm\EntryPoints;
use Espo\Modules\Crm\Services\Campaign as Service;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use Espo\Core\{
Exceptions\NotFound,
@@ -50,18 +51,39 @@ class Unsubscribe implements EntryPoint
{
use NoAuth;
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var ClientManager
*/
protected $clientManager;
/**
* @var HookManager
*/
protected $hookManager;
/**
* @var Config
*/
protected $config;
/**
* @var Metadata
*/
protected $metadata;
/**
* @var Hasher
*/
protected $hasher;
/**
* @var Service
*/
protected $service;
public function __construct(
@@ -137,7 +159,7 @@ class Unsubscribe implements EntryPoint
$emailAddress = $target->get('emailAddress');
if ($emailAddress) {
$ea = $this->entityManager->getRepository('EmailAddress')->getByAddress($emailAddress);
$ea = $this->getEmailAddressRepository()->getByAddress($emailAddress);
if ($ea) {
$ea->set('optOut', true);
@@ -161,14 +183,14 @@ class Unsubscribe implements EntryPoint
if ($link) {
$targetListList = $this->entityManager
->getRepository('MassEmail')
->getRDBRepository('MassEmail')
->getRelation($massEmail, 'targetLists')
->find();
foreach ($targetListList as $targetList) {
$optedOutResult = $this->entityManager
->getRepository('TargetList')
->updateRelation($targetList, $link, $target->id, ['optedOut' => true]);
->getRDBRepository('TargetList')
->updateRelation($targetList, $link, $target->getId(), ['optedOut' => true]);
if ($optedOutResult) {
$hookData = [
@@ -228,7 +250,7 @@ class Unsubscribe implements EntryPoint
throw new NotFound();
}
$repository = $this->entityManager->getRepository('EmailAddress');
$repository = $this->getEmailAddressRepository();
$ea = $repository->getByAddress($emailAddress);
@@ -253,4 +275,10 @@ class Unsubscribe implements EntryPoint
throw new NotFound();
}
}
private function getEmailAddressRepository(): EmailAddressRepository
{
/** @var EmailAddressRepository */
return $this->entityManager->getRepository('EmailAddress');
}
}

View File

@@ -55,6 +55,9 @@ class Preferences implements Repository,
use Di\ConfigSetter;
use Di\EntityManagerSetter;
/**
* @var EntityFactory
*/
protected $entityFactory;
public function __construct(
@@ -76,6 +79,7 @@ class Preferences implements Repository,
public function getNew(): Entity
{
/** @var PreferencesEntity */
return $this->entityFactory->create('Preferences');
}