fix repository usage
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user