From b466f91f8a7a79cac650831e46c7ecc0e0eb54ef Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 5 Nov 2021 11:31:49 +0200 Subject: [PATCH] fixes --- .../Espo/Modules/Crm/Services/Activities.php | 10 ++++------ .../Espo/Modules/Crm/Services/Campaign.php | 4 +++- .../Crm/Services/KnowledgeBaseArticle.php | 4 ++-- .../Espo/Modules/Crm/Services/Lead.php | 19 ++++++++++--------- .../Espo/Modules/Crm/Services/Opportunity.php | 16 +++++++--------- .../Espo/Modules/Crm/Services/TargetList.php | 2 +- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/application/Espo/Modules/Crm/Services/Activities.php b/application/Espo/Modules/Crm/Services/Activities.php index 50e032bcae..a8c86a7ac8 100644 --- a/application/Espo/Modules/Crm/Services/Activities.php +++ b/application/Espo/Modules/Crm/Services/Activities.php @@ -820,7 +820,7 @@ class Activities implements $unionBuilder->query($subQuery); } - if ($order && count($order)) { + if ($order !== null && count($order)) { $unionBuilder->order( $order[0]->getExpression()->getValue(), $order[0]->getDirection() @@ -1712,11 +1712,9 @@ class Activities implements continue; } - $subItem = $this->getCalendarQuery($scope, $userId, $from, $to, $skipAcl); - - if (!is_array($subItem)) { - $subItem = [$subItem]; - } + $subItem = [ + $this->getCalendarQuery($scope, $userId, $from, $to, $skipAcl) + ]; $queryList = array_merge($queryList, $subItem); } diff --git a/application/Espo/Modules/Crm/Services/Campaign.php b/application/Espo/Modules/Crm/Services/Campaign.php index 3783e694ed..0a2d5ab779 100644 --- a/application/Espo/Modules/Crm/Services/Campaign.php +++ b/application/Espo/Modules/Crm/Services/Campaign.php @@ -77,7 +77,7 @@ class Campaign extends \Espo\Services\Record implements string $campaignId, ?string $queueItemId, Entity $target, - Entity $emailOrEmailTemplate, + ?Entity $emailOrEmailTemplate, $emailAddress, $actionDate = null, $isTest = false @@ -87,6 +87,7 @@ class Campaign extends \Espo\Services\Record implements } $logRecord = $this->getEntityManager()->getEntity('CampaignLogRecord'); + $logRecord->set([ 'campaignId' => $campaignId, 'actionDate' => $actionDate, @@ -104,6 +105,7 @@ class Campaign extends \Espo\Services\Record implements 'objectType' => $emailOrEmailTemplate->getEntityType() ]); } + $this->getEntityManager()->saveEntity($logRecord); } diff --git a/application/Espo/Modules/Crm/Services/KnowledgeBaseArticle.php b/application/Espo/Modules/Crm/Services/KnowledgeBaseArticle.php index 2a0431d747..a656cfef96 100644 --- a/application/Espo/Modules/Crm/Services/KnowledgeBaseArticle.php +++ b/application/Espo/Modules/Crm/Services/KnowledgeBaseArticle.php @@ -75,7 +75,7 @@ class KnowledgeBaseArticle extends \Espo\Services\Record implements throw new BadRequest(); } - /** @var KnowledgeBaseArticleEntity $entity */ + /** @var KnowledgeBaseArticleEntity|null $entity */ $entity = $this->getEntityManager()->getEntity('KnowledgeBaseArticle', $id); if (!$entity) { @@ -91,7 +91,7 @@ class KnowledgeBaseArticle extends \Espo\Services\Record implements $attachmentsIds = $entity->get('attachmentsIds'); foreach ($attachmentsIds as $attachmentId) { - /** @var Attachment $source */ + /** @var Attachment|null $source */ $source = $this->getEntityManager()->getEntity('Attachment', $attachmentId); if ($source) { diff --git a/application/Espo/Modules/Crm/Services/Lead.php b/application/Espo/Modules/Crm/Services/Lead.php index 5b37fa6e6a..684cfac1a8 100644 --- a/application/Espo/Modules/Crm/Services/Lead.php +++ b/application/Espo/Modules/Crm/Services/Lead.php @@ -46,6 +46,8 @@ use Espo\Modules\Crm\Entities\Contact; use Espo\Core\Di; +use stdClass; + class Lead extends Record implements Di\FieldUtilAware @@ -150,10 +152,8 @@ class Lead extends Record implements $idAttribute = $field . 'Id'; $nameAttribute = $field . 'Name'; - if ($attachment) { - $attributes[$idAttribute] = $attachment->getId(); - $attributes[$nameAttribute] = $attachment->get('name'); - } + $attributes[$idAttribute] = $attachment->getId(); + $attributes[$nameAttribute] = $attachment->get('name'); } continue; @@ -169,12 +169,10 @@ class Lead extends Record implements foreach ($attachmentList as $attachment) { $attachment = $this->getAttachmentRepository()->getCopiedAttachment($attachment); - if ($attachment) { - $idList[] = $attachment->getId(); + $idList[] = $attachment->getId(); - $nameHash->{$attachment->getId()} = $attachment->get('name'); - $typeHash->{$attachment->getId()} = $attachment->get('type'); - } + $nameHash->{$attachment->getId()} = $attachment->get('name'); + $typeHash->{$attachment->getId()} = $attachment->get('type'); } $attributes[$field . 'Ids'] = $idList; @@ -221,6 +219,9 @@ class Lead extends Record implements return $data; } + /** + * @param stdClass|null $additionalData + */ public function convert(string $id, object $recordsData, ?object $additionalData = null): LeadEntity { /** @var LeadEntity */ diff --git a/application/Espo/Modules/Crm/Services/Opportunity.php b/application/Espo/Modules/Crm/Services/Opportunity.php index 8f6d872c7c..bab0786a16 100644 --- a/application/Espo/Modules/Crm/Services/Opportunity.php +++ b/application/Espo/Modules/Crm/Services/Opportunity.php @@ -371,18 +371,16 @@ class Opportunity extends Record $dtTo->setDate($dtTo->format('Y'), $dtTo->format('m'), 1); } - if ($dt && $dtTo) { - $interval = new DateInterval('P1M'); + $interval = new DateInterval('P1M'); - while ($dt->getTimestamp() < $dtTo->getTimestamp()) { - $month = $dt->format('Y-m'); + while ($dt->getTimestamp() < $dtTo->getTimestamp()) { + $month = $dt->format('Y-m'); - if (!array_key_exists($month, $result)) { - $result[$month] = 0; - } - - $dt->add($interval); + if (!array_key_exists($month, $result)) { + $result[$month] = 0; } + + $dt->add($interval); } $keyList = array_keys($result); diff --git a/application/Espo/Modules/Crm/Services/TargetList.php b/application/Espo/Modules/Crm/Services/TargetList.php index 2fe283de04..394f7b720e 100644 --- a/application/Espo/Modules/Crm/Services/TargetList.php +++ b/application/Espo/Modules/Crm/Services/TargetList.php @@ -185,7 +185,7 @@ class TargetList extends \Espo\Services\Record implements public function unlinkAll(string $id, string $link) { - /** @var TargetListEntity $entity */ + /** @var TargetListEntity|null $entity */ $entity = $this->getRepository()->get($id); if (!$entity) {