Skip to content

EspoCRM – Open Source CRM Application

Lead conversion fix attachments

Yuriif6268675f70d
diff --git a/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php b/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php
index 8a499e9e2c..1d7ce0f942 100644
--- a/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php
+++ b/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php
@@ -29,6 +29,7 @@
namespace Espo\Modules\Crm\Tools\Lead;
+use Countable;
use Espo\Core\Acl;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Conflict;
@@ -55,6 +56,7 @@ use Espo\Modules\Crm\Entities\Opportunity;
use Espo\Modules\Crm\Tools\Lead\Convert\Params;
use Espo\Modules\Crm\Tools\Lead\Convert\Values;
use Espo\ORM\Collection;
+use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Name\Attribute;
use Espo\Repositories\Attachment as AttachmentRepository;
@@ -182,9 +184,9 @@ class ConvertService
$type = $this->metadata->get(['entityDefs', $entityType, 'fields', $field, 'type']);
if (in_array($type, [FieldType::FILE, FieldType::IMAGE])) {
- $attachment = $lead->get($leadField);
+ $attachment = $this->getRelatedOne($lead, $leadField);
- if ($attachment) {
+ if ($attachment instanceof Attachment) {
$attachment = $this->getAttachmentRepository()->getCopiedAttachment($attachment);
$idAttribute = $field . 'Id';
@@ -198,7 +200,10 @@ class ConvertService
}
if ($type === FieldType::ATTACHMENT_MULTIPLE) {
- $attachmentList = $lead->get($leadField);
+ /** @var Collection<Attachment> & Countable $attachmentList */
+ $attachmentList = $this->entityManager
+ ->getRelation($lead, $leadField)
+ ->find();
if (count($attachmentList)) {
$idList = [];
@@ -613,4 +618,12 @@ class ConvertService
throw ConflictSilent::createWithBody('duplicate', Json::encode($duplicateList));
}
+
+
+ private function getRelatedOne(Entity $entity, string $link): ?Entity
+ {
+ return $this->entityManager
+ ->getRelation($entity, $link)
+ ->findOne();
+ }
}