ref
This commit is contained in:
@@ -34,6 +34,8 @@ use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\Team;
|
||||
use Espo\Entities\User;
|
||||
use Espo\ORM\Defs\Params\FieldParam;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use stdClass;
|
||||
|
||||
class DefaultSidePanelType
|
||||
@@ -49,18 +51,24 @@ class DefaultSidePanelType
|
||||
$list = [];
|
||||
|
||||
if (
|
||||
$this->metadata->get(['entityDefs', $scope, 'fields', Field::ASSIGNED_USER, 'type']) === FieldType::LINK &&
|
||||
$this->metadata->get(['entityDefs', $scope, 'links', Field::ASSIGNED_USER, 'entity']) === User::ENTITY_TYPE
|
||||
$this->metadata->get(['entityDefs', $scope, 'fields', Field::ASSIGNED_USER, FieldParam::TYPE]) ===
|
||||
FieldType::LINK &&
|
||||
$this->metadata->get(['entityDefs', $scope, 'links', Field::ASSIGNED_USER, RelationParam::ENTITY]) ===
|
||||
User::ENTITY_TYPE
|
||||
||
|
||||
$this->metadata->get(['entityDefs', $scope, 'fields', Field::ASSIGNED_USERS, 'type']) === FieldType::LINK_MULTIPLE &&
|
||||
$this->metadata->get(['entityDefs', $scope, 'links', Field::ASSIGNED_USERS, 'entity']) === User::ENTITY_TYPE
|
||||
$this->metadata->get(['entityDefs', $scope, 'fields', Field::ASSIGNED_USERS, FieldParam::TYPE]) ===
|
||||
FieldType::LINK_MULTIPLE &&
|
||||
$this->metadata->get(['entityDefs', $scope, 'links', Field::ASSIGNED_USERS, RelationParam::ENTITY]) ===
|
||||
User::ENTITY_TYPE
|
||||
) {
|
||||
$list[] = (object) ['name' => ':assignedUser'];
|
||||
}
|
||||
|
||||
if (
|
||||
$this->metadata->get(['entityDefs', $scope, 'fields', Field::TEAMS, 'type']) === FieldType::LINK_MULTIPLE &&
|
||||
$this->metadata->get(['entityDefs', $scope, 'links', Field::TEAMS, 'entity']) === Team::ENTITY_TYPE
|
||||
$this->metadata->get(['entityDefs', $scope, 'fields', Field::TEAMS, FieldParam::TYPE]) ===
|
||||
FieldType::LINK_MULTIPLE &&
|
||||
$this->metadata->get(['entityDefs', $scope, 'links', Field::TEAMS, RelationParam::ENTITY]) ===
|
||||
Team::ENTITY_TYPE
|
||||
) {
|
||||
$list[] = (object) ['name' => Field::TEAMS];
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace Espo\Core\Formula\Functions\EntityGroup;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Formula\Exceptions\Error;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\Core\Di;
|
||||
use stdClass;
|
||||
@@ -74,7 +75,7 @@ class CountRelatedType extends \Espo\Core\Formula\Functions\Base implements
|
||||
|
||||
$entityManager = $this->entityManager;
|
||||
|
||||
$foreignEntityType = $entity->getRelationParam($link, 'entity');
|
||||
$foreignEntityType = $entity->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
if (empty($foreignEntityType)) {
|
||||
throw new Error();
|
||||
|
||||
@@ -33,6 +33,7 @@ use Espo\Core\Exceptions\Error;
|
||||
|
||||
use Espo\Core\Di;
|
||||
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use stdClass;
|
||||
use PDO;
|
||||
@@ -77,7 +78,7 @@ class SumRelatedType extends \Espo\Core\Formula\Functions\Base implements
|
||||
|
||||
$entityManager = $this->entityManager;
|
||||
|
||||
$foreignEntityType = $entity->getRelationParam($link, 'entity');
|
||||
$foreignEntityType = $entity->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
if (empty($foreignEntityType)) {
|
||||
throw new Error();
|
||||
|
||||
@@ -40,6 +40,7 @@ use Espo\Core\Formula\ArgumentList;
|
||||
use Espo\Core\Formula\Functions\BaseFunction;
|
||||
use Espo\Core\Di;
|
||||
use Espo\Core\Select\Helpers\RandomStringGenerator;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
|
||||
class FindRelatedManyType extends BaseFunction implements
|
||||
@@ -139,7 +140,7 @@ class FindRelatedManyType extends BaseFunction implements
|
||||
$this->throwError("Not supported link type '$relationType'.");
|
||||
}
|
||||
|
||||
$foreignEntityType = $entity->getRelationParam($link, 'entity');
|
||||
$foreignEntityType = $entity->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
if (!$foreignEntityType) {
|
||||
$this->throwError("Bad or not supported link '$link'.");
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Espo\Core\Formula\Functions\RecordGroup;
|
||||
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\Core\Formula\{
|
||||
Functions\BaseFunction,
|
||||
@@ -121,16 +122,16 @@ class FindRelatedOneType extends BaseFunction implements
|
||||
$order = $order ?? 'ASC';
|
||||
}
|
||||
|
||||
$foreignEntityType = $entity->getRelationParam($link, 'entity');
|
||||
$foreignEntityType = $entity->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
if (!$foreignEntityType) {
|
||||
$this->throwError("Bad or not supported link '{$link}'.");
|
||||
$this->throwError("Bad or not supported link '$link'.");
|
||||
}
|
||||
|
||||
$foreignLink = $entity->getRelationParam($link, 'foreign');
|
||||
|
||||
if (!$foreignLink) {
|
||||
$this->throwError("Not supported link '{$link}'.");
|
||||
$this->throwError("Not supported link '$link'.");
|
||||
}
|
||||
|
||||
$builder = $this->selectBuilderFactory
|
||||
|
||||
@@ -34,6 +34,7 @@ use Espo\Core\Field\LinkParent;
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\Core\ORM\Defs\AttributeParam;
|
||||
use Espo\ORM\BaseEntity;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity as OrmEntity;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\ORM\Query\Part\Order;
|
||||
@@ -142,12 +143,12 @@ class Entity extends BaseEntity
|
||||
|
||||
$idsAttribute = $field . 'Ids';
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($field, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($field, RelationParam::ENTITY);
|
||||
|
||||
if ($this->getAttributeParam($idsAttribute, 'orderBy')) {
|
||||
$defs = [
|
||||
'orderBy' => $this->getAttributeParam($idsAttribute, 'orderBy'),
|
||||
'order' => 'ASC',
|
||||
'order' => Order::ASC,
|
||||
];
|
||||
|
||||
if ($this->getAttributeParam($idsAttribute, 'orderDirection')) {
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Espo\Core\Portal\Acl;
|
||||
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\ORM\BaseEntity;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
@@ -91,7 +92,7 @@ class DefaultOwnershipChecker implements
|
||||
|
||||
if (
|
||||
$entity->hasAttribute(self::ATTR_ACCOUNT_ID) &&
|
||||
$this->getRelationParam($entity, self::FIELD_ACCOUNT, 'entity') === self::ENTITY_ACCOUNT
|
||||
$this->getRelationParam($entity, self::FIELD_ACCOUNT, RelationParam::ENTITY) === self::ENTITY_ACCOUNT
|
||||
) {
|
||||
if (in_array($entity->get(self::ATTR_ACCOUNT_ID), $accountIdList)) {
|
||||
return true;
|
||||
@@ -100,7 +101,7 @@ class DefaultOwnershipChecker implements
|
||||
|
||||
if (
|
||||
$entity->hasRelation(self::FIELD_ACCOUNTS) &&
|
||||
$this->getRelationParam($entity, self::FIELD_ACCOUNTS, 'entity') === self::ENTITY_ACCOUNT
|
||||
$this->getRelationParam($entity, self::FIELD_ACCOUNTS, RelationParam::ENTITY) === self::ENTITY_ACCOUNT
|
||||
) {
|
||||
$repository = $this->entityManager->getRDBRepository($entity->getEntityType());
|
||||
|
||||
@@ -137,7 +138,7 @@ class DefaultOwnershipChecker implements
|
||||
|
||||
if (
|
||||
$entity->hasAttribute(self::ATTR_CONTACT_ID) &&
|
||||
$this->getRelationParam($entity, self::FIELD_CONTACT, 'entity') === self::ENTITY_CONTACT
|
||||
$this->getRelationParam($entity, self::FIELD_CONTACT, RelationParam::ENTITY) === self::ENTITY_CONTACT
|
||||
) {
|
||||
if ($entity->get(self::ATTR_CONTACT_ID) === $contactId) {
|
||||
return true;
|
||||
@@ -146,7 +147,7 @@ class DefaultOwnershipChecker implements
|
||||
|
||||
if (
|
||||
$entity->hasRelation(self::FIELD_CONTACTS) &&
|
||||
$this->getRelationParam($entity, self::FIELD_CONTACTS, 'entity') === self::ENTITY_CONTACT
|
||||
$this->getRelationParam($entity, self::FIELD_CONTACTS, RelationParam::ENTITY) === self::ENTITY_CONTACT
|
||||
) {
|
||||
$repository = $this->entityManager->getRDBRepository($entity->getEntityType());
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ use Espo\Core\Record\Duplicator\EntityDuplicator;
|
||||
use Espo\Core\Record\Select\ApplierClassNameListProvider;
|
||||
use Espo\Core\Select\SearchParams;
|
||||
use Espo\Core\Di;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\ORM\Repository\RDBRepository;
|
||||
@@ -1072,7 +1073,7 @@ class Service implements Crud,
|
||||
|
||||
$this->getLinkCheck()->processLink($entity, $link);
|
||||
|
||||
$foreignEntityType = $entity->getRelationParam($link, 'entity');
|
||||
$foreignEntityType = $entity->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
if (!$foreignEntityType) {
|
||||
throw new LogicException("Entity '$this->entityType' has not relation '$link'.");
|
||||
@@ -1126,7 +1127,7 @@ class Service implements Crud,
|
||||
|
||||
$this->getLinkCheck()->processUnlink($entity, $link);
|
||||
|
||||
$foreignEntityType = $entity->getRelationParam($link, 'entity');
|
||||
$foreignEntityType = $entity->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
if (!$foreignEntityType) {
|
||||
throw new LogicException("Entity '$this->entityType' has not relation '$link'.");
|
||||
@@ -1184,7 +1185,7 @@ class Service implements Crud,
|
||||
throw new LogicException("Only core entities are supported.");
|
||||
}
|
||||
|
||||
$foreignEntityType = $entity->getRelationParam($link, 'entity');
|
||||
$foreignEntityType = $entity->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
if (!$foreignEntityType) {
|
||||
throw new LogicException("Link '$link' has no 'entity'.");
|
||||
|
||||
@@ -33,6 +33,7 @@ use Espo\Core\Name\Field;
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\Core\Utils\SystemUser;
|
||||
use Espo\ORM\BaseEntity;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Relation\RelationsMap;
|
||||
use Espo\ORM\Repository\RDBRepository;
|
||||
@@ -248,7 +249,7 @@ class Database extends RDBRepository
|
||||
if (is_string($foreign)) {
|
||||
$foreignId = $foreign;
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, RelationParam::ENTITY);
|
||||
|
||||
if ($foreignEntityType) {
|
||||
$foreign = $this->entityManager->getNewEntity($foreignEntityType);
|
||||
@@ -288,7 +289,7 @@ class Database extends RDBRepository
|
||||
if (is_string($foreign)) {
|
||||
$foreignId = $foreign;
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, RelationParam::ENTITY);
|
||||
|
||||
if ($foreignEntityType) {
|
||||
$foreign = $this->entityManager->getNewEntity($foreignEntityType);
|
||||
|
||||
@@ -35,6 +35,7 @@ use Espo\Entities\Team;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Defs\RelationDefs;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Entity;
|
||||
@@ -202,6 +203,6 @@ class FieldHelper
|
||||
|
||||
private function getRelationEntityType(string $relation): ?string
|
||||
{
|
||||
return $this->getRelationParam($this->getSeed(), $relation, 'entity');
|
||||
return $this->getRelationParam($this->getSeed(), $relation, RelationParam::ENTITY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ use Espo\Core\Utils\FieldUtil;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
|
||||
use Espo\Entities\StreamSubscription;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\ORM\Query\Select as SelectQuery;
|
||||
@@ -705,14 +706,14 @@ class SelectManager
|
||||
if ($contactId) {
|
||||
if (
|
||||
$this->getSeed()->hasAttribute('contactId') &&
|
||||
$this->getSeed()->getRelationParam('contact', 'entity') === 'Contact'
|
||||
$this->getSeed()->getRelationParam('contact', RelationParam::ENTITY) === 'Contact'
|
||||
) {
|
||||
$or['contactId'] = $contactId;
|
||||
}
|
||||
|
||||
if (
|
||||
$this->getSeed()->hasRelation('contacts') &&
|
||||
$this->getSeed()->getRelationParam('contacts', 'entity') === 'Contact'
|
||||
$this->getSeed()->getRelationParam('contacts', RelationParam::ENTITY) === 'Contact'
|
||||
) {
|
||||
$this->addLeftJoin(['contacts', 'contactsAccess'], $result);
|
||||
$this->setDistinct(true, $result);
|
||||
@@ -755,13 +756,13 @@ class SelectManager
|
||||
if (count($accountIdList)) {
|
||||
if (
|
||||
$this->getSeed()->hasAttribute('accountId') &&
|
||||
$this->getSeed()->getRelationParam('account', 'entity') === 'Account'
|
||||
$this->getSeed()->getRelationParam('account', RelationParam::ENTITY) === 'Account'
|
||||
) {
|
||||
$or['accountId'] = $accountIdList;
|
||||
}
|
||||
if (
|
||||
$this->getSeed()->hasRelation('accounts') &&
|
||||
$this->getSeed()->getRelationParam('accounts', 'entity') === 'Account'
|
||||
$this->getSeed()->getRelationParam('accounts', RelationParam::ENTITY) === 'Account'
|
||||
) {
|
||||
$this->addLeftJoin(['accounts', 'accountsAccess'], $result);
|
||||
$this->setDistinct(true, $result);
|
||||
@@ -784,13 +785,13 @@ class SelectManager
|
||||
if ($contactId) {
|
||||
if (
|
||||
$this->getSeed()->hasAttribute('contactId') &&
|
||||
$this->getSeed()->getRelationParam('contact', 'entity') === 'Contact'
|
||||
$this->getSeed()->getRelationParam('contact', RelationParam::ENTITY) === 'Contact'
|
||||
) {
|
||||
$or['contactId'] = $contactId;
|
||||
}
|
||||
if (
|
||||
$this->getSeed()->hasRelation('contacts') &&
|
||||
$this->getSeed()->getRelationParam('contacts', 'entity') === 'Contact'
|
||||
$this->getSeed()->getRelationParam('contacts', RelationParam::ENTITY) === 'Contact'
|
||||
) {
|
||||
$this->addLeftJoin(['contacts', 'contactsAccess'], $result);
|
||||
$this->setDistinct(true, $result);
|
||||
@@ -968,7 +969,7 @@ class SelectManager
|
||||
// TODO allow alias
|
||||
throw new Forbidden("SelectManager::checkWhere: Unknown relation '{$link}' in where.");
|
||||
}
|
||||
$entityType = $this->getSeed()->getRelationParam($link, 'entity');
|
||||
$entityType = $this->getSeed()->getRelationParam($link, RelationParam::ENTITY);
|
||||
if (!$entityType) {
|
||||
throw new Forbidden("SelectManager::checkWhere: Bad relation.");
|
||||
}
|
||||
@@ -1834,7 +1835,7 @@ class SelectManager
|
||||
list($arrayAttributeLink, $arrayAttribute) = explode('.', $attribute);
|
||||
}
|
||||
|
||||
$arrayEntityType = $seed->getRelationParam($arrayAttributeLink, 'entity');
|
||||
$arrayEntityType = $seed->getRelationParam($arrayAttributeLink, RelationParam::ENTITY);
|
||||
|
||||
$arrayLinkAlias = $arrayAttributeLink . 'Filter' . rand(10000, 99999);
|
||||
$idPart = $arrayLinkAlias . '.id';
|
||||
|
||||
@@ -33,6 +33,7 @@ use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Acl;
|
||||
use Espo\Core\Select\Where\Item\Type;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\QueryComposer\BaseQueryComposer as QueryComposer;
|
||||
use Espo\ORM\QueryComposer\Util as QueryUtil;
|
||||
use Espo\ORM\EntityManager;
|
||||
@@ -149,14 +150,14 @@ class Checker
|
||||
|
||||
if (in_array($type, $this->linkTypeList)) {
|
||||
if (!$this->getSeed()->hasRelation($attribute)) {
|
||||
throw new BadRequest("Not existing relation '{$attribute}' in where.");
|
||||
throw new BadRequest("Not existing relation '$attribute' in where.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->getSeed()->hasAttribute($attribute)) {
|
||||
throw new BadRequest("Not existing attribute '{$attribute}' in where.");
|
||||
throw new BadRequest("Not existing attribute '$attribute' in where.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,24 +173,24 @@ class Checker
|
||||
|
||||
if (!$this->getSeed()->hasRelation($link)) {
|
||||
// TODO allow alias
|
||||
throw new Forbidden("Bad relation '{$link}' in where.");
|
||||
throw new Forbidden("Bad relation '$link' in where.");
|
||||
}
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($this->getSeed(), $link, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($this->getSeed(), $link, RelationParam::ENTITY);
|
||||
|
||||
if (!$foreignEntityType) {
|
||||
throw new Forbidden("Bad relation '{$link}' in where.");
|
||||
throw new Forbidden("Bad relation '$link' in where.");
|
||||
}
|
||||
|
||||
if (
|
||||
!$this->acl->checkScope($foreignEntityType) ||
|
||||
in_array($link, $this->acl->getScopeForbiddenLinkList($entityType))
|
||||
) {
|
||||
throw new Forbidden("Forbidden relation '{$link}' in where.");
|
||||
throw new Forbidden("Forbidden relation '$link' in where.");
|
||||
}
|
||||
|
||||
if (in_array($attribute, $this->acl->getScopeForbiddenAttributeList($foreignEntityType))) {
|
||||
throw new Forbidden("Forbidden attribute '{$link}.{$attribute}' in where.");
|
||||
throw new Forbidden("Forbidden attribute '$link.{$attribute}' in where.");
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -199,13 +200,13 @@ class Checker
|
||||
$link = $attribute;
|
||||
|
||||
if (!$this->getSeed()->hasRelation($link)) {
|
||||
throw new Forbidden("Bad relation '{$link}' in where.");
|
||||
throw new Forbidden("Bad relation '$link' in where.");
|
||||
}
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($this->getSeed(), $link, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($this->getSeed(), $link, RelationParam::ENTITY);
|
||||
|
||||
if (!$foreignEntityType) {
|
||||
throw new Forbidden("Bad relation '{$link}' in where.");
|
||||
throw new Forbidden("Bad relation '$link' in where.");
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -213,14 +214,14 @@ class Checker
|
||||
!$this->acl->checkScope($foreignEntityType) ||
|
||||
in_array($link, $this->acl->getScopeForbiddenLinkList($entityType))
|
||||
) {
|
||||
throw new Forbidden("Forbidden relation '{$link}' in where.");
|
||||
throw new Forbidden("Forbidden relation '$link' in where.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array($attribute, $this->acl->getScopeForbiddenAttributeList($entityType))) {
|
||||
throw new Forbidden("Forbidden attribute '{$attribute}' in where.");
|
||||
throw new Forbidden("Forbidden attribute '$attribute' in where.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ class RelationDefs
|
||||
*/
|
||||
public function withForeignEntityType(string $entityType): self
|
||||
{
|
||||
return $this->withParam('entity', $entityType);
|
||||
return $this->withParam(RelationParam::ENTITY, $entityType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +87,7 @@ class RelationDefs
|
||||
*/
|
||||
public function getForeignEntityType(): ?string
|
||||
{
|
||||
return $this->getParam('entity');
|
||||
return $this->getParam(RelationParam::ENTITY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@
|
||||
|
||||
namespace Espo\Modules\Crm\Classes\FieldProcessing\TargetList;
|
||||
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Modules\Crm\Entities\TargetList;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
@@ -64,7 +65,7 @@ class OptedOutCountLoader implements Loader
|
||||
$count = 0;
|
||||
|
||||
foreach ($this->targetLinkList as $link) {
|
||||
$foreignEntityType = $entity->getRelationParam($link, 'entity');
|
||||
$foreignEntityType = $entity->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
$count += $this->entityManager
|
||||
->getRDBRepository($foreignEntityType)
|
||||
|
||||
@@ -34,6 +34,7 @@ use Espo\Core\Name\Field;
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
@@ -103,7 +104,7 @@ class ParentLink implements BeforeSave
|
||||
if (
|
||||
!$accountId && $parent->get('accountId') &&
|
||||
$parent instanceof CoreEntity &&
|
||||
$parent->getRelationParam('account', 'entity') === Account::ENTITY_TYPE
|
||||
$parent->getRelationParam('account', RelationParam::ENTITY) === Account::ENTITY_TYPE
|
||||
) {
|
||||
$accountId = $parent->get('accountId');
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use Espo\Modules\Crm\Entities\Task;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
@@ -128,7 +129,7 @@ class ParentLink implements BeforeSave
|
||||
!$accountId &&
|
||||
$parent->get('accountId') &&
|
||||
$parent instanceof CoreEntity &&
|
||||
$parent->getRelationParam('account', 'entity') === Account::ENTITY_TYPE
|
||||
$parent->getRelationParam('account', RelationParam::ENTITY) === Account::ENTITY_TYPE
|
||||
) {
|
||||
$accountId = $parent->get('accountId');
|
||||
}
|
||||
@@ -137,7 +138,7 @@ class ParentLink implements BeforeSave
|
||||
!$contactId &&
|
||||
$parent->get('contactId') &&
|
||||
$parent instanceof CoreEntity &&
|
||||
$parent->getRelationParam('contact', 'entity') === Contact::ENTITY_TYPE
|
||||
$parent->getRelationParam('contact', RelationParam::ENTITY) === Contact::ENTITY_TYPE
|
||||
) {
|
||||
$contactId = $parent->get('contactId');
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ use Espo\Entities\Template;
|
||||
use Espo\Modules\Crm\Entities\Campaign as CampaignEntity;
|
||||
use Espo\Modules\Crm\Entities\TargetList;
|
||||
use Espo\ORM\Collection;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityCollection;
|
||||
use Espo\ORM\EntityManager;
|
||||
@@ -93,7 +94,7 @@ class MailMergeService
|
||||
}
|
||||
|
||||
/** @var string $targetEntityType */
|
||||
$targetEntityType = $campaign->getRelationParam($link, 'entity');
|
||||
$targetEntityType = $campaign->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
if ($checkAcl && !$this->acl->check($targetEntityType, Acl\Table::ACTION_READ)) {
|
||||
throw new Forbidden("Could not mail merge campaign because access to target entity type is forbidden.");
|
||||
|
||||
@@ -38,6 +38,7 @@ use Espo\Core\Record\Collection as RecordCollection;
|
||||
use Espo\Core\Record\EntityProvider;
|
||||
use Espo\Core\Select\SearchParams;
|
||||
use Espo\Modules\Crm\Entities\TargetList;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Query\Part\Order;
|
||||
@@ -203,7 +204,7 @@ class OptOutService
|
||||
{
|
||||
$seed = $this->entityManager->getRDBRepositoryByClass(TargetList::class)->getNew();
|
||||
|
||||
$entityType = $seed->getRelationParam($link, 'entity');
|
||||
$entityType = $seed->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
if (!$entityType) {
|
||||
throw new RuntimeException();
|
||||
|
||||
@@ -102,7 +102,7 @@ class RecordService
|
||||
throw new BadRequest("Not supported link.");
|
||||
}
|
||||
|
||||
$foreignEntityType = $entity->getRelationParam($link, 'entity');
|
||||
$foreignEntityType = $entity->getRelationParam($link, RelationParam::ENTITY);
|
||||
|
||||
if (!$foreignEntityType) {
|
||||
throw new RuntimeException();
|
||||
|
||||
@@ -48,4 +48,9 @@ class RelationParam
|
||||
* A relation name.
|
||||
*/
|
||||
public const RELATION_NAME = 'relationName';
|
||||
|
||||
/**
|
||||
* A foreign entity type.
|
||||
*/
|
||||
public const ENTITY = 'entity';
|
||||
}
|
||||
|
||||
@@ -129,11 +129,11 @@ class RelationDefs
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether has a foreign entity type is defined.
|
||||
* Whether it has a foreign entity type is defined.
|
||||
*/
|
||||
public function hasForeignEntityType(): bool
|
||||
{
|
||||
return isset($this->data['entity']);
|
||||
return isset($this->data[RelationParam::ENTITY]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +147,7 @@ class RelationDefs
|
||||
throw new RuntimeException("No 'entity' parameter defined in the relation '{$this->name}'.");
|
||||
}
|
||||
|
||||
return $this->data['entity'];
|
||||
return $this->data[RelationParam::ENTITY];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -300,7 +300,7 @@ class BaseMapper implements RDBMapper
|
||||
$entityType = $entity->getEntityType();
|
||||
$relType = $entity->getRelationType($relationName);
|
||||
|
||||
$relEntityType = $this->getRelationParam($entity, $relationName, 'entity');
|
||||
$relEntityType = $this->getRelationParam($entity, $relationName, RelationParam::ENTITY);
|
||||
|
||||
$relEntity = null;
|
||||
|
||||
@@ -738,7 +738,7 @@ class BaseMapper implements RDBMapper
|
||||
|
||||
$relType = $entity->getRelationType($relationName);
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, RelationParam::ENTITY);
|
||||
|
||||
if (!$foreignEntityType || !$relType) {
|
||||
throw new LogicException(
|
||||
@@ -833,7 +833,7 @@ class BaseMapper implements RDBMapper
|
||||
throw new RuntimeException("Bad foreign passed.");
|
||||
}
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, RelationParam::ENTITY);
|
||||
|
||||
if (!$relType || !$foreignEntityType && $relType !== Entity::BELONGS_TO_PARENT) {
|
||||
throw new LogicException(
|
||||
@@ -1119,7 +1119,7 @@ class BaseMapper implements RDBMapper
|
||||
throw new RuntimeException("Bad foreign passed.");
|
||||
}
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, RelationParam::ENTITY);
|
||||
|
||||
if ($relType === Entity::BELONGS_TO_PARENT && $relEntity) {
|
||||
$foreignEntityType = $relEntity->getEntityType();
|
||||
@@ -1685,9 +1685,9 @@ class BaseMapper implements RDBMapper
|
||||
private function getManyManyAdditionalSelect(Entity $entity, string $relationName): array
|
||||
{
|
||||
$foreign = $this->getRelationParam($entity, $relationName, 'foreign');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, RelationParam::ENTITY);
|
||||
|
||||
$middleName = lcfirst($this->getRelationParam($entity, $relationName, 'relationName'));
|
||||
$middleName = lcfirst($this->getRelationParam($entity, $relationName, RelationParam::RELATION_NAME));
|
||||
|
||||
if (!$foreign || !$foreignEntityType) {
|
||||
return [];
|
||||
|
||||
@@ -1330,7 +1330,7 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
if ($relName) {
|
||||
$part = $this->quoteColumn($relName . '.' . $part);
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relName, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relName, RelationParam::ENTITY);
|
||||
|
||||
if ($foreignEntityType) {
|
||||
$foreignSeed = $this->getSeed($foreignEntityType);
|
||||
@@ -1994,7 +1994,7 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
return null;
|
||||
}
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, RelationParam::ENTITY);
|
||||
|
||||
$table = $this->toDb($foreignEntityType);
|
||||
|
||||
@@ -3254,7 +3254,7 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
$alias = $this->sanitize($alias);
|
||||
|
||||
$relationConditions = $this->getRelationParam($entity, $relationName, 'conditions');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, 'entity');
|
||||
$foreignEntityType = $this->getRelationParam($entity, $relationName, RelationParam::ENTITY);
|
||||
|
||||
if ($relationConditions) {
|
||||
$conditions = array_merge($conditions, $relationConditions);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
namespace Espo\ORM\Repository;
|
||||
|
||||
use Espo\ORM\Collection;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityCollection;
|
||||
use Espo\ORM\EntityManager;
|
||||
@@ -80,7 +81,7 @@ class RDBRelation
|
||||
$this->entityType = $entity->getEntityType();
|
||||
|
||||
if ($entity instanceof BaseEntity) {
|
||||
$this->foreignEntityType = $entity->getRelationParam($relationName, 'entity');
|
||||
$this->foreignEntityType = $entity->getRelationParam($relationName, RelationParam::ENTITY);
|
||||
} else {
|
||||
$this->foreignEntityType = $this->entityManager
|
||||
->getDefs()
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
namespace Espo\ORM\Repository;
|
||||
|
||||
use Espo\ORM\Collection;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\EntityCollection;
|
||||
use Espo\ORM\Mapper\RDBMapper;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
@@ -72,7 +73,7 @@ class RDBRelationSelectBuilder
|
||||
$entityType = $entity->getEntityType();
|
||||
|
||||
if ($entity instanceof BaseEntity) {
|
||||
$this->foreignEntityType = $entity->getRelationParam($relationName, 'entity');
|
||||
$this->foreignEntityType = $entity->getRelationParam($relationName, RelationParam::ENTITY);
|
||||
} else {
|
||||
$this->foreignEntityType = $this->entityManager
|
||||
->getDefs()
|
||||
|
||||
@@ -37,6 +37,7 @@ use Espo\Entities\InboundEmail;
|
||||
use Espo\Entities\User as UserEntity;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\ORM\Collection;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
use Espo\Core\Repositories\Database;
|
||||
@@ -424,7 +425,7 @@ class Email extends Database implements
|
||||
!$accountId &&
|
||||
$parent->get('accountId') &&
|
||||
$parent instanceof CoreEntity &&
|
||||
$parent->getRelationParam('account', 'entity') === Account::ENTITY_TYPE
|
||||
$parent->getRelationParam('account', RelationParam::ENTITY) === Account::ENTITY_TYPE
|
||||
) {
|
||||
$accountId = $parent->get('accountId');
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
namespace Espo\Tools\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Type\RelationType;
|
||||
use Espo\Tools\EntityManager\Hook\DeleteHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
@@ -54,8 +55,8 @@ class DeleteHasChildrenLinks implements DeleteHook
|
||||
|
||||
foreach ($links as $link => $linkDefs) {
|
||||
$isCustom = $linkDefs['isCustom'] ?? false;
|
||||
$foreignEntityType = $linkDefs['entity'] ?? null;
|
||||
$type = $linkDefs['type'] ?? null;
|
||||
$foreignEntityType = $linkDefs[RelationParam::ENTITY] ?? null;
|
||||
$type = $linkDefs[RelationParam::TYPE] ?? null;
|
||||
|
||||
if (
|
||||
!$isCustom ||
|
||||
|
||||
@@ -40,6 +40,7 @@ use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\DateTime as DateTimeUtil;
|
||||
use Espo\Core\Utils\Language;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Tools\Export\Collection;
|
||||
use Espo\Tools\Export\Format\CellValuePreparator;
|
||||
@@ -527,7 +528,8 @@ class PhpSpreadsheetProcessor implements ProcessorInterface
|
||||
|
||||
if ($idValue && $foreignField) {
|
||||
if (!$foreignLink) {
|
||||
$foreignEntity = $this->metadata->get(['entityDefs', $entityType, 'links', $name, 'entity']);
|
||||
$foreignEntity =
|
||||
$this->metadata->get(['entityDefs', $entityType, 'links', $name, RelationParam::ENTITY]);
|
||||
} else {
|
||||
$foreignEntity1 = $this->metadata
|
||||
->get(['entityDefs', $entityType, 'links', $foreignLink, 'entity']);
|
||||
|
||||
@@ -36,6 +36,7 @@ use Espo\Core\Job\JobSchedulerFactory;
|
||||
use Espo\Entities\Attachment;
|
||||
use Espo\Entities\ImportError;
|
||||
use Espo\ORM\Defs\Params\AttributeParam;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\Tools\Import\Jobs\RunIdle;
|
||||
use Espo\ORM\Entity;
|
||||
@@ -669,7 +670,7 @@ class Import
|
||||
return;
|
||||
}
|
||||
|
||||
$foreignEntityType = $entity->getRelationParam($relation, 'entity');
|
||||
$foreignEntityType = $entity->getRelationParam($relation, RelationParam::ENTITY);
|
||||
|
||||
if (!$foreignEntityType) {
|
||||
return;
|
||||
|
||||
@@ -43,6 +43,7 @@ use Espo\Entities\Portal;
|
||||
use Espo\Entities\Team;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Entities\LayoutRecord;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\Tools\LayoutManager\LayoutManager;
|
||||
|
||||
@@ -148,7 +149,8 @@ class Service
|
||||
$link = $item->name ?? null;
|
||||
}
|
||||
|
||||
$foreignEntityType = $this->metadata->get(['entityDefs', $scope, 'links', $link, 'entity']);
|
||||
$foreignEntityType = $this->metadata
|
||||
->get(['entityDefs', $scope, 'links', $link, RelationParam::ENTITY]);
|
||||
|
||||
if (
|
||||
$foreignEntityType &&
|
||||
|
||||
Reference in New Issue
Block a user