fix task/meeting accountName contactName

This commit is contained in:
yuri
2018-05-07 11:57:05 +03:00
parent c44cc9906e
commit 6ac0c7b301
3 changed files with 99 additions and 13 deletions

View File

@@ -42,16 +42,35 @@ class Meeting extends \Espo\Core\Repositories\Event
$parentId = $entity->get('parentId');
$parentType = $entity->get('parentType');
if ($parentId && $parentType) {
$parent = $this->getEntityManager()->getEntity($parentType, $parentId);
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)->get($parentId);
}
}
$accountId = null;
$accountName = null;
if ($parent) {
$accountId = null;
if ($parent->getEntityType() == 'Account') {
$accountId = $parent->id;
$accountName = $parent->get('name');
} else if ($parent->getEntityType() == 'Lead') {
if ($parent->get('status') == 'Converted') {
if ($parent->get('createdAccountId')) {
$accountId = $parent->get('createdAccountId');
$accountName = $parent->get('createdAccountName');
}
}
}
@@ -60,6 +79,18 @@ class Meeting extends \Espo\Core\Repositories\Event
}
if ($accountId) {
$entity->set('accountId', $accountId);
$entity->set('accountName', $accountName);
}
}
if (
$entity->get('accountId')
&&
!$entity->get('accountName')
) {
$account = $this->getEntityManager()->getRepository('Account')->select(['id', 'name'])->get($entity->get('accountId'));
if ($account) {
$entity->set('accountName', $account->get('name'));
}
}
}

View File

@@ -106,28 +106,58 @@ class Task extends \Espo\Core\Repositories\Event
if (!$entity->isNew() && $entity->isAttributeChanged('parentId')) {
$entity->set('accountId', null);
$entity->set('contactId', null);
$entity->set('accountName', null);
$entity->set('contactName', null);
}
$parentId = $entity->get('parentId');
$parentType = $entity->get('parentType');
if ($parentId && $parentType) {
$parent = $this->getEntityManager()->getEntity($parentType, $parentId);
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 ($this->getEntityManager()->getMetadata()->get($parentType, ['fields', 'contactId'])) {
$columnList[] = 'contactId';
}
if ($parentType === 'Lead') {
$columnList[] = 'status';
$columnList[] = 'createdAccountId';
$columnList[] = 'createdAccountName';
$columnList[] = 'createdContactId';
$columnList[] = 'createdContactName';
}
$parent = $this->getEntityManager()->getRepository($parentType)->select($columnList)->get($parentId);
}
}
$accountId = null;
$contactId = null;
$accountName = null;
$contactName = null;
if ($parent) {
$accountId = null;
$contactId = null;
if ($parent->getEntityType() == 'Account') {
$accountId = $parent->id;
$accountName = $parent->get('name');
} else if ($parent->getEntityType() == 'Lead') {
if ($parent->get('status') == 'Converted') {
if ($parent->get('createdAccountId')) {
$accountId = $parent->get('createdAccountId');
$accountName = $parent->get('createdAccountName');
}
if ($parent->get('createdContactId')) {
$contactId = $parent->get('createdContactId');
$contactName = $parent->get('createdContactName');
}
}
} else if ($parent->getEntityType() == 'Contact') {
$contactId = $parent->id;
$contactName = $parent->get('name');
}
if (!$accountId && $parent->get('accountId') && $parent->getRelationParam('account', 'entity') == 'Account') {
@@ -136,16 +166,38 @@ class Task extends \Espo\Core\Repositories\Event
if (!$contactId && $parent->get('contactId') && $parent->getRelationParam('contact', 'entity') == 'Contact') {
$contactId = $parent->get('contactId');
}
}
if ($accountId) {
$entity->set('accountId', $accountId);
$entity->set('accountId', $accountId);
$entity->set('accountName', $accountName);
$entity->set('contactId', $contactId);
$entity->set('contactName', $contactName);
if (
$entity->get('accountId')
&&
!$entity->get('accountName')
) {
$account = $this->getEntityManager()->getRepository('Account')->select(['id', 'name'])->get($entity->get('accountId'));
if ($account) {
$entity->set('accountName', $account->get('name'));
}
if ($contactId) {
$entity->set('contactId', $contactId);
}
if (
$entity->get('contactId')
&&
!$entity->get('contactName')
) {
$contact = $this->getEntityManager()->getRepository('Contact')->select(['id', 'name'])->get($entity->get('contactId'));
if ($contact) {
$entity->set('contactName', $contact->get('name'));
}
}
}
parent::beforeSave($entity, $options);
}
}

View File

@@ -38,12 +38,15 @@ class Metadata
$this->data = $data;
}
public function get($entityType)
public function get($entityType, $key = null, $default = null)
{
if (!array_key_exists($entityType, $this->data)) {
return null;
}
return $this->data[$entityType];
$data = $this->data[$entityType];
if (!$key) return $data;
return \Espo\Core\Utils\Util::getValueByKey($data, $key, $default);
}
public function has($entityType)