From e35ecf96ca9554329ed543f46200f8eab7dbd940 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Dec 2020 11:19:34 +0200 Subject: [PATCH 01/12] Bump ini from 1.3.5 to 1.3.7 (#1862) Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.7. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.7) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1e6420ea9a..851cfa3348 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1527,9 +1527,9 @@ "dev": true }, "ini": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", + "version": "1.3.7", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.7.tgz", + "integrity": "sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ==", "dev": true }, "interpret": { From 105b494710ba630ea38b89552c60cdf10bf63d65 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 14 Dec 2020 12:49:16 +0200 Subject: [PATCH 02/12] fix binding for php 8 --- .../Espo/Core/Binding/BindingContainer.php | 12 +++++---- .../Core/Binding/BindingContainerTest.php | 27 ++++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/application/Espo/Core/Binding/BindingContainer.php b/application/Espo/Core/Binding/BindingContainer.php index 98a2bebc93..e67cc02ffc 100644 --- a/application/Espo/Core/Binding/BindingContainer.php +++ b/application/Espo/Core/Binding/BindingContainer.php @@ -74,17 +74,19 @@ class BindingContainer return $this->data->getContext($className, $key); } - $dependencyClass = null; + $dependencyClassName = null; - if ($param->getType()) { - $dependencyClass = $param->getClass(); + $type = $param->getType(); + + if ($type && !$type->isBuiltin()) { + $dependencyClassName = $type->getName(); } $key = null; $keyWithParamName = null; - if ($dependencyClass) { - $key = $dependencyClass->getName(); + if ($dependencyClassName) { + $key = $dependencyClassName; if ($key) { $keyWithParamName = $key . ' $' . $param->getName(); diff --git a/tests/unit/Espo/Core/Binding/BindingContainerTest.php b/tests/unit/Espo/Core/Binding/BindingContainerTest.php index df26db7441..6618021438 100644 --- a/tests/unit/Espo/Core/Binding/BindingContainerTest.php +++ b/tests/unit/Espo/Core/Binding/BindingContainerTest.php @@ -39,7 +39,7 @@ use Espo\Core\{ use ReflectionClass; use ReflectionParameter; -use ReflectionType; +use ReflectionNamedType; class BindingContainerTest extends \PHPUnit\Framework\TestCase { @@ -75,17 +75,32 @@ class BindingContainerTest extends \PHPUnit\Framework\TestCase $class = null; + $type = $this->getMockBuilder(ReflectionNamedType::class)->disableOriginalConstructor()->getMock(); + if ($className) { $class = $this->createClassMock($className); - $type = $this->getMockBuilder(ReflectionType::class)->disableOriginalConstructor()->getMock(); - - $param + $type ->expects($this->any()) - ->method('getType') - ->willReturn($type); + ->method('isBuiltin') + ->willReturn(false); + + $type + ->expects($this->any()) + ->method('getName') + ->willReturn($className); } + $type + ->expects($this->any()) + ->method('isBuiltin') + ->willReturn(true); + + $param + ->expects($this->any()) + ->method('getType') + ->willReturn($type); + $param ->expects($this->any()) ->method('getName') From 8a23bba39ad2403708d2c72de72acd3cb70def1c Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 14 Dec 2020 13:01:37 +0200 Subject: [PATCH 03/12] fix authentication param order --- application/Espo/Core/Authentication/Authentication.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/Authentication/Authentication.php b/application/Espo/Core/Authentication/Authentication.php index 5639037489..c09017fdd0 100644 --- a/application/Espo/Core/Authentication/Authentication.php +++ b/application/Espo/Core/Authentication/Authentication.php @@ -84,7 +84,6 @@ class Authentication protected $auth2FAFactory; public function __construct( - bool $allowAnyAccess = false, ApplicationUser $applicationUser, ApplicationState $applicationState, Config $config, @@ -92,7 +91,8 @@ class Authentication EntityManagerProxy $entityManagerProxy, LoginFactory $authLoginFactory, TwoFAFactory $auth2FAFactory, - AuthTokenManager $authTokenManager + AuthTokenManager $authTokenManager, + bool $allowAnyAccess = false ) { $this->allowAnyAccess = $allowAnyAccess; From e19462c045339e0707646d8c52ffb7b7ef8152e8 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 14 Dec 2020 13:10:07 +0200 Subject: [PATCH 04/12] fix query composer notice --- application/Espo/ORM/QueryComposer/BaseQueryComposer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php index 55fd97d6fa..7e2cb09d7d 100644 --- a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php +++ b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php @@ -1085,7 +1085,7 @@ abstract class BaseQueryComposer implements QueryComposer } protected function convertComplexExpression( - ?Entity $entity = null, string $attribute, bool $distinct = false, array &$params + ?Entity $entity = null, string $attribute, bool $distinct, array &$params ) : string { $function = null; From a2be80501a3f5450e5bc67978e37906f41331e00 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 14 Dec 2020 13:15:07 +0200 Subject: [PATCH 05/12] fix query composer notices --- .../Espo/ORM/QueryComposer/BaseQueryComposer.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php index 7e2cb09d7d..a166ffed54 100644 --- a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php +++ b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php @@ -1145,7 +1145,7 @@ abstract class BaseQueryComposer implements QueryComposer } protected function getFunctionArgumentPart( - Entity $entity, string $attribute, bool $distinct = false, array &$params + Entity $entity, string $attribute, bool $distinct, array &$params ) : string { $argument = $attribute; @@ -1767,7 +1767,7 @@ abstract class BaseQueryComposer implements QueryComposer return null; } - protected function getBelongsToJoinsPart(Entity $entity, ?array $select = null, array $skipList = [], array $params) : string + protected function getBelongsToJoinsPart(Entity $entity, ?array $select, array $skipList, array $params) : string { $joinsArr = []; @@ -1939,7 +1939,7 @@ abstract class BaseQueryComposer implements QueryComposer } protected function getAggregationSelectPart( - Entity $entity, string $aggregation, string $aggregationBy, bool $distinct = false, array $params + Entity $entity, string $aggregation, string $aggregationBy, bool $distinct, array $params ) : ?string { if (!isset($entity->getAttributes()[$aggregationBy])) { return null; @@ -2510,7 +2510,7 @@ abstract class BaseQueryComposer implements QueryComposer } protected function getJoinsTypePart( - Entity $entity, array $joins, bool $isLeft = false, $joinConditions = [], array $params + Entity $entity, array $joins, bool $isLeft, $joinConditions, array $params ) : string { $joinSqlList = []; @@ -2556,7 +2556,7 @@ abstract class BaseQueryComposer implements QueryComposer return implode(' ', $joinSqlList); } - protected function buildJoinConditionStatement(Entity $entity, $alias = null, $left, $right, array $params) + protected function buildJoinConditionStatement(Entity $entity, $alias, $left, $right, array $params) { $sql = ''; From 2d26d1a9d1656b848c7c679b5c7ee23a45419fde Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 14 Dec 2020 13:18:23 +0200 Subject: [PATCH 06/12] fix notice --- application/Espo/Modules/Crm/Services/Activities.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/Espo/Modules/Crm/Services/Activities.php b/application/Espo/Modules/Crm/Services/Activities.php index 6968ca6c5d..7f1c52cad3 100644 --- a/application/Espo/Modules/Crm/Services/Activities.php +++ b/application/Espo/Modules/Crm/Services/Activities.php @@ -1349,7 +1349,7 @@ class Activities implements return Select::fromRaw($selectParams); } - protected function getActivitiesSelectParams(Entity $entity, $scope, array $statusList = [], $isHistory) + protected function getActivitiesSelectParams(Entity $entity, $scope, array $statusList, $isHistory) { $selectManager = $this->getSelectManagerFactory()->create($scope); From c65b9d8cc2427c5677ed67487bd219f7742f86a8 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 14 Dec 2020 13:19:50 +0200 Subject: [PATCH 07/12] fix merge notice --- application/Espo/Core/Controllers/Record.php | 10 +++++++++- application/Espo/Services/Record.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/Controllers/Record.php b/application/Espo/Core/Controllers/Record.php index 94d257b57f..0e9319c9be 100644 --- a/application/Espo/Core/Controllers/Record.php +++ b/application/Espo/Core/Controllers/Record.php @@ -43,6 +43,8 @@ use Espo\Core\{ Record\Collection as RecordCollection, }; +use StdClass; + class Record extends Base { const MAX_SIZE_LIMIT = 200; @@ -441,9 +443,15 @@ class Record extends Base throw new BadRequest(); } - if (empty($data->targetId) || empty($data->sourceIds) || !is_array($data->sourceIds) || !($data->attributes instanceof \StdClass)) { + if ( + empty($data->targetId) || + empty($data->sourceIds) || + !is_array($data->sourceIds) || + !($data->attributes instanceof StdClass) + ) { throw new BadRequest(); } + $targetId = $data->targetId; $sourceIds = $data->sourceIds; $attributes = $data->attributes; diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index e4c982eede..b86f16631a 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -2205,7 +2205,7 @@ class Record implements Crud, } } - public function merge($id, array $sourceIdList = [], $attributes) + public function merge(string $id, array $sourceIdList, StdClass $attributes) { if (empty($id)) { throw new Error("No ID passed."); From 9dc050332e9b6a2140674a1f94c72ba7c6ae7c92 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 14 Dec 2020 13:48:25 +0200 Subject: [PATCH 08/12] controller manager notice fix --- application/Espo/Core/ControllerManager.php | 27 ++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/application/Espo/Core/ControllerManager.php b/application/Espo/Core/ControllerManager.php index 5797fde92e..026f1c8773 100644 --- a/application/Espo/Core/ControllerManager.php +++ b/application/Espo/Core/ControllerManager.php @@ -125,18 +125,23 @@ class ControllerManager $params = $method->getParameters(); - if (count($params) > 0) { - $firstParamClass = $params[0]->getClass(); + if (count($params) === 0) { + return false; + } - if ( - $firstParamClass - && - ( - $firstParamClass->getName() === Request::class || $firstParamClass->isSubclassOf(Request::class) - ) - ) { - return true; - } + $type = $params[0]->getType(); + + if (!$type || $type->isBuiltin()) { + return false; + } + + $firstParamClass = new ReflectionClass($type->getName()); + + if ( + $firstParamClass->getName() === Request::class || + $firstParamClass->isSubclassOf(Request::class) + ) { + return true; } return false; From bb10b0a266f2d796b134ecbcb8a99cfa8031f441 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 14 Dec 2020 13:48:32 +0200 Subject: [PATCH 09/12] controller manager test --- .../unit/Espo/Core/ControllerManagerTest.php | 82 +++++++++++++++++++ .../Controllers/TestController.php | 43 ++++++++++ 2 files changed, 125 insertions(+) create mode 100644 tests/unit/Espo/Core/ControllerManagerTest.php create mode 100644 tests/unit/testClasses/Controllers/TestController.php diff --git a/tests/unit/Espo/Core/ControllerManagerTest.php b/tests/unit/Espo/Core/ControllerManagerTest.php new file mode 100644 index 0000000000..8734b408e9 --- /dev/null +++ b/tests/unit/Espo/Core/ControllerManagerTest.php @@ -0,0 +1,82 @@ +classFinder = $this->getMockBuilder(ClassFinder::class)->disableOriginalConstructor()->getMock(); + $this->injectableFactory = $this->getMockBuilder(InjectableFactory::class)->disableOriginalConstructor()->getMock(); + $this->request = $this->getMockBuilder(RequestWrapper::class)->disableOriginalConstructor()->getMock(); + $this->response = $this->getMockBuilder(ResponseWrapper::class)->disableOriginalConstructor()->getMock(); + + $this->controllerManager = new ControllerManager($this->injectableFactory, $this->classFinder); + } + + public function testAction1() + { + $controller = $this->getMockBuilder(TestController::class)->disableOriginalConstructor()->getMock(); + + $this->classFinder + ->expects($this->once()) + ->method('find') + ->with('Controllers', 'Test') + ->willReturn(TestController::class); + + $this->request + ->expects($this->once()) + ->method('getMethod') + ->willReturn('POST'); + + $this->injectableFactory + ->expects($this->once()) + ->method('createWith') + ->with(TestController::class, ['name' => 'Test']) + ->willReturn($controller); + + $controller + ->expects($this->once()) + ->method('postActionHello') + ->with($this->request, $this->response); + + $this->controllerManager->process('Test', 'hello', $this->request, $this->response); + } +} diff --git a/tests/unit/testClasses/Controllers/TestController.php b/tests/unit/testClasses/Controllers/TestController.php new file mode 100644 index 0000000000..2beb657a1b --- /dev/null +++ b/tests/unit/testClasses/Controllers/TestController.php @@ -0,0 +1,43 @@ + Date: Mon, 14 Dec 2020 13:59:25 +0200 Subject: [PATCH 10/12] fix notices --- application/Espo/Services/EmailAccount.php | 14 ++++++++++++-- application/Espo/Services/InboundEmail.php | 22 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/application/Espo/Services/EmailAccount.php b/application/Espo/Services/EmailAccount.php index 914c01db09..c650cc0b99 100644 --- a/application/Espo/Services/EmailAccount.php +++ b/application/Espo/Services/EmailAccount.php @@ -442,7 +442,17 @@ class EmailAccount extends Record implements $flags = $message->getFlags(); } - $email = $this->importMessage($importer, $emailAccount, $message, $teamIdList, null, [$userId], $filterCollection, $fetchOnlyHeader, $folderData); + $email = $this->importMessage( + $importer, + $emailAccount, + $message, + $teamIdList, + null, + [$userId], + $filterCollection, + $fetchOnlyHeader, + $folderData + ); if ($emailAccount->get('keepFetchedEmailsUnread')) { if (is_array($flags) && empty($flags[Storage::FLAG_SEEN])) { @@ -529,7 +539,7 @@ class EmailAccount extends Record implements $emailAccount, $message, $teamIdList, - $userId = null, + $userId, $userIdList = [], $filterCollection, $fetchOnlyHeader, diff --git a/application/Espo/Services/InboundEmail.php b/application/Espo/Services/InboundEmail.php index 9c334d70e0..ea6ee98ce7 100644 --- a/application/Espo/Services/InboundEmail.php +++ b/application/Espo/Services/InboundEmail.php @@ -364,8 +364,15 @@ class InboundEmail extends RecordService implements } $email = $this->importMessage( - $importer, $emailAccount, $message, $teamIdList, $userId, $userIdList, - $filterCollection, $fetchOnlyHeader, null + $importer, + $emailAccount, + $message, + $teamIdList, + $userId, + $userIdList, + $filterCollection, + $fetchOnlyHeader, + null ); if ($emailAccount->get('keepFetchedEmailsUnread')) { @@ -481,8 +488,15 @@ class InboundEmail extends RecordService implements } protected function importMessage( - $importer, $emailAccount, $message, $teamIdList, $userId = null, $userIdList = [], - $filterCollection, $fetchOnlyHeader, $folderData = null + $importer, + $emailAccount, + $message, + $teamIdList, + $userId, + $userIdList, + $filterCollection, + $fetchOnlyHeader, + $folderData = null ) { $email = null; From 58d3929bee20e1dc6d8ff58eacc14d75b3e6162e Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 14 Dec 2020 13:59:52 +0200 Subject: [PATCH 11/12] fix notices and cs --- .../Espo/Modules/Crm/Services/Campaign.php | 293 ++++++++++++------ 1 file changed, 203 insertions(+), 90 deletions(-) diff --git a/application/Espo/Modules/Crm/Services/Campaign.php b/application/Espo/Modules/Crm/Services/Campaign.php index 593addfd5a..fb5d7bd901 100644 --- a/application/Espo/Modules/Crm/Services/Campaign.php +++ b/application/Espo/Modules/Crm/Services/Campaign.php @@ -57,21 +57,30 @@ class Campaign extends \Espo\Services\Record implements { parent::loadAdditionalFields($entity); - $sentCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where([ - 'campaignId' => $entity->id, - 'action' => 'Sent', - 'isTest' => false - ])->count(); + $sentCount = $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'campaignId' => $entity->id, + 'action' => 'Sent', + 'isTest' => false + ]) + ->count(); + if (!$sentCount) { $sentCount = null; } + $entity->set('sentCount', $sentCount); - $openedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where([ - 'campaignId' => $entity->id, - 'action' => 'Opened', - 'isTest' => false - ])->count(); + $openedCount = $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'campaignId' => $entity->id, + 'action' => 'Opened', + 'isTest' => false + ]) + ->count(); + $entity->set('openedCount', $openedCount); $openedPercentage = null; @@ -80,23 +89,27 @@ class Campaign extends \Espo\Services\Record implements } $entity->set('openedPercentage', $openedPercentage); - $clickedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where([ - 'campaignId' => $entity->id, - 'action' => 'Clicked', - 'isTest' => false, - 'id=s' => [ - 'entityType' => 'CampaignLogRecord', - 'selectParams' => [ - 'select' => ['MIN:id'], - 'whereClause' => [ - 'action' => 'Clicked', - 'isTest' => false, - 'campaignId' => $entity->id, + $clickedCount = $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'campaignId' => $entity->id, + 'action' => 'Clicked', + 'isTest' => false, + 'id=s' => [ + 'entityType' => 'CampaignLogRecord', + 'selectParams' => [ + 'select' => ['MIN:id'], + 'whereClause' => [ + 'action' => 'Clicked', + 'isTest' => false, + 'campaignId' => $entity->id, + ], + 'groupBy' => ['queueItemId'], ], - 'groupBy' => ['queueItemId'], ], - ], - ])->count(); + ]) + ->count(); + $entity->set('clickedCount', $clickedCount); $clickedPercentage = null; @@ -105,47 +118,71 @@ class Campaign extends \Espo\Services\Record implements } $entity->set('clickedPercentage', $clickedPercentage); - $optedInCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where([ - 'campaignId' => $entity->id, - 'action' => 'Opted In', - 'isTest' => false - ])->count(); - if (!$optedInCount) $optedInCount = null; + $optedInCount = $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'campaignId' => $entity->id, + 'action' => 'Opted In', + 'isTest' => false, + ]) + ->count(); + + if (!$optedInCount) { + $optedInCount = null; + } + $entity->set('optedInCount', $optedInCount); - $optedOutCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where([ - 'campaignId' => $entity->id, - 'action' => 'Opted Out', - 'isTest' => false - ])->count(); + $optedOutCount = $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'campaignId' => $entity->id, + 'action' => 'Opted Out', + 'isTest' => false, + ]) + ->count(); + $entity->set('optedOutCount', $optedOutCount); $optedOutPercentage = null; + if ($sentCount > 0) { $optedOutPercentage = round($optedOutCount / $sentCount * 100, 2, \PHP_ROUND_HALF_EVEN); } + $entity->set('optedOutPercentage', $optedOutPercentage); - $bouncedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where([ - 'campaignId' => $entity->id, - 'action' => 'Bounced', - 'isTest' => false - ])->count(); + $bouncedCount = $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'campaignId' => $entity->id, + 'action' => 'Bounced', + 'isTest' => false, + ]) + ->count(); + $entity->set('bouncedCount', $bouncedCount); $bouncedPercentage = null; + if ($sentCount && $sentCount > 0) { $bouncedPercentage = round($bouncedCount / $sentCount * 100, 2, \PHP_ROUND_HALF_EVEN); } + $entity->set('bouncedPercentage', $bouncedPercentage); if ($this->getAcl()->check('Lead')) { - $leadCreatedCount = $this->getEntityManager()->getRepository('Lead')->where([ - 'campaignId' => $entity->id - ])->count(); + $leadCreatedCount = $this->getEntityManager() + ->getRepository('Lead') + ->where([ + 'campaignId' => $entity->id, + ]) + ->count(); + if (!$leadCreatedCount) { $leadCreatedCount = null; } + $entity->set('leadCreatedCount', $leadCreatedCount); } @@ -157,24 +194,28 @@ class Campaign extends \Espo\Services\Record implements 'select' => ['SUM:amountConverted'], 'whereClause' => [ 'stage' => 'Closed Won', - 'campaignId' => $entity->id + 'campaignId' => $entity->id, ], - 'groupBy' => ['opportunity.campaignId'] + 'groupBy' => ['opportunity.campaignId'], ]; $sql = $this->getEntityManager()->getQueryComposer()->compose(Select::fromRaw($params)); $pdo = $this->getEntityManager()->getPDO(); $sth = $pdo->prepare($sql); + $sth->execute(); $revenue = null; + if ($row = $sth->fetch(\PDO::FETCH_ASSOC)) { $revenue = floatval($row['SUM:amountConverted']); + if (!$revenue) { $revenue = null; } } + $entity->set('revenue', $revenue); } } @@ -191,7 +232,7 @@ class Campaign extends \Espo\Services\Record implements 'parentId' => $target->id, 'parentType' => $target->getEntityType(), 'action' => 'Lead Created', - 'isTest' => $isTest + 'isTest' => $isTest, ]); $this->getEntityManager()->saveEntity($logRecord); @@ -199,9 +240,9 @@ class Campaign extends \Espo\Services\Record implements public function logSent( string $campaignId, - ?string $queueItemId = null, + ?string $queueItemId, Entity $target, - Entity $emailOrEmailTemplate = null, + Entity $emailOrEmailTemplate, $emailAddress, $actionDate = null, $isTest = false @@ -218,7 +259,7 @@ class Campaign extends \Espo\Services\Record implements 'action' => 'Sent', 'stringData' => $emailAddress, 'queueItemId' => $queueItemId, - 'isTest' => $isTest + 'isTest' => $isTest, ]); if ($emailOrEmailTemplate) { @@ -230,19 +271,35 @@ class Campaign extends \Espo\Services\Record implements $this->getEntityManager()->saveEntity($logRecord); } - public function logBounced($campaignId, $queueItemId = null, Entity $target, $emailAddress, $isHard = false, $actionDate = null, $isTest = false) - { - if ($queueItemId && $this->getEntityManager()->getRepository('CampaignLogRecord')->where([ - 'queueItemId' => $queueItemId, - 'action' => 'Bounced', - 'isTest' => $isTest - ])->findOne()) { + public function logBounced( + $campaignId, + $queueItemId, + Entity $target, + $emailAddress, + $isHard = false, + $actionDate = null, + $isTest = false + ) { + if ( + $queueItemId && + $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'queueItemId' => $queueItemId, + 'action' => 'Bounced', + 'isTest' => $isTest, + ]) + ->findOne() + ) { return; } + if (empty($actionDate)) { $actionDate = date('Y-m-d H:i:s'); } + $logRecord = $this->getEntityManager()->getEntity('CampaignLogRecord'); + $logRecord->set([ 'campaignId' => $campaignId, 'actionDate' => $actionDate, @@ -251,8 +308,9 @@ class Campaign extends \Espo\Services\Record implements 'action' => 'Bounced', 'stringData' => $emailAddress, 'queueItemId' => $queueItemId, - 'isTest' => $isTest + 'isTest' => $isTest, ]); + if ($isHard) { $logRecord->set('stringAdditionalData', 'Hard'); } else { @@ -261,21 +319,38 @@ class Campaign extends \Espo\Services\Record implements $this->getEntityManager()->saveEntity($logRecord); } - public function logOptedIn($campaignId, $queueItemId = null, Entity $target, $emailAddress = null, $actionDate = null, $isTest = false) - { - if ($queueItemId && $this->getEntityManager()->getRepository('CampaignLogRecord')->where([ - 'queueItemId' => $queueItemId, - 'action' => 'Opted In', - 'isTest' => $isTest - ])->findOne()) return; + public function logOptedIn( + $campaignId, + $queueItemId, + Entity $target, + $emailAddress = null, + $actionDate = null, + $isTest = false + ) { + if ( + $queueItemId && + $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'queueItemId' => $queueItemId, + 'action' => 'Opted In', + 'isTest' => $isTest, + ]) + ->findOne() + ) { + return; + } if (empty($actionDate)) { $actionDate = date('Y-m-d H:i:s'); } + if (!$emailAddress) { $emailAddress = $target->get('emailAddress'); } + $logRecord = $this->getEntityManager()->getEntity('CampaignLogRecord'); + $logRecord->set([ 'campaignId' => $campaignId, 'actionDate' => $actionDate, @@ -284,23 +359,38 @@ class Campaign extends \Espo\Services\Record implements 'action' => 'Opted In', 'stringData' => $emailAddress, 'queueItemId' => $queueItemId, - 'isTest' => $isTest + 'isTest' => $isTest, ]); + $this->getEntityManager()->saveEntity($logRecord); } - public function logOptedOut($campaignId, $queueItemId = null, Entity $target, $emailAddress = null, $actionDate = null, $isTest = false) - { - if ($queueItemId && $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array( - 'queueItemId' => $queueItemId, - 'action' => 'Opted Out', - 'isTest' => $isTest - ))->findOne()) { + public function logOptedOut( + $campaignId, + $queueItemId, + Entity $target, + $emailAddress = null, + $actionDate = null, + $isTest = false + ) { + if ( + $queueItemId && + $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'queueItemId' => $queueItemId, + 'action' => 'Opted Out', + 'isTest' => $isTest, + ]) + ->findOne() + ) { return; } + if (empty($actionDate)) { $actionDate = date('Y-m-d H:i:s'); } + $logRecord = $this->getEntityManager()->getEntity('CampaignLogRecord'); $logRecord->set(array( 'campaignId' => $campaignId, @@ -315,22 +405,31 @@ class Campaign extends \Espo\Services\Record implements $this->getEntityManager()->saveEntity($logRecord); } - public function logOpened($campaignId, $queueItemId = null, Entity $target, $actionDate = null, $isTest = false) + public function logOpened($campaignId, $queueItemId, Entity $target, $actionDate = null, $isTest = false) { if (empty($actionDate)) { $actionDate = date('Y-m-d H:i:s'); } - if ($queueItemId && $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array( - 'queueItemId' => $queueItemId, - 'action' => 'Opened', - 'isTest' => $isTest - ))->findOne()) { + if ( + $queueItemId && + $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'queueItemId' => $queueItemId, + 'action' => 'Opened', + 'isTest' => $isTest, + ]) + ->findOne() + ) { return; } + $queueItem = $this->getEntityManager()->getEntity('EmailQueueItem', $queueItemId); + if ($queueItem) { $massEmail = $this->getEntityManager()->getEntity('MassEmail', $queueItem->get('massEmailId')); + if ($massEmail && $massEmail->id) { $logRecord = $this->getEntityManager()->getEntity('CampaignLogRecord'); $logRecord->set([ @@ -342,28 +441,42 @@ class Campaign extends \Espo\Services\Record implements 'objectId' => $massEmail->get('emailTemplateId'), 'objectType' => 'EmailTemplate', 'queueItemId' => $queueItemId, - 'isTest' => $isTest + 'isTest' => $isTest, ]); + $this->getEntityManager()->saveEntity($logRecord); } } } - public function logClicked($campaignId, $queueItemId = null, Entity $target, Entity $trackingUrl, $actionDate = null, $isTest = false) - { + public function logClicked( + $campaignId, + $queueItemId, + Entity $target, + Entity $trackingUrl, + $actionDate = null, + $isTest = false + ) { if ($this->getConfig()->get('massEmailOpenTracking')) { $this->logOpened($campaignId, $queueItemId, $target); } - if ($queueItemId && $this->getEntityManager()->getRepository('CampaignLogRecord')->where([ - 'queueItemId' => $queueItemId, - 'action' => 'Clicked', - 'objectId' => $trackingUrl->id, - 'objectType' => $trackingUrl->getEntityType(), - 'isTest' => $isTest - ])->findOne()) { + if ( + $queueItemId && + $this->getEntityManager() + ->getRepository('CampaignLogRecord') + ->where([ + 'queueItemId' => $queueItemId, + 'action' => 'Clicked', + 'objectId' => $trackingUrl->id, + 'objectType' => $trackingUrl->getEntityType(), + 'isTest' => $isTest, + ]) + ->findOne() + ) { return; } + if (empty($actionDate)) { $actionDate = date('Y-m-d H:i:s'); } @@ -378,7 +491,7 @@ class Campaign extends \Espo\Services\Record implements 'objectId' => $trackingUrl->id, 'objectType' => $trackingUrl->getEntityType(), 'queueItemId' => $queueItemId, - 'isTest' => $isTest + 'isTest' => $isTest, ]); $this->getEntityManager()->saveEntity($logRecord); } From 4ab0d765e33c531555cc62f3409f530b6f5fde20 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 14 Dec 2020 14:52:18 +0200 Subject: [PATCH 12/12] fix notices --- application/Espo/Core/ExternalAccount/OAuth2/Client.php | 2 +- application/Espo/Services/EmailAccount.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/ExternalAccount/OAuth2/Client.php b/application/Espo/Core/ExternalAccount/OAuth2/Client.php index 618f411ffc..a954321260 100644 --- a/application/Espo/Core/ExternalAccount/OAuth2/Client.php +++ b/application/Espo/Core/ExternalAccount/OAuth2/Client.php @@ -155,7 +155,7 @@ class Client return $this->execute($url, $params, $httpMethod, $httpHeaders); } - private function execute($url, $params = null, $httpMethod, array $httpHeaders = []) + private function execute($url, $params, $httpMethod, array $httpHeaders = []) { $curlOptions = array( CURLOPT_RETURNTRANSFER => true, diff --git a/application/Espo/Services/EmailAccount.php b/application/Espo/Services/EmailAccount.php index c650cc0b99..b0c0d36b15 100644 --- a/application/Espo/Services/EmailAccount.php +++ b/application/Espo/Services/EmailAccount.php @@ -540,7 +540,7 @@ class EmailAccount extends Record implements $message, $teamIdList, $userId, - $userIdList = [], + $userIdList, $filterCollection, $fetchOnlyHeader, $folderData = null