From abfc22c080fce37cded234a502f3248a5306da2c Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 15 Nov 2024 12:13:25 +0200 Subject: [PATCH] ref --- .../DefaultLayouts/DefaultSidePanelType.php | 20 ++++++++++----- .../EntityGroup/CountRelatedType.php | 3 ++- .../Functions/EntityGroup/SumRelatedType.php | 3 ++- .../RecordGroup/FindRelatedManyType.php | 3 ++- .../RecordGroup/FindRelatedOneType.php | 7 +++--- application/Espo/Core/ORM/Entity.php | 5 ++-- .../Portal/Acl/DefaultOwnershipChecker.php | 9 ++++--- application/Espo/Core/Record/Service.php | 7 +++--- .../Espo/Core/Repositories/Database.php | 5 ++-- .../Espo/Core/Select/Helpers/FieldHelper.php | 3 ++- .../Espo/Core/Select/SelectManager.php | 17 +++++++------ .../Espo/Core/Select/Where/Checker.php | 25 ++++++++++--------- .../Utils/Database/Orm/Defs/RelationDefs.php | 4 +-- .../TargetList/OptedOutCountLoader.php | 3 ++- .../Modules/Crm/Hooks/Meeting/ParentLink.php | 3 ++- .../Modules/Crm/Hooks/Task/ParentLink.php | 5 ++-- .../Crm/Tools/Campaign/MailMergeService.php | 3 ++- .../Crm/Tools/TargetList/OptOutService.php | 3 ++- .../Crm/Tools/TargetList/RecordService.php | 2 +- .../Espo/ORM/Defs/Params/RelationParam.php | 5 ++++ application/Espo/ORM/Defs/RelationDefs.php | 6 ++--- application/Espo/ORM/Mapper/BaseMapper.php | 12 ++++----- .../ORM/QueryComposer/BaseQueryComposer.php | 6 ++--- .../Espo/ORM/Repository/RDBRelation.php | 3 ++- .../Repository/RDBRelationSelectBuilder.php | 3 ++- application/Espo/Repositories/Email.php | 3 ++- .../Hook/Hooks/DeleteHasChildrenLinks.php | 5 ++-- .../Format/Xlsx/PhpSpreadsheetProcessor.php | 4 ++- application/Espo/Tools/Import/Import.php | 3 ++- application/Espo/Tools/Layout/Service.php | 4 ++- 30 files changed, 111 insertions(+), 73 deletions(-) diff --git a/application/Espo/Classes/DefaultLayouts/DefaultSidePanelType.php b/application/Espo/Classes/DefaultLayouts/DefaultSidePanelType.php index 5789908110..a12d7ff4a3 100644 --- a/application/Espo/Classes/DefaultLayouts/DefaultSidePanelType.php +++ b/application/Espo/Classes/DefaultLayouts/DefaultSidePanelType.php @@ -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]; } diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php index 0e909b7ebc..ea0527deeb 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php @@ -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(); diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php index 6d6f966aea..fcc9c7a922 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php @@ -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(); diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php index 23642677c5..a824503ff7 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedManyType.php @@ -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'."); diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php index 6bccdd50ae..33c81d6340 100644 --- a/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php +++ b/application/Espo/Core/Formula/Functions/RecordGroup/FindRelatedOneType.php @@ -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 diff --git a/application/Espo/Core/ORM/Entity.php b/application/Espo/Core/ORM/Entity.php index fb61991ebc..a19d4fa587 100644 --- a/application/Espo/Core/ORM/Entity.php +++ b/application/Espo/Core/ORM/Entity.php @@ -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')) { diff --git a/application/Espo/Core/Portal/Acl/DefaultOwnershipChecker.php b/application/Espo/Core/Portal/Acl/DefaultOwnershipChecker.php index 65495d916f..cf5abf4ebb 100644 --- a/application/Espo/Core/Portal/Acl/DefaultOwnershipChecker.php +++ b/application/Espo/Core/Portal/Acl/DefaultOwnershipChecker.php @@ -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()); diff --git a/application/Espo/Core/Record/Service.php b/application/Espo/Core/Record/Service.php index a36c23fda8..405ce7e159 100644 --- a/application/Espo/Core/Record/Service.php +++ b/application/Espo/Core/Record/Service.php @@ -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'."); diff --git a/application/Espo/Core/Repositories/Database.php b/application/Espo/Core/Repositories/Database.php index dcad8cda9e..d13ea2c1e2 100644 --- a/application/Espo/Core/Repositories/Database.php +++ b/application/Espo/Core/Repositories/Database.php @@ -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); diff --git a/application/Espo/Core/Select/Helpers/FieldHelper.php b/application/Espo/Core/Select/Helpers/FieldHelper.php index 788a4f5064..f01cb48cd5 100644 --- a/application/Espo/Core/Select/Helpers/FieldHelper.php +++ b/application/Espo/Core/Select/Helpers/FieldHelper.php @@ -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); } } diff --git a/application/Espo/Core/Select/SelectManager.php b/application/Espo/Core/Select/SelectManager.php index df1f49da2c..0af7257e25 100644 --- a/application/Espo/Core/Select/SelectManager.php +++ b/application/Espo/Core/Select/SelectManager.php @@ -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'; diff --git a/application/Espo/Core/Select/Where/Checker.php b/application/Espo/Core/Select/Where/Checker.php index 8e5e78cf91..117f79bfe2 100644 --- a/application/Espo/Core/Select/Where/Checker.php +++ b/application/Espo/Core/Select/Where/Checker.php @@ -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."); } } diff --git a/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php b/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php index 15d96d6680..2cdc83dddb 100644 --- a/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php +++ b/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php @@ -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); } /** diff --git a/application/Espo/Modules/Crm/Classes/FieldProcessing/TargetList/OptedOutCountLoader.php b/application/Espo/Modules/Crm/Classes/FieldProcessing/TargetList/OptedOutCountLoader.php index aba28d0f1f..609836aadc 100644 --- a/application/Espo/Modules/Crm/Classes/FieldProcessing/TargetList/OptedOutCountLoader.php +++ b/application/Espo/Modules/Crm/Classes/FieldProcessing/TargetList/OptedOutCountLoader.php @@ -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) diff --git a/application/Espo/Modules/Crm/Hooks/Meeting/ParentLink.php b/application/Espo/Modules/Crm/Hooks/Meeting/ParentLink.php index 7a1375d686..745542a30e 100644 --- a/application/Espo/Modules/Crm/Hooks/Meeting/ParentLink.php +++ b/application/Espo/Modules/Crm/Hooks/Meeting/ParentLink.php @@ -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'); } diff --git a/application/Espo/Modules/Crm/Hooks/Task/ParentLink.php b/application/Espo/Modules/Crm/Hooks/Task/ParentLink.php index 6e826015b8..187b909760 100644 --- a/application/Espo/Modules/Crm/Hooks/Task/ParentLink.php +++ b/application/Espo/Modules/Crm/Hooks/Task/ParentLink.php @@ -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'); } diff --git a/application/Espo/Modules/Crm/Tools/Campaign/MailMergeService.php b/application/Espo/Modules/Crm/Tools/Campaign/MailMergeService.php index 05b816fd87..831ca67b80 100644 --- a/application/Espo/Modules/Crm/Tools/Campaign/MailMergeService.php +++ b/application/Espo/Modules/Crm/Tools/Campaign/MailMergeService.php @@ -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."); diff --git a/application/Espo/Modules/Crm/Tools/TargetList/OptOutService.php b/application/Espo/Modules/Crm/Tools/TargetList/OptOutService.php index 6c489d5c35..65966036ac 100644 --- a/application/Espo/Modules/Crm/Tools/TargetList/OptOutService.php +++ b/application/Espo/Modules/Crm/Tools/TargetList/OptOutService.php @@ -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(); diff --git a/application/Espo/Modules/Crm/Tools/TargetList/RecordService.php b/application/Espo/Modules/Crm/Tools/TargetList/RecordService.php index f0e0745683..34f3194c77 100644 --- a/application/Espo/Modules/Crm/Tools/TargetList/RecordService.php +++ b/application/Espo/Modules/Crm/Tools/TargetList/RecordService.php @@ -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(); diff --git a/application/Espo/ORM/Defs/Params/RelationParam.php b/application/Espo/ORM/Defs/Params/RelationParam.php index 8b72edcc61..fe98d19a42 100644 --- a/application/Espo/ORM/Defs/Params/RelationParam.php +++ b/application/Espo/ORM/Defs/Params/RelationParam.php @@ -48,4 +48,9 @@ class RelationParam * A relation name. */ public const RELATION_NAME = 'relationName'; + + /** + * A foreign entity type. + */ + public const ENTITY = 'entity'; } diff --git a/application/Espo/ORM/Defs/RelationDefs.php b/application/Espo/ORM/Defs/RelationDefs.php index c865577f94..da059750c7 100644 --- a/application/Espo/ORM/Defs/RelationDefs.php +++ b/application/Espo/ORM/Defs/RelationDefs.php @@ -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]; } /** diff --git a/application/Espo/ORM/Mapper/BaseMapper.php b/application/Espo/ORM/Mapper/BaseMapper.php index 51ad6fef82..1050623b72 100644 --- a/application/Espo/ORM/Mapper/BaseMapper.php +++ b/application/Espo/ORM/Mapper/BaseMapper.php @@ -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 []; diff --git a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php index 9d65026c4a..0b9a062135 100644 --- a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php +++ b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php @@ -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); diff --git a/application/Espo/ORM/Repository/RDBRelation.php b/application/Espo/ORM/Repository/RDBRelation.php index 662d0289b3..b734499d6d 100644 --- a/application/Espo/ORM/Repository/RDBRelation.php +++ b/application/Espo/ORM/Repository/RDBRelation.php @@ -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() diff --git a/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php b/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php index f477b3aeac..9926d85565 100644 --- a/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php +++ b/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php @@ -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() diff --git a/application/Espo/Repositories/Email.php b/application/Espo/Repositories/Email.php index 6ef62a615c..069d2b0b8d 100644 --- a/application/Espo/Repositories/Email.php +++ b/application/Espo/Repositories/Email.php @@ -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'); } diff --git a/application/Espo/Tools/EntityManager/Hook/Hooks/DeleteHasChildrenLinks.php b/application/Espo/Tools/EntityManager/Hook/Hooks/DeleteHasChildrenLinks.php index 30c5c49179..6124a9605a 100644 --- a/application/Espo/Tools/EntityManager/Hook/Hooks/DeleteHasChildrenLinks.php +++ b/application/Espo/Tools/EntityManager/Hook/Hooks/DeleteHasChildrenLinks.php @@ -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 || diff --git a/application/Espo/Tools/Export/Format/Xlsx/PhpSpreadsheetProcessor.php b/application/Espo/Tools/Export/Format/Xlsx/PhpSpreadsheetProcessor.php index 77e112390e..c98b3f6360 100644 --- a/application/Espo/Tools/Export/Format/Xlsx/PhpSpreadsheetProcessor.php +++ b/application/Espo/Tools/Export/Format/Xlsx/PhpSpreadsheetProcessor.php @@ -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']); diff --git a/application/Espo/Tools/Import/Import.php b/application/Espo/Tools/Import/Import.php index 53272c0fa8..2dccb984ba 100644 --- a/application/Espo/Tools/Import/Import.php +++ b/application/Espo/Tools/Import/Import.php @@ -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; diff --git a/application/Espo/Tools/Layout/Service.php b/application/Espo/Tools/Layout/Service.php index 0a78f828c9..95f8e8eb87 100644 --- a/application/Espo/Tools/Layout/Service.php +++ b/application/Espo/Tools/Layout/Service.php @@ -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 &&