This commit is contained in:
Yuri Kuznetsov
2021-09-30 16:47:53 +03:00
parent be9fd29023
commit b3e5003e0c
12 changed files with 139 additions and 66 deletions

View File

@@ -31,6 +31,8 @@ namespace Espo\Controllers;
use Espo\Core\Exceptions\BadRequest;
use Espo\Services\DashboardTemplate as Service;
use Espo\Core\{
Api\Request,
Controllers\Record,
@@ -55,7 +57,7 @@ class DashboardTemplate extends Record
throw new BadRequest();
}
$this->getServiceFactory()->create('DashboardTemplate')->deployToUsers(
$this->getDashboardTemplateService()->deployToUsers(
$data->id,
$data->userIdList,
!empty($data->append)
@@ -76,7 +78,7 @@ class DashboardTemplate extends Record
throw new BadRequest();
}
$this->getServiceFactory()->create('DashboardTemplate')->deployToTeam(
$this->getDashboardTemplateService()->deployToTeam(
$data->id,
$data->teamId,
!empty($data->append)
@@ -84,4 +86,9 @@ class DashboardTemplate extends Record
return true;
}
private function getDashboardTemplateService(): Service
{
return $this->getRecordService();
}
}

View File

@@ -31,14 +31,27 @@ namespace Espo\Controllers;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Api\Request;
use Espo\Core\{
Controllers\Base,
Api\Request,
};
use Espo\Services\Layout as Service;
class Layout extends Base
use Espo\Entities\User;
class Layout
{
private $user;
private $service;
public function __construct(User $user, Service $service)
{
$this->user = $user;
$this->service = $service;
}
/**
* @return mixed
*/
public function getActionRead(Request $request)
{
$params = $request->getRouteParams();
@@ -46,11 +59,12 @@ class Layout extends Base
$scope = $params['scope'] ?? null;
$name = $params['name'] ?? null;
return $this->getServiceFactory()
->create('Layout')
->getForFrontend($scope, $name);
return $this->service->getForFrontend($scope, $name);
}
/**
* @return mixed
*/
public function putActionUpdate(Request $request)
{
$params = $request->getRouteParams();
@@ -69,11 +83,12 @@ class Layout extends Base
$name = $params['name'] ?? null;
$setId = $params['setId'] ?? null;
return $this->getServiceFactory()
->create('Layout')
->update($scope, $name, $setId, $data);
return $this->service->update($scope, $name, $setId, $data);
}
/**
* @return mixed
*/
public function postActionResetToDefault(Request $request)
{
$data = $request->getParsedBody();
@@ -86,23 +101,22 @@ class Layout extends Base
throw new BadRequest();
}
return $this->getServiceFactory()
->create('Layout')
->resetToDefault($data->scope, $data->name, $data->setId ?? null);
return $this->service->resetToDefault($data->scope, $data->name, $data->setId ?? null);
}
/**
* @return mixed
*/
public function getActionGetOriginal(Request $request)
{
if (!$this->user->isAdmin()) {
throw new Forbidden();
}
return $this->getServiceFactory()
->create('Layout')
->getOriginal(
$request->getQueryParam('scope'),
$request->getQueryParam('name'),
$request->getQueryParam('setId')
);
return $this->service->getOriginal(
$request->getQueryParam('scope'),
$request->getQueryParam('name'),
$request->getQueryParam('setId')
);
}
}

View File

@@ -29,6 +29,8 @@
namespace Espo\Controllers;
use Espo\Services\LeadCapture as Service;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\NotFound;
@@ -60,7 +62,7 @@ class LeadCapture extends Record
$response->setHeader('Access-Control-Allow-Origin', $allowOrigin);
$this->getRecordService()->leadCapture($params['apiKey'], $data);
$this->getLeadCaptureService()->leadCapture($params['apiKey'], $data);
return true;
}
@@ -73,11 +75,11 @@ class LeadCapture extends Record
throw new BadRequest('No API key provided.');
}
if (!$this->getRecordService()->isApiKeyValid($params['apiKey'])) {
if (!$this->getLeadCaptureService()->isApiKeyValid($params['apiKey'])) {
throw new NotFound();
}
$allowOrigin = $this->getConfig()->get('leadCaptureAllowOrigin', '*');
$allowOrigin = $this->config->get('leadCaptureAllowOrigin', '*');
$response->setHeader('Access-Control-Allow-Headers', 'Content-Type, Accept');
$response->setHeader('Access-Control-Allow-Origin', $allowOrigin);
@@ -94,7 +96,7 @@ class LeadCapture extends Record
throw new BadRequest();
}
return $this->getRecordService()
return $this->getLeadCaptureService()
->generateNewApiKeyForEntity($data->id)
->getValueMap();
}
@@ -105,8 +107,11 @@ class LeadCapture extends Record
throw new Forbidden();
}
return $this->getServiceFactory()
->create('LeadCapture')
->getSmtpAccountDataList();
return $this->getLeadCaptureService()->getSmtpAccountDataList();
}
private function getLeadCaptureService(): Service
{
return $this->getRecordService();
}
}

View File

@@ -31,20 +31,20 @@ namespace Espo\Controllers;
use Espo\Core\Exceptions\Forbidden;
use Espo\Services\Metadata as Service;
use Espo\Core\{
Controllers\Base,
Api\Request,
};
use StdClass;
use stdClass;
class Metadata extends Base
{
public function getActionRead(): StdClass
public function getActionRead(): stdClass
{
return $this->getServiceFactory()
->create('Metadata')
->getDataForFrontend();
return $this->getMetadataService()->getDataForFrontend();
}
public function getActionGet(Request $request)
@@ -57,4 +57,9 @@ class Metadata extends Base
return $this->metadata->get($key, false);
}
private function getMetadataService(): Service
{
return $this->getServiceFactory()->create('Metadata');
}
}

View File

@@ -29,6 +29,8 @@
namespace Espo\Modules\Crm\Controllers;
use Espo\Modules\Crm\Services\MassEmail as Service;
use Espo\Core\{
Exceptions\BadRequest,
Exceptions\Forbidden,
@@ -46,7 +48,7 @@ class MassEmail extends \Espo\Core\Controllers\Record
throw new BadRequest();
}
$this->getServiceFactory()->create('MassEmail')->processTest($id, $targetList);
$this->getMassEmailService()->processTest($id, $targetList);
return true;
}
@@ -60,6 +62,11 @@ class MassEmail extends \Espo\Core\Controllers\Record
throw new Forbidden();
}
return $this->getServiceFactory()->create('MassEmail')->getSmtpAccountDataList();
return $this->getMassEmailService()->getSmtpAccountDataList();
}
private function getMassEmailService(): Service
{
return $this->getServiceFactory()->create('MassEmail');
}
}

View File

@@ -29,6 +29,8 @@
namespace Espo\Modules\Crm\Services;
use Espo\Services\Pdf as PdfService;
use Espo\ORM\{
Entity,
};
@@ -457,7 +459,7 @@ class Campaign extends \Espo\Services\Record implements
$filename = $campaign->get('name') . ' - ' .
$this->getDefaultLanguage()->translate($targetEntityType, 'scopeNamesPlural');
return $this->getServiceFactory()->create('Pdf')->generateMailMerge(
return $this->getPdfService()->generateMailMerge(
$targetEntityType,
$targetEntityList,
$template,
@@ -470,4 +472,9 @@ class Campaign extends \Espo\Services\Record implements
{
return $this->defaultLanguage;
}
private function getPdfService(): PdfService
{
return $this->injectableFactory->create(PdfService::class);
}
}

View File

@@ -240,8 +240,8 @@ class Lead extends Record implements
$account->set(get_object_vars($recordsData->Account));
if ($duplicateCheck) {
$rDuplicateList = $this->getServiceFactory()
->create('Account')
$rDuplicateList = $this->recordServiceContainer
->get('Account')
->findDuplicates($account, $recordsData->Account);
if ($rDuplicateList) {
@@ -270,8 +270,8 @@ class Lead extends Record implements
}
if ($duplicateCheck) {
$rDuplicateList = $this->getServiceFactory()
->create('Contact')
$rDuplicateList = $this->recordServiceContainer
->get('Contact')
->findDuplicates($contact, $recordsData->Contact);
if ($rDuplicateList) {
@@ -304,8 +304,8 @@ class Lead extends Record implements
}
if ($duplicateCheck) {
$rDuplicateList = $this->getServiceFactory()
->create('Opportunity')
$rDuplicateList = $this->recordServiceContainer
->get('Opportunity')
->findDuplicates($opportunity, $recordsData->Opportunity);
if ($rDuplicateList) {

View File

@@ -32,6 +32,8 @@ namespace Espo\Modules\Crm\Services;
use Espo\ORM\Entity;
use Espo\Modules\Crm\Business\Event\Invitations;
use Espo\Services\Email as EmailService;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Di;
@@ -102,9 +104,7 @@ class Meeting extends \Espo\Services\Record implements
$smtpParams = null;
if ($useUserSmtp) {
$smtpParams = $this->getServiceFactory()
->create('Email')
->getUserSmtpParams($this->getUser()->id);
$smtpParams = $this->getEmailService()->getUserSmtpParams($this->user->getId());
}
return $this->injectableFactory->createWith(Invitations::class, [
@@ -259,4 +259,9 @@ class Meeting extends \Espo\Services\Record implements
return true;
}
private function getEmailService(): EmailService
{
return $this->injectableFactory->create(EmailService::class);
}
}

View File

@@ -31,6 +31,9 @@ namespace Espo\Services;
use Laminas\Mail\Message;
use Espo\Services\EmailAccount as EmailAccountService;
use Espo\Services\InboundEmail as InboundEmailService;
use Espo\{
ORM\Entity,
Entities\User,
@@ -125,7 +128,7 @@ class Email extends Record implements
}
if (!$smtpParams && $fromAddress) {
$emailAccountService = $this->serviceFactory->create('EmailAccount');
$emailAccountService = $this->getEmailAccountService();
$emailAccount = $emailAccountService->findAccountForUser($user, $fromAddress);
@@ -193,7 +196,7 @@ class Email extends Record implements
}
}
$emailAccountService = $this->getServiceFactory()->create('EmailAccount');
$emailAccountService = $this->getEmailAccountService();
$emailAccount = $emailAccountService->findAccountForUser($user, $originalFromAddress);
@@ -219,7 +222,7 @@ class Email extends Record implements
}
if (!$smtpParams) {
$inboundEmailService = $this->getServiceFactory()->create('InboundEmail');
$inboundEmailService = $this->getInboundEmailService();
if ($user) {
$inboundEmail = $inboundEmailService->findSharedAccountForUser($user, $originalFromAddress);
@@ -318,7 +321,8 @@ class Email extends Record implements
if ($inboundEmail->get('storeSentEmails')) {
try {
$inboundEmailService = $this->getServiceFactory()->create('InboundEmail');
$inboundEmailService = $this->getInboundEmailService();
$inboundEmailService->storeSentMessage($inboundEmail, $message);
}
catch (Exception $e) {
@@ -334,7 +338,8 @@ class Email extends Record implements
if ($emailAccount->get('storeSentEmails')) {
try {
$emailAccountService = $this->getServiceFactory()->create('EmailAccount');
$emailAccountService = $this->getEmailAccountService();
$emailAccountService->storeSentMessage($emailAccount, $message);
}
catch (Exception $e) {
@@ -841,7 +846,7 @@ class Email extends Record implements
$emailAccount = $this->entityManager->getEntity('EmailAccount', $id);
if ($emailAccount && $emailAccount->get('smtpHandler')) {
$this->getServiceFactory()->create('EmailAccount')->applySmtpHandler($emailAccount, $smtpParams);
$this->getEmailAccountService()->applySmtpHandler($emailAccount, $smtpParams);
}
}
@@ -849,7 +854,7 @@ class Email extends Record implements
$inboundEmail = $this->entityManager->getEntity('InboundEmail', $id);
if ($inboundEmail && $inboundEmail->get('smtpHandler')) {
$this->getServiceFactory()->create('InboundEmail')->applySmtpHandler($inboundEmail, $smtpParams);
$this->getInboundEmailService()->applySmtpHandler($inboundEmail, $smtpParams);
}
}
@@ -1006,4 +1011,14 @@ class Email extends Record implements
return $replied->getMessageId();
}
private function getEmailAccountService(): EmailAccountService
{
return $this->injectableFactory->create(EmailAccountService::class);
}
private function getInboundEmailService(): InboundEmailService
{
return $this->injectableFactory->create(InboundEmailService::class);
}
}

View File

@@ -600,8 +600,10 @@ class EmailAccount extends Record implements
{
if ($email->get('parentType') && $email->get('parentId')) {
$parent = $this->entityManager->getEntity($email->get('parentType'), $email->get('parentId'));
if ($parent) {
$this->getServiceFactory()->create('Stream')->noteEmailReceived($parent, $email);
$this->getStreamService()->noteEmailReceived($parent, $email);
return;
}
}

View File

@@ -93,8 +93,6 @@ class EmailTemplate extends Record implements
$result = (object) [];
$emailTemplateService = $this->getServiceFactory()->create('EmailTemplate');
$dataList = [];
if ($parentId && $parentType) {
@@ -131,7 +129,7 @@ class EmailTemplate extends Record implements
$entityType = $e->getEntityType();
$recordService = $this->getServiceFactory()->create($entityType);
$recordService = $this->recordServiceContainer->get($entityType);
$recordService->prepareEntityForOutput($e);

View File

@@ -34,6 +34,9 @@ use Laminas\Mail\Message;
use Espo\ORM\Entity;
use Espo\Services\EmailTemplate as EmailTemplateService;
use Espo\Modules\Crm\Services\Campaign as CampaignService;
use Espo\Core\{
Exceptions\Error,
Exceptions\BadRequest,
@@ -549,7 +552,7 @@ class InboundEmail extends RecordService implements
$parent = $this->entityManager->getEntity($email->get('parentType'), $email->get('parentId'));
if ($parent) {
$this->getServiceFactory()->create('Stream')->noteEmailReceived($parent, $email);
$this->getStreamService()->noteEmailReceived($parent, $email);
return;
}
@@ -596,7 +599,7 @@ class InboundEmail extends RecordService implements
$this->processCaseToEmailFields($case, $email);
if (!$email->isFetched()) {
$this->getServiceFactory()->create('Stream')->noteEmailReceived($case, $email);
$this->getStreamService()->noteEmailReceived($case, $email);
}
}
@@ -620,7 +623,7 @@ class InboundEmail extends RecordService implements
$this->processCaseToEmailFields($case, $email);
if (!$email->isFetched()) {
$this->getServiceFactory()->create('Stream')->noteEmailReceived($case, $email);
$this->getStreamService()->noteEmailReceived($case, $email);
}
}
@@ -639,7 +642,7 @@ class InboundEmail extends RecordService implements
$user = $this->entityManager->getEntity('User', $case->get('assignedUserId'));
$this->getServiceFactory()->create('Stream')->noteEmailReceived($case, $email, true);
$this->getStreamService()->noteEmailReceived($case, $email, true);
if ($inboundEmail->get('reply')) {
$this->autoReply($inboundEmail, $email, $case, $user);
@@ -923,7 +926,7 @@ class InboundEmail extends RecordService implements
$entityHash['User'] = $user;
}
$emailTemplateService = $this->getServiceFactory()->create('EmailTemplate');
$emailTemplateService = $this->getEmailTemplateService();
$replyData = $emailTemplateService->parse(
$replyEmailTemplateId,
@@ -1088,10 +1091,10 @@ class InboundEmail extends RecordService implements
return true;
}
protected function getCampaignService()
protected function getCampaignService(): CampaignService
{
if (!$this->campaignService) {
$this->campaignService = $this->getServiceFactory()->create('Campaign');
$this->campaignService = $this->injectableFactory->create(CampaignService::class);
}
return $this->campaignService;
@@ -1100,7 +1103,7 @@ class InboundEmail extends RecordService implements
public function findAccountForSending(string $emailAddress): ?InboundEmailEntity
{
$inboundEmail = $this->entityManager
->getRepository('InboundEmail')
->getRDBRepository('InboundEmail')
->where([
'status' => 'Active',
'useSmtp' => true,
@@ -1344,4 +1347,9 @@ class InboundEmail extends RecordService implements
return false;
}
private function getEmailTemplateService(): EmailTemplateService
{
return $this->injectableFactory->create(EmailTemplateService::class);
}
}