decoupling

This commit is contained in:
Yuri Kuznetsov
2020-06-23 16:14:11 +03:00
parent 771acbea35
commit 7bcb6a320e
21 changed files with 575 additions and 224 deletions

View File

@@ -34,6 +34,8 @@ use Espo\Core\Exceptions\NotFound;
use Espo\Core\{
InjectableFactory,
Utils\ClassFinder,
EntryPoints\NotStrictAuth,
EntryPoints\NoAuth,
};
class EntryPointManager
@@ -52,7 +54,14 @@ class EntryPointManager
if (!$className) {
throw new NotFound();
}
return $className::$authRequired;
$class = new \ReflectionClass($className);
if ($class->implementsInterface(NoAuth::class)) {
return false;
}
return $className::$authRequired ?? true;
}
public function checkNotStrictAuth(string $name) : bool
@@ -61,7 +70,14 @@ class EntryPointManager
if (!$className) {
throw new NotFound();
}
return $className::$notStrictAuth;
$class = new \ReflectionClass($className);
if ($class->implementsInterface(NotStrictAuth::class)) {
return true;
}
return $className::$notStrictAuth ?? false;
}
public function run(string $name, array $data = [])

View File

@@ -29,18 +29,25 @@
namespace Espo\Core\EntryPoints;
use \Espo\Core\Container;
use Espo\Core\Container;
use Espo\Core\EntryPoint;
use \Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\Forbidden;
/** Deprecated */
abstract class Base
{
private $container;
public static $authRequired = true;
public static $notStrictAuth = false;
private $container;
public function __construct(Container $container)
{
$this->container = $container;
}
protected function getContainer()
{
return $this->container;
@@ -100,11 +107,4 @@ abstract class Base
{
return $this->getContainer()->get('clientManager');
}
public function __construct(Container $container)
{
$this->container = $container;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoints;
interface EntryPoint
{
}

View File

@@ -0,0 +1,35 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoints;
interface NoAuth
{
}

View File

@@ -0,0 +1,35 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoints;
interface NotStrictAuth
{
}

View File

@@ -29,13 +29,19 @@
namespace Espo\EntryPoints;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
class Attachment extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\EntryPoint;
use Espo\Core\Di;
class Attachment implements EntryPoint,
Di\EntityManagerAware,
Di\AclAware
{
public static $authRequired = true;
use Di\EntityManagerSetter;
use Di\AclSetter;
protected $allowedFileTypes = [
'image/jpeg',
@@ -51,17 +57,17 @@ class Attachment extends \Espo\Core\EntryPoints\Base
throw new BadRequest();
}
$attachment = $this->getEntityManager()->getEntity('Attachment', $id);
$attachment = $this->entityManager->getEntity('Attachment', $id);
if (!$attachment) {
throw new NotFound();
}
if (!$this->getAcl()->checkEntity($attachment)) {
if (!$this->acl->checkEntity($attachment)) {
throw new Forbidden();
}
$fileName = $this->getEntityManager()->getRepository('Attachment')->getFilePath($attachment);
$fileName = $this->entityManager->getRepository('Attachment')->getFilePath($attachment);
if (!file_exists($fileName)) {
throw new NotFound();

View File

@@ -34,11 +34,13 @@ use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
class Avatar extends Image
{
public static $authRequired = true;
use Espo\Core\EntryPoints\NotStrictAuth;
use Espo\Core\Di;
public static $notStrictAuth = true;
class Avatar extends Image implements NotStrictAuth,
Di\MetadataAware
{
use Di\MetadataSetter;
protected $systemColor = '#a4b5bd';
@@ -63,7 +65,7 @@ class Avatar extends Image
}
$x = intval($sum % 128) + 1;
$colorList = $this->getMetadata()->get(['app', 'avatars', 'colorList']) ?? $this->colorList;
$colorList = $this->metadata->get(['app', 'avatars', 'colorList']) ?? $this->colorList;
$index = intval($x * count($colorList) / 128);
return $colorList[$index];
@@ -77,7 +79,7 @@ class Avatar extends Image
$userId = $_GET['id'];
$user = $this->getEntityManager()->getEntity('User', $userId);
$user = $this->entityManager->getEntity('User', $userId);
if (!$user) {
header('Content-Type: image/png');
$img = imagecreatetruecolor(14, 14);
@@ -113,7 +115,7 @@ class Avatar extends Image
$hash = $userId;
$color = $this->getColor($userId);
if ($hash === 'system') {
$color = $this->getMetadata()->get(['app', 'avatars', 'systemColor']) ?? $this->systemColor;
$color = $this->metadata->get(['app', 'avatars', 'systemColor']) ?? $this->systemColor;
}
$imgContent = $identicon->getImageData($hash, $width, $color);

View File

@@ -29,13 +29,33 @@
namespace Espo\EntryPoints;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
class ChangePassword extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\{
EntryPoint,
NoAuth,
};
use Espo\Core\{
Utils\Config,
Utils\ClientManager,
ORM\EntityManager,
};
class ChangePassword implements EntryPoint, NoAuth
{
public static $authRequired = false;
protected $config;
protected $clientManager;
protected $entityManager;
public function __construct(Config $config, ClientManager $clientManager, EntityManager $entityManager)
{
$this->config = $config;
$this->clientManager = $clientManager;
$this->entityManager = $entityManager;
}
public function run()
{
@@ -43,18 +63,17 @@ class ChangePassword extends \Espo\Core\EntryPoints\Base
if (!$requestId) throw new BadRequest();
$config = $this->getConfig();
$themeManager = $this->getThemeManager();
$config = $this->config;
$request = $this->getEntityManager()->getRepository('PasswordChangeRequest')->where([
'requestId' => $requestId
$request = $this->entityManager->getRepository('PasswordChangeRequest')->where([
'requestId' => $requestId,
])->findOne();
$strengthParams = [
'passwordStrengthLength' => $this->getConfig()->get('passwordStrengthLength'),
'passwordStrengthLetterCount' => $this->getConfig()->get('passwordStrengthLetterCount'),
'passwordStrengthNumberCount' => $this->getConfig()->get('passwordStrengthNumberCount'),
'passwordStrengthBothCases' => $this->getConfig()->get('passwordStrengthBothCases'),
'passwordStrengthLength' => $this->config->get('passwordStrengthLength'),
'passwordStrengthLetterCount' => $this->config->get('passwordStrengthLetterCount'),
'passwordStrengthNumberCount' => $this->config->get('passwordStrengthNumberCount'),
'passwordStrengthBothCases' => $this->config->get('passwordStrengthBothCases'),
];
if (!$request) throw new NotFound();
@@ -70,11 +89,6 @@ class ChangePassword extends \Espo\Core\EntryPoints\Base
});
";
$this->getClientManager()->display($runScript);
}
protected function getThemeManager()
{
return $this->getContainer()->get('themeManager');
$this->clientManager->display($runScript);
}
}

View File

@@ -29,14 +29,31 @@
namespace Espo\EntryPoints;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
class ConfirmOptIn extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\{
EntryPoint,
NoAuth,
};
use Espo\Core\{
Utils\ClientManager,
ServiceFactory,
};
class ConfirmOptIn implements EntryPoint, NoAuth
{
public static $authRequired = false;
protected $clientManager;
protected $serviceFactory;
public function __construct(ClientManager $clientManager, ServiceFactory $serviceFactory)
{
$this->clientManager = $clientManager;
$this->serviceFactory = $serviceFactory;
}
public function run()
{
@@ -44,7 +61,7 @@ class ConfirmOptIn extends \Espo\Core\EntryPoints\Base
$id = $_GET['id'];
$data = $this->getServiceFactory()->create('LeadCapture')->confirmOptIn($id);
$data = $this->serviceFactory->create('LeadCapture')->confirmOptIn($id);
if ($data->status === 'success') {
$action = 'optInConfirmationSuccess';
@@ -62,6 +79,6 @@ class ConfirmOptIn extends \Espo\Core\EntryPoints\Base
});
";
$this->getClientManager()->display($runScript);
$this->clientManager->display($runScript);
}
}

View File

@@ -29,15 +29,23 @@
namespace Espo\EntryPoints;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
class Download extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\{
EntryPoint,
NoAuth,
};
use Espo\Core\{
Acl,
ORM\EntityManager,
};
class Download implements EntryPoint
{
public static $authRequired = true;
protected $fileTypesToShowInline = array(
protected $fileTypesToShowInline = [
'application/pdf',
'application/vnd.ms-word',
'application/vnd.ms-excel',
@@ -45,8 +53,17 @@ class Download extends \Espo\Core\EntryPoints\Base
'application/vnd.oasis.opendocument.spreadsheet',
'text/plain',
'application/msword',
'application/msexcel'
);
'application/msexcel',
];
protected $acl;
protected $entityManager;
public function __construct(Acl $acl, EntityManager $entityManager)
{
$this->acl = $acl;
$this->entityManager = $entityManager;
}
public function run()
{
@@ -55,25 +72,25 @@ class Download extends \Espo\Core\EntryPoints\Base
}
$id = $_GET['id'];
$attachment = $this->getEntityManager()->getEntity('Attachment', $id);
$attachment = $this->entityManager->getEntity('Attachment', $id);
if (!$attachment) {
throw new NotFound();
}
if (!$this->getAcl()->checkEntity($attachment)) {
if (!$this->acl->checkEntity($attachment)) {
throw new Forbidden();
}
$sourceId = $attachment->getSourceId();
if ($this->getEntityManager()->getRepository('Attachment')->hasDownloadUrl($attachment)) {
$downloadUrl = $this->getEntityManager()->getRepository('Attachment')->getDownloadUrl($attachment);
if ($this->entityManager->getRepository('Attachment')->hasDownloadUrl($attachment)) {
$downloadUrl = $this->entityManager->getRepository('Attachment')->getDownloadUrl($attachment);
header('Location: ' . $downloadUrl);
exit;
}
$fileName = $this->getEntityManager()->getRepository('Attachment')->getFilePath($attachment);
$fileName = $this->entityManager->getRepository('Attachment')->getFilePath($attachment);
if (!file_exists($fileName)) {
throw new NotFound();
@@ -103,4 +120,3 @@ class Download extends \Espo\Core\EntryPoints\Base
exit;
}
}

View File

@@ -29,15 +29,23 @@
namespace Espo\EntryPoints;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\NotFoundSilent;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\NotFoundSilent;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
class Image extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\EntryPoint;
use Espo\Core\Di;
class Image implements EntryPoint,
Di\EntityManagerAware,
Di\AclAware,
Di\FileManagerAware
{
public static $authRequired = true;
use Di\EntityManagerSetter;
use Di\AclSetter;
use Di\FileManagerSetter;
protected $allowedFileTypes = [
'image/jpeg',
@@ -82,19 +90,19 @@ class Image extends \Espo\Core\EntryPoints\Base
protected function show($id, $size, $disableAccessCheck = false)
{
$attachment = $this->getEntityManager()->getEntity('Attachment', $id);
$attachment = $this->entityManager->getEntity('Attachment', $id);
if (!$attachment) {
throw new NotFoundSilent();
}
if (!$disableAccessCheck && !$this->getAcl()->checkEntity($attachment)) {
if (!$disableAccessCheck && !$this->acl->checkEntity($attachment)) {
throw new Forbidden();
}
$sourceId = $attachment->getSourceId();
$filePath = $this->getEntityManager()->getRepository('Attachment')->getFilePath($attachment);
$filePath = $this->entityManager->getRepository('Attachment')->getFilePath($attachment);
$fileType = $attachment->get('type');
@@ -143,7 +151,7 @@ class Image extends \Espo\Core\EntryPoints\Base
$contents = ob_get_contents();
ob_end_clean();
imagedestroy($targetImage);
$this->getContainer()->get('fileManager')->putContents($thumbFilePath, $contents);
$this->fileManager->putContents($thumbFilePath, $contents);
}
$filePath = $thumbFilePath;

View File

@@ -29,14 +29,21 @@
namespace Espo\EntryPoints;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
class LogoImage extends Image
use Espo\Core\EntryPoints\{
NoAuth,
};
use Espo\Core\Di;
class LogoImage extends Image implements NoAuth,
Di\ConfigAware
{
public static $authRequired = false;
use Di\ConfigSetter;
protected $allowedRelatedTypeList = ['Settings', 'Portal'];
@@ -44,12 +51,12 @@ class LogoImage extends Image
public function run()
{
$this->imageSizes['small-logo'] = array(181, 44);
$this->imageSizes['small-logo'] = [181, 44];
if (!empty($_GET['id'])) {
$id = $_GET['id'];
} else {
$id = $this->getConfig()->get('companyLogoId');
$id = $this->config->get('companyLogoId');
}
if (empty($id)) {
@@ -64,4 +71,3 @@ class LogoImage extends Image
$this->show($id, $size);
}
}

View File

@@ -29,16 +29,16 @@
namespace Espo\EntryPoints;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use Espo\Core\EntryPoints\{
EntryPoint,
NoAuth,
};
class OauthCallback extends \Espo\Core\EntryPoints\Base
class OauthCallback implements EntryPoint, NoAuth
{
public static $authRequired = false;
public function run()
{
echo "EspoCRM rocks! If this window is not closed automatically, it's probable that URL you use to access EspoCRM doesn't match URL specified at Administration > Settings > Site URL.";
echo "EspoCRM rocks! If this window is not closed automatically, it's probable that URL you use to access ".
"EspoCRM doesn't match URL specified at Administration > Settings > Site URL.";
}
}

View File

@@ -29,17 +29,31 @@
namespace Espo\EntryPoints;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\BadRequest;
class Pdf extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\{
EntryPoint,
};
use Espo\Core\{
ORM\EntityManager,
ServiceFactory,
};
class Pdf implements EntryPoint
{
public static $authRequired = true;
protected $entityManager;
protected $serviceFactory;
public function __construct(EntityManager $entityManager, ServiceFactory $serviceFactory)
{
$this->entityManager = $entityManager;
$this->serviceFactory = $serviceFactory;
}
public function run()
{
if (empty($_GET['entityId']) || empty($_GET['entityType']) || empty($_GET['templateId'])) {
throw new BadRequest();
}
@@ -47,16 +61,15 @@ class Pdf extends \Espo\Core\EntryPoints\Base
$entityType = $_GET['entityType'];
$templateId = $_GET['templateId'];
$entity = $this->getEntityManager()->getEntity($entityType, $entityId);
$template = $this->getEntityManager()->getEntity('Template', $templateId);
$entity = $this->entityManager->getEntity($entityType, $entityId);
$template = $this->entityManager->getEntity('Template', $templateId);
if (!$entity || !$template) {
throw new NotFound();
}
$this->getContainer()->get('serviceFactory')->create('Pdf')->buildFromTemplate($entity, $template, true);
$this->serviceFactory->create('Pdf')->buildFromTemplate($entity, $template, true);
exit;
}
}

View File

@@ -29,15 +29,31 @@
namespace Espo\EntryPoints;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\NotFound;
class Portal extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\{
EntryPoint,
NoAuth,
};
use Espo\Core\{
Utils\ClientManager,
Utils\Config,
Portal\Application as PortalApplication,
};
class Portal implements EntryPoint, NoAuth
{
public static $authRequired = false;
protected $clientManager;
protected $config;
public function run($data = array())
public function __construct(ClientManager $clientManager, Config $config)
{
$this->clientManager = $clientManager;
$this->config = $config;
}
public function run($data = [])
{
if (!empty($_GET['id'])) {
$id = $_GET['id'];
@@ -53,15 +69,15 @@ class Portal extends \Espo\Core\EntryPoints\Base
}
if (!$id) {
$id = $this->getConfig()->get('defaultPortalId');
$id = $this->config->get('defaultPortalId');
}
if (!$id) {
throw new NotFound();
}
}
$application = new \Espo\Core\Portal\Application($id);
$application->setBasePath($this->getContainer()->get('clientManager')->getBasePath());
$application = new PortalApplication($id);
$application->setBasePath($this->clientManager->getBasePath());
$application->runClient();
}
}

View File

@@ -29,16 +29,33 @@
namespace Espo\Modules\Crm\EntryPoints;
use \Espo\Core\Utils\Util;
use Espo\Core\Utils\Util;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
class CampaignTrackOpened extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\{
EntryPoint,
NoAuth,
};
use Espo\Core\{
ORM\EntityManager,
ServiceFactory,
};
class CampaignTrackOpened implements EntryPoint, NoAuth
{
public static $authRequired = false;
protected $entityManager;
protected $serviceFactory;
public function __construct(EntityManager $entityManager, ServiceFactory $serviceFactory)
{
$this->entityManager = $entityManager;
$this->serviceFactory = $serviceFactory;
}
public function run()
{
@@ -48,7 +65,7 @@ class CampaignTrackOpened extends \Espo\Core\EntryPoints\Base
$queueItemId = $_GET['id'];
$queueItem = $this->getEntityManager()->getEntity('EmailQueueItem', $queueItemId);
$queueItem = $this->entityManager->getEntity('EmailQueueItem', $queueItemId);
if (!$queueItem) {
throw new NotFound();
@@ -61,25 +78,25 @@ class CampaignTrackOpened extends \Espo\Core\EntryPoints\Base
$targetId = $queueItem->get('targetId');
if ($targetType && $targetId) {
$target = $this->getEntityManager()->getEntity($targetType, $targetId);
$target = $this->entityManager->getEntity($targetType, $targetId);
}
$massEmailId = $queueItem->get('massEmailId');
if (!$massEmailId) return;
$massEmail = $this->getEntityManager()->getEntity('MassEmail', $massEmailId);
$massEmail = $this->entityManager->getEntity('MassEmail', $massEmailId);
if (!$massEmail) return;
$campaignId = $massEmail->get('campaignId');
if (!$campaignId) return;
$campaign = $this->getEntityManager()->getEntity('Campaign', $campaignId);
$campaign = $this->entityManager->getEntity('Campaign', $campaignId);
if (!$campaign) return;
if (!$target) {
return;
}
$campaignService = $this->getServiceFactory()->create('Campaign');
$campaignService = $this->serviceFactory->create('Campaign');
$campaignService->logOpened($campaignId, $queueItemId, $target, null, $queueItem->get('isTest'));
header('Content-Type: image/png');
@@ -94,4 +111,3 @@ class CampaignTrackOpened extends \Espo\Core\EntryPoints\Base
imagedestroy($img);
}
}

View File

@@ -34,13 +34,43 @@ use Espo\Core\Exceptions;
use Espo\Modules\Crm\Entities\EmailQueueItem;
use Espo\Modules\Crm\Entities\CampaignTrackingUrl;
class CampaignUrl extends \Espo\Core\EntryPoints\Base
{
public static $authRequired = false;
use Espo\Core\EntryPoints\{
EntryPoint,
NoAuth,
};
protected function getHookManager()
{
return $this->getContainer()->get('hookManager');
use Espo\Core\{
ORM\EntityManager,
ServiceFactory,
Utils\Hasher,
HookManager,
Utils\ClientManager,
Utils\Metadata,
};
class CampaignUrl implements EntryPoint, NoAuth
{
protected $entityManager;
protected $serviceFactory;
protected $hasher;
protected $hookManager;
protected $clientManager;
protected $metadata;
public function __construct(
EntityManager $entityManager,
ServiceFactory $serviceFactory,
Hasher $hasher,
HookManager $hookManager,
ClientManager $clientManager,
Metadata $metadata
) {
$this->entityManager = $entityManager;
$this->serviceFactory = $serviceFactory;
$this->hasher = $hasher;
$this->hookManager = $hookManager;
$this->clientManager = $clientManager;
$this->metadata = $metadata;
}
public function run()
@@ -51,14 +81,14 @@ class CampaignUrl extends \Espo\Core\EntryPoints\Base
$hash = $_GET['hash'] ?? null;
if (!$trackingUrlId) throw new Exceptions\BadRequest();
$trackingUrl = $this->getEntityManager()->getEntity('CampaignTrackingUrl', $trackingUrlId);
$trackingUrl = $this->entityManager->getEntity('CampaignTrackingUrl', $trackingUrlId);
if (!$trackingUrl) throw new Exceptions\NotFound();
if ($emailAddress && $hash) {
$this->processWithHash($trackingUrl, $emailAddress, $hash);
} else {
if (!$queueItemId) throw new Exceptions\BadRequest();
$queueItem = $this->getEntityManager()->getEntity('EmailQueueItem', $queueItemId);
$queueItem = $this->entityManager->getEntity('EmailQueueItem', $queueItemId);
if (!$queueItem) throw new Exceptions\NotFound();
$this->processWithQueueItem($trackingUrl, $queueItem);
@@ -85,36 +115,36 @@ class CampaignUrl extends \Espo\Core\EntryPoints\Base
$targetId = $queueItem->get('targetId');
if ($targetType && $targetId) {
$target = $this->getEntityManager()->getEntity($targetType, $targetId);
$target = $this->entityManager->getEntity($targetType, $targetId);
}
$campaignId = $trackingUrl->get('campaignId');
if ($campaignId) {
$campaign = $this->getEntityManager()->getEntity('Campaign', $campaignId);
$campaign = $this->entityManager->getEntity('Campaign', $campaignId);
}
if ($target) {
$this->getHookManager()->process('CampaignTrackingUrl', 'afterClick', $trackingUrl, [], [
$this->hookManager->process('CampaignTrackingUrl', 'afterClick', $trackingUrl, [], [
'targetId' => $targetId,
'targetType' => $targetType,
]);
}
if ($campaign && $target) {
$campaignService = $this->getServiceFactory()->create('Campaign');
$campaignService = $this->serviceFactory->create('Campaign');
$campaignService->logClicked($campaignId, $queueItem->id, $target, $trackingUrl, null, $queueItem->get('isTest'));
}
}
protected function processWithHash(CampaignTrackingUrl $trackingUrl, string $emailAddress, string $hash)
{
$hash2 = $this->getContainer()->get('hasher')->hash($emailAddress);
$hash2 = $this->hasher->hash($emailAddress);
if ($hash2 !== $hash) {
throw new Exceptions\NotFound();
}
$eaRepository = $this->getEntityManager()->getRepository('EmailAddress');
$eaRepository = $this->entityManager->getRepository('EmailAddress');
$ea = $eaRepository->getByAddress($emailAddress);
if (!$ea) {
@@ -124,7 +154,7 @@ class CampaignUrl extends \Espo\Core\EntryPoints\Base
$entityList = $eaRepository->getEntityListByAddressId($ea->id);
foreach ($entityList as $target) {
$this->getHookManager()->process('CampaignTrackingUrl', 'afterClick', $trackingUrl, [], [
$this->hookManager->process('CampaignTrackingUrl', 'afterClick', $trackingUrl, [], [
'targetId' => $target->id,
'targetType' => $target->getEntityType(),
]);
@@ -137,8 +167,8 @@ class CampaignUrl extends \Espo\Core\EntryPoints\Base
$data = [
'message' => $message,
'view' => $this->getMetadata()->get(['clientDefs', 'Campaign', 'trackinkUrlMessageView']),
'template' => $this->getMetadata()->get(['clientDefs', 'Campaign', 'trackinkUrlMessageTemplate']),
'view' => $this->metadata->get(['clientDefs', 'Campaign', 'trackinkUrlMessageView']),
'template' => $this->metadata->get(['clientDefs', 'Campaign', 'trackinkUrlMessageTemplate']),
];
$runScript = "
@@ -148,6 +178,6 @@ class CampaignUrl extends \Espo\Core\EntryPoints\Base
controller.doAction('displayMessage', ".json_encode($data).");
});
";
$this->getClientManager()->display($runScript);
$this->clientManager->display($runScript);
}
}

View File

@@ -25,34 +25,54 @@
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
************************************************************************/
namespace Espo\Modules\Crm\EntryPoints;
use \Espo\Core\Utils\Util;
use Espo\Core\Utils\Util;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
class EventConfirmation extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\{
EntryPoint,
NoAuth,
};
use Espo\Core\{
ORM\EntityManager,
Utils\ClientManager,
HookManager,
};
class EventConfirmation implements EntryPoint, NoAuth
{
public static $authRequired = false;
protected $entityManager;
protected $clientManager;
protected $hookManager;
public function __construct(EntityManager $entityManager, ClientManager $clientManager, HookManager $hookManager) {
$this->entityManager = $entityManager;
$this->clientManager = $clientManager;
$this->hookManager = $hookManager;
}
public function run()
{
$uid = $_GET['uid'];
$action = $_GET['action'];
$uid = $_GET['uid'] ?? null;
$action = $_GET['action'] ?? null;
if (empty($uid) || empty($action)) {
throw new BadRequest();
}
if (!in_array($action, array('accept', 'decline', 'tentative'))) {
if (!in_array($action, ['accept', 'decline', 'tentative'])) {
throw new BadRequest();
}
$uniqueId = $this->getEntityManager()->getRepository('UniqueId')->where(array('name' => $uid))->findOne();
$uniqueId = $this->entityManager->getRepository('UniqueId')->where(['name' => $uid])->findOne();
if (!$uniqueId) {
throw new NotFound();
@@ -67,8 +87,8 @@ class EventConfirmation extends \Espo\Core\EntryPoints\Base
$link = $data->link;
if (!empty($eventType) && !empty($eventId) && !empty($inviteeType) && !empty($inviteeId) && !empty($link)) {
$event = $this->getEntityManager()->getEntity($eventType, $eventId);
$invitee = $this->getEntityManager()->getEntity($inviteeType, $inviteeId);
$event = $this->entityManager->getEntity($eventType, $eventId);
$invitee = $this->entityManager->getEntity($inviteeType, $inviteeId);
if (!$event || !$invitee) {
throw new NotFound();
@@ -91,7 +111,7 @@ class EventConfirmation extends \Espo\Core\EntryPoints\Base
$data = (object) [
'status' => $status
];
$this->getEntityManager()->getRepository($eventType)->updateRelation($event, $link, $invitee->id, $data);
$this->entityManager->getRepository($eventType)->updateRelation($event, $link, $invitee->id, $data);
$actionData = [
'eventName' => $event->get('name'),
@@ -105,7 +125,7 @@ class EventConfirmation extends \Espo\Core\EntryPoints\Base
'inviteeId' => $invitee->id
];
$this->getEntityManager()->getHookManager()->process($event->getEntityType(), $hookMethodName, $event, [], $actionData);
$this->hookManager->process($event->getEntityType(), $hookMethodName, $event, [], $actionData);
$runScript = "
Espo.require('crm:controllers/event-confirmation', function (Controller) {
@@ -115,7 +135,7 @@ class EventConfirmation extends \Espo\Core\EntryPoints\Base
});
";
$this->getClientManager()->display($runScript);
$this->clientManager->display($runScript);
return;
}

View File

@@ -29,20 +29,50 @@
namespace Espo\Modules\Crm\EntryPoints;
use \Espo\Core\Utils\Util;
use Espo\Core\Utils\Util;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
class SubscribeAgain extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\{
EntryPoint,
NoAuth,
};
use Espo\Core\{
ORM\EntityManager,
Utils\ClientManager,
HookManager,
Utils\Config,
Utils\Metadata,
Utils\Hasher,
};
class SubscribeAgain implements EntryPoint, NoAuth
{
public static $authRequired = false;
protected $entityManager;
protected $clientManager;
protected $hookManager;
protected $config;
protected $metadata;
protected $hasher;
protected function getHookManager()
{
return $this->getContainer()->get('hookManager');
public function __construct(
EntityManager $entityManager,
ClientManager $clientManager,
HookManager $hookManager,
Config $config,
Metadata $metadata,
Hasher $hasher
) {
$this->entityManager = $entityManager;
$this->clientManager = $clientManager;
$this->hookManager = $hookManager;
$this->config = $config;
$this->metadata = $metadata;
$this->hasher = $hasher;
}
public function run()
@@ -61,7 +91,7 @@ class SubscribeAgain extends \Espo\Core\EntryPoints\Base
}
$queueItemId = $id;
$queueItem = $this->getEntityManager()->getEntity('EmailQueueItem', $queueItemId);
$queueItem = $this->entityManager->getEntity('EmailQueueItem', $queueItemId);
if (!$queueItem) {
throw new NotFound();
@@ -72,18 +102,18 @@ class SubscribeAgain extends \Espo\Core\EntryPoints\Base
$massEmailId = $queueItem->get('massEmailId');
if ($massEmailId) {
$massEmail = $this->getEntityManager()->getEntity('MassEmail', $massEmailId);
$massEmail = $this->entityManager->getEntity('MassEmail', $massEmailId);
if ($massEmail) {
$campaignId = $massEmail->get('campaignId');
if ($campaignId) {
$campaign = $this->getEntityManager()->getEntity('Campaign', $campaignId);
$campaign = $this->entityManager->getEntity('Campaign', $campaignId);
}
$targetType = $queueItem->get('targetType');
$targetId = $queueItem->get('targetId');
if ($targetType && $targetId) {
$target = $this->getEntityManager()->getEntity($targetType, $targetId);
$target = $this->entityManager->getEntity($targetType, $targetId);
if (!$target) {
throw new NotFound();
@@ -92,10 +122,10 @@ class SubscribeAgain extends \Espo\Core\EntryPoints\Base
if ($massEmail->get('optOutEntirely')) {
$emailAddress = $target->get('emailAddress');
if ($emailAddress) {
$ea = $this->getEntityManager()->getRepository('EmailAddress')->getByAddress($emailAddress);
$ea = $this->entityManager->getRepository('EmailAddress')->getByAddress($emailAddress);
if ($ea) {
$ea->set('optOut', false);
$this->getEntityManager()->saveEntity($ea);
$this->entityManager->saveEntity($ea);
}
}
}
@@ -114,7 +144,7 @@ class SubscribeAgain extends \Espo\Core\EntryPoints\Base
$targetListList = $massEmail->get('targetLists');
foreach ($targetListList as $targetList) {
$optedInResult = $this->getEntityManager()->getRepository('TargetList')->updateRelation($targetList, $link, $target->id, array(
$optedInResult = $this->entityManager->getRepository('TargetList')->updateRelation($targetList, $link, $target->id, array(
'optedOut' => false
));
if ($optedInResult) {
@@ -123,11 +153,11 @@ class SubscribeAgain extends \Espo\Core\EntryPoints\Base
'targetId' => $targetId,
'targetType' => $targetType
];
$this->getHookManager()->process('TargetList', 'afterCancelOptOut', $targetList, [], $hookData);
$this->hookManager->process('TargetList', 'afterCancelOptOut', $targetList, [], $hookData);
}
}
$this->getHookManager()->process($target->getEntityType(), 'afterCancelOptOut', $target, [], []);
$this->hookManager->process($target->getEntityType(), 'afterCancelOptOut', $target, [], []);
$this->display(['queueItemId' => $queueItemId]);
}
@@ -136,13 +166,13 @@ class SubscribeAgain extends \Espo\Core\EntryPoints\Base
}
if ($campaign && $target) {
$logRecord = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array(
$logRecord = $this->entityManager->getRepository('CampaignLogRecord')->where(array(
'queueItemId' => $queueItemId,
'action' => 'Opted Out'
))->order('createdAt', true)->findOne();
if ($logRecord) {
$this->getEntityManager()->removeEntity($logRecord);
$this->entityManager->removeEntity($logRecord);
}
}
@@ -152,8 +182,8 @@ class SubscribeAgain extends \Espo\Core\EntryPoints\Base
{
$data = [
'actionData' => $actionData,
'view' => $this->getMetadata()->get(['clientDefs', 'Campaign', 'subscribeView']),
'template' => $this->getMetadata()->get(['clientDefs', 'Campaign', 'subscribeTemplate']),
'view' => $this->metadata->get(['clientDefs', 'Campaign', 'subscribeView']),
'template' => $this->metadata->get(['clientDefs', 'Campaign', 'subscribeTemplate']),
];
$runScript = "
@@ -163,20 +193,20 @@ class SubscribeAgain extends \Espo\Core\EntryPoints\Base
controller.doAction('subscribeAgain', ".json_encode($data).");
});
";
$this->getClientManager()->display($runScript);
$this->clientManager->display($runScript);
}
protected function processWithHash(string $emailAddress, string $hash)
{
$secretKey = $this->getConfig()->get('hashSecretKey');
$secretKey = $this->config->get('hashSecretKey');
$hash2 = $this->getContainer()->get('hasher')->hash($emailAddress);
$hash2 = $this->hasher->hash($emailAddress);
if ($hash2 !== $hash) {
throw new NotFound();
}
$repository = $this->getEntityManager()->getRepository('EmailAddress');
$repository = $this->entityManager->getRepository('EmailAddress');
$ea = $repository->getByAddress($emailAddress);
if ($ea) {
@@ -184,10 +214,10 @@ class SubscribeAgain extends \Espo\Core\EntryPoints\Base
if ($ea->get('optOut')) {
$ea->set('optOut', false);
$this->getEntityManager()->saveEntity($ea);
$this->entityManager->saveEntity($ea);
foreach ($entityList as $entity) {
$this->getHookManager()->process($entity->getEntityType(), 'afterCancelOptOut', $entity, [], []);
$this->hookManager->process($entity->getEntityType(), 'afterCancelOptOut', $entity, [], []);
}
}

View File

@@ -29,20 +29,54 @@
namespace Espo\Modules\Crm\EntryPoints;
use \Espo\Core\Utils\Util;
use Espo\Core\Utils\Util;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
class Unsubscribe extends \Espo\Core\EntryPoints\Base
use Espo\Core\EntryPoints\{
EntryPoint,
NoAuth,
};
use Espo\Core\{
ORM\EntityManager,
Utils\ClientManager,
HookManager,
Utils\Config,
Utils\Metadata,
Utils\Hasher,
ServiceFactory,
};
class Unsubscribe implements EntryPoint, NoAuth
{
public static $authRequired = false;
protected $entityManager;
protected $clientManager;
protected $hookManager;
protected $config;
protected $metadata;
protected $hasher;
protected $serviceFactory;
protected function getHookManager()
{
return $this->getContainer()->get('hookManager');
public function __construct(
EntityManager $entityManager,
ClientManager $clientManager,
HookManager $hookManager,
Config $config,
Metadata $metadata,
Hasher $hasher,
ServiceFactory $serviceFactory
) {
$this->entityManager = $entityManager;
$this->clientManager = $clientManager;
$this->hookManager = $hookManager;
$this->config = $config;
$this->metadata = $metadata;
$this->hasher = $hasher;
$this->serviceFactory = $serviceFactory;
}
public function run()
@@ -61,7 +95,7 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base
}
$queueItemId = $id;
$queueItem = $this->getEntityManager()->getEntity('EmailQueueItem', $queueItemId);
$queueItem = $this->entityManager->getEntity('EmailQueueItem', $queueItemId);
if (!$queueItem) {
throw new NotFound();
@@ -72,18 +106,18 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base
$massEmailId = $queueItem->get('massEmailId');
if ($massEmailId) {
$massEmail = $this->getEntityManager()->getEntity('MassEmail', $massEmailId);
$massEmail = $this->entityManager->getEntity('MassEmail', $massEmailId);
if ($massEmail) {
$campaignId = $massEmail->get('campaignId');
if ($campaignId) {
$campaign = $this->getEntityManager()->getEntity('Campaign', $campaignId);
$campaign = $this->entityManager->getEntity('Campaign', $campaignId);
}
$targetType = $queueItem->get('targetType');
$targetId = $queueItem->get('targetId');
if ($targetType && $targetId) {
$target = $this->getEntityManager()->getEntity($targetType, $targetId);
$target = $this->entityManager->getEntity($targetType, $targetId);
if (!$target) {
throw new NotFound();
@@ -92,10 +126,10 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base
if ($massEmail->get('optOutEntirely')) {
$emailAddress = $target->get('emailAddress');
if ($emailAddress) {
$ea = $this->getEntityManager()->getRepository('EmailAddress')->getByAddress($emailAddress);
$ea = $this->entityManager->getRepository('EmailAddress')->getByAddress($emailAddress);
if ($ea) {
$ea->set('optOut', true);
$this->getEntityManager()->saveEntity($ea);
$this->entityManager->saveEntity($ea);
}
}
}
@@ -114,7 +148,7 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base
$targetListList = $massEmail->get('targetLists');
foreach ($targetListList as $targetList) {
$optedOutResult = $this->getEntityManager()->getRepository('TargetList')->updateRelation($targetList, $link, $target->id, array(
$optedOutResult = $this->entityManager->getRepository('TargetList')->updateRelation($targetList, $link, $target->id, array(
'optedOut' => true
));
if ($optedOutResult) {
@@ -123,11 +157,11 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base
'targetId' => $targetId,
'targetType' => $targetType
];
$this->getHookManager()->process('TargetList', 'afterOptOut', $targetList, [], $hookData);
$this->hookManager->process('TargetList', 'afterOptOut', $targetList, [], $hookData);
}
}
$this->getHookManager()->process($target->getEntityType(), 'afterOptOut', $target, [], []);
$this->hookManager->process($target->getEntityType(), 'afterOptOut', $target, [], []);
$this->display(['queueItemId' => $queueItemId]);
}
@@ -136,8 +170,10 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base
}
if ($campaign && $target) {
$campaignService = $this->getServiceFactory()->create('Campaign');
$campaignService->logOptedOut($campaignId, $queueItemId, $target, $queueItem->get('emailAddress'), null, $queueItem->get('isTest'));
$campaignService = $this->serviceFactory->create('Campaign');
$campaignService->logOptedOut(
$campaignId, $queueItemId, $target, $queueItem->get('emailAddress'), null, $queueItem->get('isTest')
);
}
}
@@ -145,8 +181,8 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base
{
$data = [
'actionData' => $actionData,
'view' => $this->getMetadata()->get(['clientDefs', 'Campaign', 'unsubscribeView']),
'template' => $this->getMetadata()->get(['clientDefs', 'Campaign', 'unsubscribeTemplate']),
'view' => $this->metadata->get(['clientDefs', 'Campaign', 'unsubscribeView']),
'template' => $this->metadata->get(['clientDefs', 'Campaign', 'unsubscribeTemplate']),
];
$runScript = "
@@ -156,20 +192,20 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base
controller.doAction('unsubscribe', ".json_encode($data).");
});
";
$this->getClientManager()->display($runScript);
$this->clientManager->display($runScript);
}
protected function processWithHash(string $emailAddress, string $hash)
{
$secretKey = $this->getConfig()->get('hashSecretKey');
$secretKey = $this->config->get('hashSecretKey');
$hash2 = $this->getContainer()->get('hasher')->hash($emailAddress);
$hash2 = $this->hasher->hash($emailAddress);
if ($hash2 !== $hash) {
throw new NotFound();
}
$repository = $this->getEntityManager()->getRepository('EmailAddress');
$repository = $this->entityManager->getRepository('EmailAddress');
$ea = $repository->getByAddress($emailAddress);
if ($ea) {
@@ -177,10 +213,10 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base
if (!$ea->get('optOut')) {
$ea->set('optOut', true);
$this->getEntityManager()->saveEntity($ea);
$this->entityManager->saveEntity($ea);
foreach ($entityList as $entity) {
$this->getHookManager()->process($entity->getEntityType(), 'afterOptOut', $entity, [], []);
$this->hookManager->process($entity->getEntityType(), 'afterOptOut', $entity, [], []);
}
}

View File

@@ -55,12 +55,12 @@ class SthCollection implements \IteratorAggregate, ICollection
return $this->entityManager->getQuery();
}
protected function getPdo() : \PDO
protected function getPdo()
{
return $this->entityManager->getPdo();
}
protected function getEntityFactory() : object
protected function getEntityFactory()
{
return $this->entityManager->getEntityFactory();
}