From 2bf70e88bafa87789b70ea64655116e93eafeefc Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 15 Sep 2020 15:29:09 +0300 Subject: [PATCH] fix repository usage --- .../Espo/Modules/Crm/Repositories/Meeting.php | 18 ++++++++++++++++-- .../Espo/Modules/Crm/Repositories/Task.php | 15 ++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/application/Espo/Modules/Crm/Repositories/Meeting.php b/application/Espo/Modules/Crm/Repositories/Meeting.php index c6bc9e4c57..2cf6203a20 100644 --- a/application/Espo/Modules/Crm/Repositories/Meeting.php +++ b/application/Espo/Modules/Crm/Repositories/Meeting.php @@ -50,17 +50,21 @@ class Meeting extends \Espo\Core\Repositories\Event implements Di\ConfigAware, D if ($entity->isAttributeChanged('parentId') || $entity->isAttributeChanged('parentType')) { $parent = null; + if ($parentId && $parentType) { if ($this->getEntityManager()->hasRepository($parentType)) { $columnList = ['id', 'name']; + if ($this->getEntityManager()->getMetadata()->get($parentType, ['fields', 'accountId'])) { $columnList[] = 'accountId'; } + if ($parentType === 'Lead') { $columnList[] = 'status'; $columnList[] = 'createdAccountId'; $columnList[] = 'createdAccountName'; } + $parent = $this->getEntityManager()->getRepository($parentType) ->select($columnList) ->where(['id' => $parentId]) @@ -82,9 +86,13 @@ class Meeting extends \Espo\Core\Repositories\Event implements Di\ConfigAware, D } } } - if (!$accountId && $parent->get('accountId') && $parent->getRelationParam('account', 'entity') == 'Account') { + if ( + !$accountId && $parent->get('accountId') && + $parent->getRelationParam('account', 'entity') == 'Account' + ) { $accountId = $parent->get('accountId'); } + if ($accountId) { $entity->set('accountId', $accountId); $entity->set('accountName', $accountName); @@ -96,7 +104,12 @@ class Meeting extends \Espo\Core\Repositories\Event implements Di\ConfigAware, D && !$entity->get('accountName') ) { - $account = $this->getEntityManager()->getRepository('Account')->select(['id', 'name'])->get($entity->get('accountId')); + $account = $this->getEntityManager() + ->getRepository('Account') + ->select(['id', 'name']) + ->where(['id' => $entity->get('accountId')]) + ->findOne(); + if ($account) { $entity->set('accountName', $account->get('name')); } @@ -108,6 +121,7 @@ class Meeting extends \Espo\Core\Repositories\Event implements Di\ConfigAware, D if (!$this->config->get('eventAssignedUserIsAttendeeDisabled')) { if ($entity->hasLinkMultipleField('assignedUsers')) { $assignedUserIdList = $entity->getLinkMultipleIdList('assignedUsers'); + foreach ($assignedUserIdList as $assignedUserId) { $entity->addLinkMultipleId('users', $assignedUserId); $entity->setLinkMultipleName('users', $assignedUserId, diff --git a/application/Espo/Modules/Crm/Repositories/Task.php b/application/Espo/Modules/Crm/Repositories/Task.php index 74abd33d8d..d20ca44c64 100644 --- a/application/Espo/Modules/Crm/Repositories/Task.php +++ b/application/Espo/Modules/Crm/Repositories/Task.php @@ -133,7 +133,12 @@ class Task extends \Espo\Core\Repositories\Event && !$entity->get('accountName') ) { - $account = $this->getEntityManager()->getRepository('Account')->select(['id', 'name'])->get($entity->get('accountId')); + $account = $this->getEntityManager() + ->getRepository('Account') + ->select(['id', 'name']) + ->where(['id' => $entity->get('accountId')]) + ->findOne(); + if ($account) { $entity->set('accountName', $account->get('name')); } @@ -144,14 +149,18 @@ class Task extends \Espo\Core\Repositories\Event && !$entity->get('contactName') ) { - $contact = $this->getEntityManager()->getRepository('Contact')->select(['id', 'name'])->get($entity->get('contactId')); + $contact = $this->getEntityManager() + ->getRepository('Contact') + ->select(['id', 'name']) + ->where(['id' => $entity->get('contactId')]) + ->findOne(); + if ($contact) { $entity->set('contactName', $contact->get('name')); } } } - parent::beforeSave($entity, $options); } }