From 85d4490231424a25f498af596099f7be66e823cd Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 15 Nov 2024 11:47:08 +0200 Subject: [PATCH] ref --- .../FieldConverters/RelationshipRole.php | 3 +- application/Espo/Classes/Jobs/Cleanup.php | 3 +- .../Core/Utils/Database/Orm/Converter.php | 56 ++++++++++--------- .../Utils/Database/Orm/Defs/EntityDefs.php | 6 +- .../Utils/Database/Orm/Defs/RelationDefs.php | 5 +- .../Utils/Database/Orm/RelationConverter.php | 15 ++--- .../Core/Utils/Database/Schema/Builder.php | 3 +- .../Espo/Core/Utils/Database/Schema/Utils.php | 3 +- .../Crm/Tools/TargetList/RecordService.php | 3 +- application/Espo/ORM/BaseEntity.php | 3 +- application/Espo/ORM/Defs/EntityDefs.php | 13 +++-- .../Espo/ORM/Defs/Params/EntityParam.php | 51 +++++++++++++++++ .../Espo/ORM/Defs/Params/RelationParam.php | 10 ++++ application/Espo/ORM/Defs/RelationDefs.php | 6 +- application/Espo/ORM/Mapper/BaseMapper.php | 4 +- .../ORM/QueryComposer/BaseQueryComposer.php | 6 +- .../Hook/Hooks/CollaboratorsUpdateHook.php | 3 +- .../Espo/Tools/EntityManager/NameUtil.php | 3 +- .../Espo/Tools/LinkManager/LinkManager.php | 9 +-- 19 files changed, 142 insertions(+), 63 deletions(-) create mode 100644 application/Espo/ORM/Defs/Params/EntityParam.php diff --git a/application/Espo/Classes/FieldConverters/RelationshipRole.php b/application/Espo/Classes/FieldConverters/RelationshipRole.php index d1832137a6..f365b41ec2 100644 --- a/application/Espo/Classes/FieldConverters/RelationshipRole.php +++ b/application/Espo/Classes/FieldConverters/RelationshipRole.php @@ -33,6 +33,7 @@ use Espo\Core\Utils\Database\Orm\Defs\AttributeDefs; use Espo\Core\Utils\Database\Orm\Defs\EntityDefs; use Espo\Core\Utils\Database\Orm\FieldConverter; use Espo\ORM\Defs\FieldDefs; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Name\Attribute; use Espo\ORM\Type\AttributeType; use RuntimeException; @@ -66,7 +67,7 @@ class RelationshipRole implements FieldConverter /** @var ?string $link */ $link = $data['link'] ?? null; /** @var ?string $relationName */ - $relationName = $data['relationName'] ?? null; + $relationName = $data[RelationParam::RELATION_NAME] ?? null; /** @var ?string $nearKey */ $nearKey = $data['nearKey'] ?? null; diff --git a/application/Espo/Classes/Jobs/Cleanup.php b/application/Espo/Classes/Jobs/Cleanup.php index 5243e1a178..0262acf53a 100644 --- a/application/Espo/Classes/Jobs/Cleanup.php +++ b/application/Espo/Classes/Jobs/Cleanup.php @@ -49,6 +49,7 @@ use Espo\Entities\ScheduledJob; use Espo\Entities\ScheduledJobLogRecord; use Espo\Entities\UniqueId; use Espo\Entities\UserReaction; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Name\Attribute; use Espo\ORM\Query\DeleteBuilder; use Espo\ORM\Repository\RDBRepository; @@ -605,7 +606,7 @@ class Cleanup implements JobDataLess } try { - $relationName = $entity->getRelationParam($relation, 'relationName'); + $relationName = $entity->getRelationParam($relation, RelationParam::RELATION_NAME); if (!$relationName) { continue; diff --git a/application/Espo/Core/Utils/Database/Orm/Converter.php b/application/Espo/Core/Utils/Database/Orm/Converter.php index 34d5f08145..b6d8fd742b 100644 --- a/application/Espo/Core/Utils/Database/Orm/Converter.php +++ b/application/Espo/Core/Utils/Database/Orm/Converter.php @@ -41,6 +41,7 @@ use Espo\ORM\Defs\AttributeDefs; use Espo\ORM\Defs\FieldDefs; use Espo\ORM\Defs\IndexDefs; use Espo\ORM\Defs\Params\AttributeParam; +use Espo\ORM\Defs\Params\EntityParam; use Espo\ORM\Defs\Params\FieldParam; use Espo\ORM\Defs\Params\IndexParam; use Espo\ORM\Defs\Params\RelationParam; @@ -103,7 +104,7 @@ class Converter private array $idParams = []; /** @var string[] */ - private array $copyEntityProperties = ['indexes']; + private array $copyEntityProperties = [EntityParam::INDEXES]; private IndexHelper $indexHelper; @@ -200,7 +201,7 @@ class Converter $ormMetadata[$entityType] = [ 'attributes' => [], - 'relations' => [], + EntityParam::RELATIONS => [], ]; foreach ($this->copyEntityProperties as $optionName) { @@ -356,7 +357,7 @@ class Converter return null; } - $relationParams = $data[$entityType]['relations'][$relation] ?? []; + $relationParams = $data[$entityType][EntityParam::RELATIONS][$relation] ?? []; $foreignEntityType = $relationParams['entity'] ?? null; @@ -375,7 +376,7 @@ class Converter */ private function convertFields(string $entityType, array &$entityMetadata): array { - $entityMetadata['fields'] ??= []; + $entityMetadata[EntityParam::FIELDS] ??= []; // List of unmerged fields with default field definitions in $output. $unmergedFields = [Field::NAME]; @@ -385,7 +386,8 @@ class Converter AttributeParam::TYPE => Entity::ID, ], 'name' => [ - AttributeParam::TYPE => $entityMetadata['fields'][Field::NAME][FieldParam::TYPE] ?? Entity::VARCHAR, + AttributeParam::TYPE => $entityMetadata[EntityParam::FIELDS][Field::NAME][FieldParam::TYPE] ?? + Entity::VARCHAR, AttributeParam::NOT_STORABLE => true, ], Attribute::DELETED => [ @@ -398,7 +400,7 @@ class Converter unset($output[Attribute::DELETED]); } - foreach ($entityMetadata['fields'] as $attribute => $attributeParams) { + foreach ($entityMetadata[EntityParam::FIELDS] as $attribute => $attributeParams) { if (empty($attributeParams[AttributeParam::TYPE])) { continue; } @@ -507,7 +509,7 @@ class Converter $scopeDefs = $this->metadata->get(['scopes', $entityType]) ?? []; if ($scopeDefs['stream'] ?? false) { - if (!isset($entityMetadata['fields'][Field::IS_FOLLOWED])) { + if (!isset($entityMetadata[EntityParam::FIELDS][Field::IS_FOLLOWED])) { $ormMetadata[$entityType]['attributes'][Field::IS_FOLLOWED] = [ AttributeParam::TYPE => Entity::BOOL, AttributeParam::NOT_STORABLE => true, @@ -530,7 +532,7 @@ class Converter // @todo Refactor. if ($scopeDefs['stars'] ?? false) { - if (!isset($entityMetadata['fields'][Field::IS_STARRED])) { + if (!isset($entityMetadata[EntityParam::FIELDS][Field::IS_STARRED])) { $ormMetadata[$entityType]['attributes'][Field::IS_STARRED] = [ AttributeParam::TYPE => Entity::BOOL, AttributeParam::NOT_STORABLE => true, @@ -698,7 +700,7 @@ class Converter } $fieldList = $this->metadata - ->get(['entityDefs', $entityType, 'collection', 'textFilterFields'], ['name']); + ->get(['entityDefs', $entityType, 'collection', 'textFilterFields'], [Field::NAME]); $fullTextSearchColumnList = []; @@ -739,11 +741,11 @@ class Converter if (!empty($fullTextSearchColumnList)) { $ormMetadata[$entityType]['fullTextSearchColumnList'] = $fullTextSearchColumnList; - if (!array_key_exists('indexes', $ormMetadata[$entityType])) { - $ormMetadata[$entityType]['indexes'] = []; + if (!array_key_exists(EntityParam::INDEXES, $ormMetadata[$entityType])) { + $ormMetadata[$entityType][EntityParam::INDEXES] = []; } - $ormMetadata[$entityType]['indexes']['system_fullTextSearch'] = [ + $ormMetadata[$entityType][EntityParam::INDEXES]['system_fullTextSearch'] = [ IndexParam::COLUMNS => $fullTextSearchColumnList, IndexParam::FLAGS => ['fulltext'] ]; @@ -757,37 +759,37 @@ class Converter { $defs = &$ormMetadata[$entityType]; - $defs['indexes'] ??= []; + $defs[EntityParam::INDEXES] ??= []; if (isset($defs['attributes'])) { $indexList = self::getEntityIndexListFromAttributes($defs['attributes']); foreach ($indexList as $indexName => $indexParams) { - if (!isset($defs['indexes'][$indexName])) { - $defs['indexes'][$indexName] = $indexParams; + if (!isset($defs[EntityParam::INDEXES][$indexName])) { + $defs[EntityParam::INDEXES][$indexName] = $indexParams; } } } - foreach ($defs['indexes'] as $indexName => &$indexData) { + foreach ($defs[EntityParam::INDEXES] as $indexName => &$indexData) { $indexDefs = IndexDefs::fromRaw($indexData, $indexName); if (!$indexDefs->getKey()) { - $indexData['key'] = $this->composeIndexKey($indexDefs, $entityType); + $indexData[IndexParam::KEY] = $this->composeIndexKey($indexDefs, $entityType); } } - if (isset($defs['relations'])) { - foreach ($defs['relations'] as &$relationData) { + if (isset($defs[EntityParam::RELATIONS])) { + foreach ($defs[EntityParam::RELATIONS] as &$relationData) { $type = $relationData[RelationParam::TYPE] ?? null; if ($type !== Entity::MANY_MANY) { continue; } - $relationName = $relationData['relationName'] ?? ''; + $relationName = $relationData[RelationParam::RELATION_NAME] ?? ''; - $relationData['indexes'] ??= []; + $relationData[RelationParam::INDEXES] ??= []; $uniqueColumnList = []; @@ -796,7 +798,7 @@ class Converter $indexDefs = IndexDefs::fromRaw([IndexParam::COLUMNS => [$midKey]], $indexName); - $relationData['indexes'][$indexName] = [ + $relationData[RelationParam::INDEXES][$indexName] = [ IndexParam::COLUMNS => $indexDefs->getColumnList(), IndexParam::KEY => $this->composeIndexKey($indexDefs, ucfirst($relationName)), ]; @@ -804,7 +806,7 @@ class Converter $uniqueColumnList[] = $midKey; } - foreach ($relationData['indexes'] as $indexName => &$indexData) { + foreach ($relationData[RelationParam::INDEXES] as $indexName => &$indexData) { if (!empty($indexData[IndexParam::KEY])) { continue; } @@ -827,7 +829,7 @@ class Converter IndexParam::COLUMNS => $uniqueColumnList, ], $indexName); - $relationData['indexes'][$indexName] = [ + $relationData[RelationParam::INDEXES][$indexName] = [ IndexParam::TYPE => self::INDEX_TYPE_UNIQUE, IndexParam::COLUMNS => $indexDefs->getColumnList(), IndexParam::KEY => $this->composeIndexKey($indexDefs, ucfirst($relationName)), @@ -879,7 +881,7 @@ class Converter { $result = []; - foreach ($defs['relations'] as $name => $relationParams) { + foreach ($defs[EntityParam::RELATIONS] as $name => $relationParams) { $relationDefs = RelationDefs::fromRaw($relationParams, $name); if ($relationDefs->getType() !== Entity::MANY_MANY) { @@ -939,8 +941,8 @@ class Converter } foreach ($relationDefs->getIndexList() as $indexDefs) { - $itemDefs['indexes'] ??= []; - $itemDefs['indexes'][] = self::convertIndexDefsToRaw($indexDefs); + $itemDefs[EntityParam::INDEXES] ??= []; + $itemDefs[EntityParam::INDEXES][] = self::convertIndexDefsToRaw($indexDefs); } $result[$relationEntityType] = $itemDefs; diff --git a/application/Espo/Core/Utils/Database/Orm/Defs/EntityDefs.php b/application/Espo/Core/Utils/Database/Orm/Defs/EntityDefs.php index 4f8b3b5e0a..0ddbfa5faf 100644 --- a/application/Espo/Core/Utils/Database/Orm/Defs/EntityDefs.php +++ b/application/Espo/Core/Utils/Database/Orm/Defs/EntityDefs.php @@ -29,6 +29,8 @@ namespace Espo\Core\Utils\Database\Orm\Defs; +use Espo\ORM\Defs\Params\EntityParam; + /** * @immutable */ @@ -135,7 +137,7 @@ class EntityDefs $relationsData[$name] = $relationDefs->toAssoc(); } - $data['relations'] = $relationsData; + $data[EntityParam::RELATIONS] = $relationsData; } if (count($this->indexes)) { @@ -145,7 +147,7 @@ class EntityDefs $indexesData[$name] = $indexDefs->toAssoc(); } - $data['indexes'] = $indexesData; + $data[EntityParam::INDEXES] = $indexesData; } return $data; diff --git a/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php b/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php index f4c8bdcf46..15d96d6680 100644 --- a/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php +++ b/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php @@ -30,6 +30,7 @@ namespace Espo\Core\Utils\Database\Orm\Defs; use Espo\Core\Utils\Util; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Type\RelationType; class RelationDefs @@ -110,7 +111,7 @@ class RelationDefs */ public function withRelationshipName(string $name): self { - return $this->withParam('relationName', $name); + return $this->withParam(RelationParam::RELATION_NAME, $name); } /** @@ -118,7 +119,7 @@ class RelationDefs */ public function getRelationshipName(): ?string { - return $this->getParam('relationName'); + return $this->getParam(RelationParam::RELATION_NAME); } /** diff --git a/application/Espo/Core/Utils/Database/Orm/RelationConverter.php b/application/Espo/Core/Utils/Database/Orm/RelationConverter.php index 4c858b3f15..49570b08a9 100644 --- a/application/Espo/Core/Utils/Database/Orm/RelationConverter.php +++ b/application/Espo/Core/Utils/Database/Orm/RelationConverter.php @@ -40,6 +40,7 @@ use Espo\Core\Utils\Log; use Espo\Core\Utils\Util; use Espo\Core\Utils\Metadata; use Espo\ORM\Defs\Params\AttributeParam; +use Espo\ORM\Defs\Params\EntityParam; use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Defs\RelationDefs; use Espo\ORM\Type\AttributeType; @@ -53,11 +54,11 @@ class RelationConverter /** @var string[] */ private $mergeParams = [ - 'relationName', + RelationParam::RELATION_NAME, 'conditions', 'additionalColumns', 'noJoin', - 'indexes', + RelationParam::INDEXES, ]; public function __construct( @@ -83,11 +84,11 @@ class RelationConverter null; /** @var ?string $relationshipName */ - $relationshipName = $params['relationName'] ?? null; + $relationshipName = $params[RelationParam::RELATION_NAME] ?? null; if ($relationshipName) { $relationshipName = lcfirst($relationshipName); - $params['relationName'] = $relationshipName; + $params[RelationParam::RELATION_NAME] = $relationshipName; } $linkType = $params[RelationParam::TYPE] ?? null; @@ -110,9 +111,9 @@ class RelationConverter $raw = $convertedEntityDefs->toAssoc(); - if (isset($raw['relations'][$name])) { - $this->mergeParams($raw['relations'][$name], $params, $foreignParams ?? []); - $this->correct($raw['relations'][$name]); + if (isset($raw[EntityParam::RELATIONS][$name])) { + $this->mergeParams($raw[EntityParam::RELATIONS][$name], $params, $foreignParams ?? []); + $this->correct($raw[EntityParam::RELATIONS][$name]); } return [$entityType => $raw]; diff --git a/application/Espo/Core/Utils/Database/Schema/Builder.php b/application/Espo/Core/Utils/Database/Schema/Builder.php index 88bd4338fc..4fde99601d 100644 --- a/application/Espo/Core/Utils/Database/Schema/Builder.php +++ b/application/Espo/Core/Utils/Database/Schema/Builder.php @@ -39,6 +39,7 @@ use Espo\ORM\Defs\AttributeDefs; use Espo\ORM\Defs\EntityDefs; use Espo\ORM\Defs\IndexDefs; use Espo\ORM\Defs\Params\AttributeParam; +use Espo\ORM\Defs\Params\EntityParam; use Espo\ORM\Defs\RelationDefs; use Espo\ORM\Entity; @@ -104,7 +105,7 @@ class Builder } foreach ($ormMeta as $entityType => $entityParams) { - foreach (($entityParams['relations'] ?? []) as $relationName => $relationParams) { + foreach (($entityParams[EntityParam::RELATIONS] ?? []) as $relationName => $relationParams) { $relationDefs = RelationDefs::fromRaw($relationParams, $relationName); if ($relationDefs->getType() !== Entity::MANY_MANY) { diff --git a/application/Espo/Core/Utils/Database/Schema/Utils.php b/application/Espo/Core/Utils/Database/Schema/Utils.php index c955ef8b45..5051ed3a15 100644 --- a/application/Espo/Core/Utils/Database/Schema/Utils.php +++ b/application/Espo/Core/Utils/Database/Schema/Utils.php @@ -33,6 +33,7 @@ use Espo\Core\ORM\Type\FieldType; use Espo\Core\Utils\Util; use Espo\ORM\Defs\IndexDefs; use Espo\ORM\Defs\Params\AttributeParam; +use Espo\ORM\Defs\Params\EntityParam; use Espo\ORM\Defs\Params\IndexParam; class Utils @@ -50,7 +51,7 @@ class Utils $indexList = []; foreach ($defs as $entityType => $entityParams) { - $indexes = $entityParams['indexes'] ?? []; + $indexes = $entityParams[EntityParam::INDEXES] ?? []; foreach ($indexes as $indexName => $indexParams) { $indexDefs = IndexDefs::fromRaw($indexParams, $indexName); diff --git a/application/Espo/Modules/Crm/Tools/TargetList/RecordService.php b/application/Espo/Modules/Crm/Tools/TargetList/RecordService.php index a79f9f7e0c..f0e0745683 100644 --- a/application/Espo/Modules/Crm/Tools/TargetList/RecordService.php +++ b/application/Espo/Modules/Crm/Tools/TargetList/RecordService.php @@ -36,6 +36,7 @@ use Espo\Core\Exceptions\Forbidden; use Espo\Core\Exceptions\NotFound; use Espo\Core\HookManager; use Espo\Modules\Crm\Entities\TargetList; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\EntityManager; use RuntimeException; @@ -107,7 +108,7 @@ class RecordService throw new RuntimeException(); } - $linkEntityType = ucfirst($entity->getRelationParam($link, 'relationName') ?? ''); + $linkEntityType = ucfirst($entity->getRelationParam($link, RelationParam::RELATION_NAME) ?? ''); if ($linkEntityType === '') { throw new RuntimeException(); diff --git a/application/Espo/ORM/BaseEntity.php b/application/Espo/ORM/BaseEntity.php index f5cdb043d8..2d55e1212d 100644 --- a/application/Espo/ORM/BaseEntity.php +++ b/application/Espo/ORM/BaseEntity.php @@ -32,6 +32,7 @@ namespace Espo\ORM; use Espo\ORM\DataLoader\EmptyLoader; use Espo\ORM\DataLoader\Loader; use Espo\ORM\Defs\Params\AttributeParam; +use Espo\ORM\Defs\Params\EntityParam; use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Name\Attribute; use Espo\ORM\Relation\EmptyRelations; @@ -100,7 +101,7 @@ class BaseEntity implements Entity $this->entityManager = $entityManager; $this->attributesDefs = $defs['attributes'] ?? $this->attributesDefs; - $this->relationsDefs = $defs['relations'] ?? $this->relationsDefs; + $this->relationsDefs = $defs[EntityParam::RELATIONS] ?? $this->relationsDefs; if ($valueAccessorFactory) { $this->valueAccessor = $valueAccessorFactory->create($this); diff --git a/application/Espo/ORM/Defs/EntityDefs.php b/application/Espo/ORM/Defs/EntityDefs.php index c0f03271c6..8338351ecd 100644 --- a/application/Espo/ORM/Defs/EntityDefs.php +++ b/application/Espo/ORM/Defs/EntityDefs.php @@ -29,6 +29,7 @@ namespace Espo\ORM\Defs; +use Espo\ORM\Defs\Params\EntityParam; use RuntimeException; class EntityDefs @@ -87,7 +88,7 @@ class EntityDefs public function getRelationNameList(): array { /** @var string[] */ - return array_keys($this->data['relations'] ?? []); + return array_keys($this->data[EntityParam::RELATIONS] ?? []); } /** @@ -98,7 +99,7 @@ class EntityDefs public function getIndexNameList(): array { /** @var string[] */ - return array_keys($this->data['indexes'] ?? []); + return array_keys($this->data[EntityParam::INDEXES] ?? []); } /** @@ -109,7 +110,7 @@ class EntityDefs public function getFieldNameList(): array { /** @var string[] */ - return array_keys($this->data['fields'] ?? []); + return array_keys($this->data[EntityParam::FIELDS] ?? []); } /** @@ -379,7 +380,7 @@ class EntityDefs private function loadRelation(string $name): ?RelationDefs { - $raw = $this->data['relations'][$name] ?? null; + $raw = $this->data[EntityParam::RELATIONS][$name] ?? null; if (!$raw) { return null; @@ -399,7 +400,7 @@ class EntityDefs private function loadIndex(string $name): ?IndexDefs { - $raw = $this->data['indexes'][$name] ?? null; + $raw = $this->data[EntityParam::INDEXES][$name] ?? null; if (!$raw) { return null; @@ -419,7 +420,7 @@ class EntityDefs private function loadField(string $name): ?FieldDefs { - $raw = $this->data['fields'][$name] ?? null; + $raw = $this->data[EntityParam::FIELDS][$name] ?? null; if (!$raw) { return null; diff --git a/application/Espo/ORM/Defs/Params/EntityParam.php b/application/Espo/ORM/Defs/Params/EntityParam.php new file mode 100644 index 0000000000..6695493be9 --- /dev/null +++ b/application/Espo/ORM/Defs/Params/EntityParam.php @@ -0,0 +1,51 @@ +. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU Affero General Public License version 3. + * + * In accordance with Section 7(b) of the GNU Affero General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +namespace Espo\ORM\Defs\Params; + +/** + * An entity parameter. + */ +class EntityParam +{ + /** + * Fields. + */ + public const FIELDS = 'fields'; + + /** + * Relations. + */ + public const RELATIONS = 'relations'; + + /** + * Indexes. + */ + public const INDEXES = 'indexes'; +} diff --git a/application/Espo/ORM/Defs/Params/RelationParam.php b/application/Espo/ORM/Defs/Params/RelationParam.php index 70277e4b89..8b72edcc61 100644 --- a/application/Espo/ORM/Defs/Params/RelationParam.php +++ b/application/Espo/ORM/Defs/Params/RelationParam.php @@ -38,4 +38,14 @@ class RelationParam * A type. */ public const TYPE = 'type'; + + /** + * Indexes. + */ + public const INDEXES = 'indexes'; + + /** + * A relation name. + */ + public const RELATION_NAME = 'relationName'; } diff --git a/application/Espo/ORM/Defs/RelationDefs.php b/application/Espo/ORM/Defs/RelationDefs.php index 5bda47db7a..c865577f94 100644 --- a/application/Espo/ORM/Defs/RelationDefs.php +++ b/application/Espo/ORM/Defs/RelationDefs.php @@ -292,7 +292,7 @@ class RelationDefs */ public function hasRelationshipName(): bool { - return isset($this->data['relationName']); + return isset($this->data[RelationParam::RELATION_NAME]); } /** @@ -306,7 +306,7 @@ class RelationDefs throw new RuntimeException("No 'relationName' parameter defined in the relation '{$this->name}'."); } - return $this->data['relationName']; + return $this->data[RelationParam::RELATION_NAME]; } /** @@ -323,7 +323,7 @@ class RelationDefs $list = []; - foreach (($this->data['indexes'] ?? []) as $name => $item) { + foreach (($this->data[RelationParam::INDEXES] ?? []) as $name => $item) { $list[] = IndexDefs::fromRaw($item, $name); } diff --git a/application/Espo/ORM/Mapper/BaseMapper.php b/application/Espo/ORM/Mapper/BaseMapper.php index 8b70d3f80d..51ad6fef82 100644 --- a/application/Espo/ORM/Mapper/BaseMapper.php +++ b/application/Espo/ORM/Mapper/BaseMapper.php @@ -596,7 +596,7 @@ class BaseMapper implements RDBMapper switch ($relType) { case Entity::MANY_MANY: - $middleName = ucfirst($this->getRelationParam($entity, $relationName, 'relationName')); + $middleName = ucfirst($this->getRelationParam($entity, $relationName, RelationParam::RELATION_NAME)); $nearKey = $keySet['nearKey'] ?? null; $distantKey = $keySet['distantKey'] ?? null; @@ -662,7 +662,7 @@ class BaseMapper implements RDBMapper throw new RuntimeException("Empty ID passed to 'getRelationColumn'."); } - $middleName = ucfirst($this->getRelationParam($entity, $relationName, 'relationName')); + $middleName = ucfirst($this->getRelationParam($entity, $relationName, RelationParam::RELATION_NAME)); $keySet = $this->helper->getRelationKeys($entity, $relationName); diff --git a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php index a982d14960..9d65026c4a 100644 --- a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php +++ b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php @@ -31,7 +31,9 @@ namespace Espo\ORM\QueryComposer; use Espo\Core\ORM\Type\FieldType; use Espo\ORM\Defs\Params\AttributeParam; +use Espo\ORM\Defs\Params\EntityParam; use Espo\ORM\Defs\Params\IndexParam; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Entity; use Espo\ORM\EntityFactory; use Espo\ORM\BaseEntity; @@ -725,7 +727,7 @@ abstract class BaseQueryComposer implements QueryComposer } foreach ($indexList as $indexName) { - $indexKey = $this->metadata->get($entityType, ['indexes', $indexName, IndexParam::KEY]); + $indexKey = $this->metadata->get($entityType, [EntityParam::INDEXES, $indexName, IndexParam::KEY]); if ($indexKey) { $indexKeyList[] = $indexKey; @@ -3298,7 +3300,7 @@ abstract class BaseQueryComposer implements QueryComposer foreach ($indexList as $indexName) { $indexKey = $this->metadata->get( $entity->getEntityType(), - ['relations', $relationName, 'indexes', $indexName, IndexParam::KEY] + [EntityParam::RELATIONS, $relationName, RelationParam::INDEXES, $indexName, IndexParam::KEY] ); if ($indexKey) { diff --git a/application/Espo/Tools/EntityManager/Hook/Hooks/CollaboratorsUpdateHook.php b/application/Espo/Tools/EntityManager/Hook/Hooks/CollaboratorsUpdateHook.php index 9b6118c535..770db50772 100644 --- a/application/Espo/Tools/EntityManager/Hook/Hooks/CollaboratorsUpdateHook.php +++ b/application/Espo/Tools/EntityManager/Hook/Hooks/CollaboratorsUpdateHook.php @@ -34,6 +34,7 @@ use Espo\Core\ORM\Type\FieldType; use Espo\Core\Utils\Log; use Espo\Core\Utils\Metadata; use Espo\Entities\User; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Type\RelationType; use Espo\Tools\EntityManager\Hook\UpdateHook; use Espo\Tools\EntityManager\Params; @@ -92,7 +93,7 @@ class CollaboratorsUpdateHook implements UpdateHook self::FIELD => [ 'type' => RelationType::HAS_MANY, 'entity' => User::ENTITY_TYPE, - 'relationName' => self::RELATION_NAME, + RelationParam::RELATION_NAME => self::RELATION_NAME, 'layoutRelationshipsDisabled' => true, ], ], diff --git a/application/Espo/Tools/EntityManager/NameUtil.php b/application/Espo/Tools/EntityManager/NameUtil.php index d20fa69d9e..93279aae19 100644 --- a/application/Espo/Tools/EntityManager/NameUtil.php +++ b/application/Espo/Tools/EntityManager/NameUtil.php @@ -35,6 +35,7 @@ use Espo\Core\Utils\Metadata; use Espo\Core\Utils\Route; use Espo\Core\Utils\Util; use Espo\Core\ServiceFactory; +use Espo\ORM\Defs\Params\EntityParam; use Espo\ORM\EntityManager; use Espo\ORM\Entity; @@ -329,7 +330,7 @@ class NameUtil foreach ($scopeList as $entityType) { $relationsDefs = $this->entityManager ->getMetadata() - ->get($entityType, 'relations'); + ->get($entityType, EntityParam::RELATIONS); if (empty($relationsDefs)) { continue; diff --git a/application/Espo/Tools/LinkManager/LinkManager.php b/application/Espo/Tools/LinkManager/LinkManager.php index 878fa2d845..ca3dce65d9 100644 --- a/application/Espo/Tools/LinkManager/LinkManager.php +++ b/application/Espo/Tools/LinkManager/LinkManager.php @@ -38,6 +38,7 @@ use Espo\Core\Utils\Language; use Espo\Core\Utils\Metadata; use Espo\Core\Utils\Route; use Espo\Core\Utils\Util; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Entity; use Espo\ORM\Type\RelationType; use Espo\Tools\LinkManager\Hook\HookProcessor as LinkHookProcessor; @@ -470,7 +471,7 @@ class LinkManager 'links' => [ $link => [ 'type' => Entity::HAS_MANY, - 'relationName' => $relationName, + RelationParam::RELATION_NAME => $relationName, 'foreign' => $linkForeign, 'entity' => $entityForeign, 'audited' => $auditedForeign, @@ -491,7 +492,7 @@ class LinkManager 'links' => [ $linkForeign => [ 'type' => Entity::HAS_MANY, - 'relationName' => $relationName, + RelationParam::RELATION_NAME => $relationName, 'foreign' => $link, 'entity' => $entity, 'audited' => $audited, @@ -874,8 +875,8 @@ class LinkManager $type = LinkType::ONE_TO_ONE_RIGHT; } - $name = $this->metadata->get(['entityDefs', $entity, $link, 'relationName']) ?? - $this->metadata->get(['entityDefs', $entityForeign, $linkForeign, 'relationName']); + $name = $this->metadata->get(['entityDefs', $entity, $link, RelationParam::RELATION_NAME]) ?? + $this->metadata->get(['entityDefs', $entityForeign, $linkForeign, RelationParam::RELATION_NAME]); $linkParams = null;